127 double *cost_remain )
139 double *sub_cost_remain = NULL;
142 candnbr = lcandnum - fcandnum + 1;
152 pmptr->candtab[rootnum].fcandnum = fcandnum;
153 pmptr->candtab[rootnum].lcandnum = lcandnum;
154 pmptr->candtab[rootnum].cluster = cluster;
157 if(pmptr->etree->nodetab[rootnum].sonsnbr == 0)
162 assert( pmptr->etree->nodetab[rootnum].ndecost <= pmptr->etree->nodetab[rootnum].subcost );
165 isocost = pmptr->etree->nodetab[rootnum].ndecost / candnbr;
166 for(p=0;p<candnbr;p++)
167 cost_remain[p] -= isocost;
170 aspt_cost = pmptr->etree->nodetab[rootnum].subcost - pmptr->etree->nodetab[rootnum].ndecost;
176 if(cost_remain[0] <= 0)
180 if (cost_remain[candnbr-1] <= 0)
183 assert(fcand < candnbr);
184 assert(candnbr >= 1);
188 for(i=fcand; i<candnbr; i++)
189 cumul_cost += cost_remain[i];
191 if (cumul_cost < aspt_cost) {
192 double ratio = aspt_cost / cumul_cost;
193 for(i=fcand; i<candnbr; i++)
194 cost_remain[i] *= ratio;
203 sonsnbr = pmptr->etree->nodetab[rootnum].sonsnbr;
205 if ( sonsnbr == 1 ) {
208 fcandnum, lcandnum, cluster, cost_remain );
216 for(i=0; i<sonsnbr; i++)
219 cumul_cost = -pmptr->etree->nodetab[
eTreeSonI(pmptr->etree, rootnum, i)].subcost;
222 soncost = -pmptr->etree->nodetab[
eTreeSonI(pmptr->etree, rootnum, i)].ndecost;
231 i =
pqueuePop2( queue_tree, &cumul_cost, NULL );
232 cumul_cost = -cumul_cost;
240 if (cumul_cost <= cost_remain[fcand]) {
241 cost_remain[fcand] -= cumul_cost;
243 fcandnum+fcand, fcandnum+fcand, cluster);
251 if ( pmptr->nocrossproc &&
252 (cumul_cost <= (cost_remain[fcand]+epsilon)) )
254 cost_remain[fcand] -= cumul_cost;
256 fcandnum+fcand, fcandnum+fcand, cluster );
261 if( (fcand < candnbr-1) && (cost_remain[fcand] <= epsilon) )
273 cumul_cost -= cost_remain[fcand];
274 while ((( pmptr->nocrossproc && (cumul_cost > ((
double)scandnbr)*epsilon)) ||
275 (!pmptr->nocrossproc && (cumul_cost > epsilon))) &&
276 (lcand < candnbr - 1))
279 assert( cost_remain[lcand] > 0 );
280 cumul_cost -= cost_remain[lcand];
289 MALLOC_INTERN(sub_cost_remain, lcand-fcand+1,
double);
292 isocost = cumul_cost / scandnbr;
293 for(p=0; p<scandnbr; p++)
295 sub_cost_remain[p] = cost_remain[fcand+p] + isocost;
296 cost_remain[fcand+p] = - isocost;
301 for(p=0; p<scandnbr-1; p++)
303 sub_cost_remain[p] = cost_remain[fcand+p];
304 cost_remain[fcand+p] = 0.0;
306 sub_cost_remain[scandnbr-1] = cost_remain[lcand] + cumul_cost;
307 cost_remain[fcand+scandnbr-1] = -cumul_cost;
311 fcandnum+fcand, fcandnum+lcand, cluster, sub_cost_remain);
312 memFree_null(sub_cost_remain);
314 if ( (lcand < candnbr - 1) &&
315 ( pmptr->nocrossproc ||
316 (cost_remain[lcand] < epsilon) ) )
322 if ( pmptr->nocrossproc )
342 for (i=0; i<candnbr; i++) {
349 i =
pqueuePop2( queue_tree, &cumul_cost, NULL );
350 cumul_cost = -cumul_cost;
357 fcandnum+fcand, fcandnum+fcand, cluster);
360 cost_remain[fcand] -= cumul_cost;
361 pqueuePush1(queue_proc, fcand, -cost_remain[fcand]);