Debian Codegraph @

packages/seacas/libraries/chaco/klspiff/buckets1.c

raw
1 /*
2 * Copyright(C) 1999-2020, 2023 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8
9 #include "params.h" // for MAXSETS
10 #include "structs.h" // for vtx_data, bilist
11 #include <stdio.h> // for NULL
12
13 /* Idea:
14 'buckets[i][j]' is a set of buckets to sort moves from i to j.
15 listspace[i] is space for lists in buckets[i][j].
16 Loop through all nonequal pairs [i][j], taking the first element
17 in each list. Compare them all to find the largest allowed move.
18 Make that move, and save it in movelist.
19 */
20
21 void bucketsort1(struct vtx_data **graph, /* graph data structure */
22 int vtx, /* vertex being added to lists */
23 struct bilist ****buckets, /* array of lists for bucket sort */
24 struct bilist **listspace, /* list data structure for each vertex */
25 int **dvals, /* d-values for each vertex for removing */
26 int *sets, /* processor each vertex is assigned to */
27 float *term_wgts[], /* weights for terminal propagation */
28 int maxdval, /* maximum possible dvalue for a vertex */
29 int nsets, /* number of sets being divided into */
30 int (*hops)[MAXSETS], /* hop cost between sets */
31 int using_ewgts /* are edge weights being used? */
32 )
33 {
34 extern double CUT_TO_HOP_COST; /* if term_prop, cut/hop importance */
35 struct bilist *lptr = NULL; /* pointer to an element in listspace */
36 float *ewptr = NULL; /* loops through edge weights */
37 int *edges = NULL; /* edge list for a vertex */
38 int myset; /* set that current vertex belongs to */
39 int newset; /* set current vertex could move to */
40 int set; /* set that neighboring vertex belongs to */
41 int weight; /* edge weight for a particular edge */
42 float tval; /* terminal propagation value */
43 int val; /* terminal propagation rounded value */
44 double cut_cost; /* relative cut/hop importance */
45 double hop_cost; /* relative hop/cut importance */
46 int myhop; /* hops associated with current vertex */
47 int j, l; /* loop counters */
48
49 /* Compute d-vals by seeing which sets neighbors belong to. */
50 cut_cost = hop_cost = 1;
51 if (term_wgts[1] != NULL) {
52 if (CUT_TO_HOP_COST > 1) {
53 cut_cost = CUT_TO_HOP_COST;
54 }
55 else {
56 hop_cost = 1.0 / CUT_TO_HOP_COST;
57 }
58 }
59
60 weight = cut_cost + .5;
61 myset = sets[vtx];
62
63 /* Initialize all the preference values. */
64 if (term_wgts[1] != NULL) {
65 /* Using terminal propagation. */
66 if (myset == 0) { /* No terminal value. */
67 for (newset = 1; newset < nsets; newset++) {
68 tval = (term_wgts[newset])[vtx];
69 if (tval < 0) {
70 val = -tval * hop_cost + .5;
71 val = -val;
72 }
73 else {
74 val = tval * hop_cost + .5;
75 }
76 dvals[vtx][newset - 1] = val;
77 }
78 }
79 else {
80 tval = -(term_wgts[myset])[vtx];
81 if (tval < 0) {
82 val = -tval * hop_cost + .5;
83 val = -val;
84 }
85 else {
86 val = tval * hop_cost + .5;
87 }
88 dvals[vtx][0] = val;
89 l = 1;
90 for (newset = 1; newset < nsets; newset++) {
91 if (newset != myset) {
92 tval = (term_wgts[newset])[vtx] - (term_wgts[myset])[vtx];
93 if (tval < 0) {
94 val = -tval * hop_cost + .5;
95 val = -val;
96 }
97 else {
98 val = tval * hop_cost + .5;
99 }
100 dvals[vtx][l] = val;
101 l++;
102 }
103 }
104 }
105 }
106 else {
107 for (j = 0; j < nsets - 1; j++) {
108 dvals[vtx][j] = 0;
109 }
110 }
111
112 /* First count the neighbors in each set. */
113 edges = graph[vtx]->edges;
114 if (using_ewgts) {
115 ewptr = graph[vtx]->ewgts;
116 }
117 for (j = graph[vtx]->nedges - 1; j; j--) {
118 set = sets[*(++edges)];
119 if (set < 0) {
120 set = -set - 1;
121 }
122 if (using_ewgts) {
123 weight = *(++ewptr) * cut_cost + .5;
124 }
125 myhop = hops[myset][set];
126
127 l = 0;
128 for (newset = 0; newset < nsets; newset++) {
129 if (newset != myset) {
130 dvals[vtx][l] += weight * (myhop - hops[newset][set]);
131 l++;
132 }
133 }
134 }
135
136 /* Now add to appropriate buckets. */
137 l = 0;
138 for (newset = 0; newset < nsets; newset++) {
139 if (newset != myset) {
140 lptr = listspace[l];
141 add2bilist(&lptr[vtx], &buckets[myset][newset][dvals[vtx][l] + maxdval]);
142 ++l;
143 }
144 }
145 }