213 |
|
static double |
214 |
|
migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const PRICEMAT *pm) |
215 |
|
{ |
216 |
< |
const double maxamt = .1; |
216 |
> |
const double maxamt = 1./(double)pm->ncols; |
217 |
|
const double minamt = maxamt*5e-6; |
218 |
|
static double *src_cost = NULL; |
219 |
|
static int n_alloc = 0; |
241 |
|
/* find best source & dest. */ |
242 |
|
best.s = best.d = -1; best.price = FHUGE; best.amt = 0; |
243 |
|
for (cur.s = pm->nrows; cur.s--; ) { |
244 |
– |
const float *price = pricerow(pm,cur.s); |
244 |
|
double cost_others = 0; |
245 |
|
if (src_rem[cur.s] <= minamt) |
246 |
|
continue; |
247 |
< |
cur.d = -1; /* examine cheapest dest. */ |
248 |
< |
for (i = pm->ncols; i--; ) |
249 |
< |
if (dst_rem[i] > minamt && |
250 |
< |
(cur.d < 0 || price[i] < price[cur.d])) |
251 |
< |
cur.d = i; |
253 |
< |
if (cur.d < 0) |
247 |
> |
/* examine cheapest dest. */ |
248 |
> |
for (i = 0; i < pm->ncols; i++) |
249 |
> |
if (dst_rem[cur.d = psortrow(pm,cur.s)[i]] > minamt) |
250 |
> |
break; |
251 |
> |
if (i >= pm->ncols) |
252 |
|
return(.0); |
253 |
< |
if ((cur.price = price[cur.d]) >= best.price) |
253 |
> |
if ((cur.price = pricerow(pm,cur.s)[cur.d]) >= best.price) |
254 |
|
continue; /* no point checking further */ |
255 |
|
cur.amt = (src_rem[cur.s] < dst_rem[cur.d]) ? |
256 |
|
src_rem[cur.s] : dst_rem[cur.d]; |