DECLARATIONS ///.
Date [Ver. 1.0. Started - October 15, 2002.]
] FUNCTION DEFINITIONS /// Function*************************************************************
Description [Performs a sequence of adjacent variable swaps known as "sifting". Uses the cost functions determined by the flag.]
45{
46 double CostCurrent;
47 double CostLimit;
48 double CostBest;
49 int BestQ;
50 int VarCurrent;
51 int q;
52 int c;
53 int v;
54
56
57
59 CostCurrent =
p->nWidthCur;
60 else if (
p->fMinApl )
61 CostCurrent =
p->nAplCur;
62 else
63 CostCurrent =
p->nNodesCur;
64
65
67
68
69 for ( c = 0; c <
p->nSupp; c++ )
70 {
71
72 VarCurrent = -1;
73 CostBest = -1.0;
74 for ( v = 0; v <
p->nSupp; v++ )
75 {
77 if ( !
p->pPlanes[v].fSifted )
78 {
79
80
81 if ( CostBest < p->pPlanes[v].statsNodes )
82 {
83
84 CostBest =
p->pPlanes[v].statsNodes;
85 VarCurrent = v;
86 }
87
88 }
89 }
90 assert( VarCurrent != -1 );
91
92 p->pPlanes[VarCurrent].fSifted = 1;
93
94
95 p->pVarCosts[VarCurrent] = CostCurrent;
96
97
98 CostBest = CostCurrent;
99 BestQ = VarCurrent;
100
101
102
103
104
105 if ( VarCurrent < p->nSupp/2 )
106 {
107
108 p->pPlanes[0].statsCostAbove = 0;
109 for ( v = 1; v <= VarCurrent; v++ )
110 p->pPlanes[v].statsCostAbove =
p->pPlanes[v-1].statsCostAbove +
p->pPlanes[v-1].statsCost;
111
112 p->pPlanes[
p->nSupp].statsCostBelow = 0;
113 for ( v =
p->nSupp - 1; v >= VarCurrent; v-- )
114 p->pPlanes[v].statsCostBelow =
p->pPlanes[v+1].statsCostBelow +
p->pPlanes[v+1].statsCost;
115
116 assert( CostCurrent ==
p->pPlanes[VarCurrent].statsCostAbove +
117 p->pPlanes[VarCurrent].statsCost +
118 p->pPlanes[VarCurrent].statsCostBelow );
119
120
121 for ( q = VarCurrent-1; q >= 0; q-- )
122 {
124
125 p->pVarCosts[q] = CostCurrent;
126
127 p->pPlanes[q].statsCostBelow =
p->pPlanes[q+1].statsCostBelow +
p->pPlanes[q+1].statsCost;
128
129 if ( CostCurrent >= CostLimit )
130 break;
131
133 break;
134
135 if ( CostBest > CostCurrent )
136 {
137 CostBest = CostCurrent;
138 BestQ = q;
139
141 }
142
143
144
145
146 if (
p->fMinWidth ||
p->fMinApl )
147 {
148 if (
p->nNodesCur >= 2 *
p->nNodesMaxAlloc )
149 {
150
152 }
153 }
154 }
155
156 if ( q == -1 )
157 q++;
158
159
160
161 for ( ; q <
p->nSupp-1; )
162 {
164 q++;
165
167 printf("reoReorderSift(): Error! On the backward move, the costs are different.\n");
168 p->pVarCosts[q] = CostCurrent;
169
170 p->pPlanes[q].statsCostAbove =
p->pPlanes[q-1].statsCostAbove +
p->pPlanes[q-1].statsCost;
171
172 if ( q >= BestQ )
173 {
174
175 if ( CostCurrent >= CostLimit )
176 break;
177
179 break;
180 }
181
182 if ( CostBest >= CostCurrent )
183 {
184 CostBest = CostCurrent;
185 BestQ = q;
186
188 }
189
190
191
192
193 if (
p->fMinWidth ||
p->fMinApl )
194 {
195 if (
p->nNodesCur >= 2 *
p->nNodesMaxAlloc )
196 {
197
199 }
200 }
201 }
202
204 for ( ; q > BestQ; q-- )
205 {
207
209 {
210 printf("reoReorderSift(): Error! On the return move, the costs are different.\n" );
211 fflush(stdout);
212 }
213 }
214 }
215 else
216 {
217
218 p->pPlanes[0].statsCostAbove = 0;
219 for ( v = 1; v <= VarCurrent; v++ )
220 p->pPlanes[v].statsCostAbove =
p->pPlanes[v-1].statsCostAbove +
p->pPlanes[v-1].statsCost;
221
222 p->pPlanes[
p->nSupp].statsCostBelow = 0;
223 for ( v =
p->nSupp - 1; v >= VarCurrent; v-- )
224 p->pPlanes[v].statsCostBelow =
p->pPlanes[v+1].statsCostBelow +
p->pPlanes[v+1].statsCost;
225
226 assert( CostCurrent ==
p->pPlanes[VarCurrent].statsCostAbove +
227 p->pPlanes[VarCurrent].statsCost +
228 p->pPlanes[VarCurrent].statsCostBelow );
229
230
231 for ( q = VarCurrent; q <
p->nSupp-1; )
232 {
234 q++;
235 p->pVarCosts[q] = CostCurrent;
236
237 p->pPlanes[q].statsCostAbove =
p->pPlanes[q-1].statsCostAbove +
p->pPlanes[q-1].statsCost;
238
239 if ( CostCurrent >= CostLimit )
240 break;
241
243 break;
244
245 if ( CostBest > CostCurrent )
246 {
247 CostBest = CostCurrent;
248 BestQ = q;
249
251 }
252
253
254
255
256 if (
p->fMinWidth ||
p->fMinApl )
257 {
258 if (
p->nNodesCur >= 2 *
p->nNodesMaxAlloc )
259 {
260
262 }
263 }
264 }
265
266
267 for ( --q; q >= 0; q-- )
268 {
270
271
273 printf("reoReorderSift(): Error! On the backward move, the costs are different.\n");
274 p->pVarCosts[q] = CostCurrent;
275
276 p->pPlanes[q].statsCostBelow =
p->pPlanes[q+1].statsCostBelow +
p->pPlanes[q+1].statsCost;
277
278 if ( q <= BestQ )
279 {
280
281 if ( CostCurrent >= CostLimit )
282 break;
283
285 break;
286 }
287
288 if ( CostBest >= CostCurrent )
289 {
290 CostBest = CostCurrent;
291 BestQ = q;
292
294 }
295
296
297
298
299 if (
p->fMinWidth ||
p->fMinApl )
300 {
301 if (
p->nNodesCur >= 2 *
p->nNodesMaxAlloc )
302 {
303
305 }
306 }
307 }
308
309 if ( q == -1 )
310 q++;
311
312
314 for ( ; q < BestQ; q++ )
315 {
317
319 {
320 printf("reoReorderSift(): Error! On the return move, the costs are different.\n" );
321 fflush(stdout);
322 }
323 }
324 }
326
327
329 p->nWidthCur = (int)CostBest;
330 else if (
p->fMinApl )
331 p->nAplCur = CostCurrent;
332 else
333 p->nNodesCur = (int)CostBest;
334 }
335
336
337 for ( v = 0; v <
p->nSupp; v++ )
338 p->pPlanes[v].fSifted = 0;
339}
void reoResizeStructures(reo_man *p, int nDdVarsMax, int nNodesMax, int nFuncs)
double reoReorderSwapAdjacentVars(reo_man *p, int Level, int fMovingUp)
FUNCTION DEFINITIONS ///.
#define REO_REORDER_LIMIT
MACRO DEFINITIONS ///.