| 383 |
|
#undef discount |
| 384 |
|
} |
| 385 |
|
|
| 386 |
+ |
#ifdef DUMP_MATRIX |
| 387 |
+ |
/* Dump transport plan and corresponding price matrix to a text file */ |
| 388 |
+ |
static void |
| 389 |
+ |
dump_matrix(const MIGRATION *me, const PRICEMAT *pm) |
| 390 |
+ |
{ |
| 391 |
+ |
char fname[256]; |
| 392 |
+ |
FILE *fp; |
| 393 |
+ |
int i, j; |
| 394 |
+ |
|
| 395 |
+ |
sprintf(fname, "edge_%d-%d.txt", me->rbfv[0]->ord, me->rbfv[1]->ord); |
| 396 |
+ |
if ((fp = fopen(fname, "w")) == NULL) |
| 397 |
+ |
return; |
| 398 |
+ |
for (j = 0; j < 2; j++) { |
| 399 |
+ |
fprintf(fp, "Available from %d source RBF lobes in node %d:\n", |
| 400 |
+ |
me->rbfv[j]->nrbf, me->rbfv[j]->ord); |
| 401 |
+ |
for (i = 0; i < me->rbfv[j]->nrbf; i++) |
| 402 |
+ |
fprintf(fp, " %.4e", rbf_volume(&me->rbfv[j]->rbfa[i]) / |
| 403 |
+ |
me->rbfv[j]->vtotal); |
| 404 |
+ |
fputc('\n', fp); |
| 405 |
+ |
} |
| 406 |
+ |
fprintf(fp, "Price (quadratic distance metric) matrix:\n"); |
| 407 |
+ |
for (i = 0; i < pm->nrows; i++) { |
| 408 |
+ |
for (j = 0; j < pm->ncols; j++) |
| 409 |
+ |
fprintf(fp, " %.4e", pricerow(pm,i)[j]); |
| 410 |
+ |
fputc('\n', fp); |
| 411 |
+ |
} |
| 412 |
+ |
fprintf(fp, "Solution matrix (transport plan):\n"); |
| 413 |
+ |
for (i = 0; i < mtx_nrows(me); i++) { |
| 414 |
+ |
for (j = 0; j < mtx_ncols(me); j++) |
| 415 |
+ |
fprintf(fp, " %.4e", mtx_coef(me,i,j)); |
| 416 |
+ |
fputc('\n', fp); |
| 417 |
+ |
} |
| 418 |
+ |
fclose(fp); |
| 419 |
+ |
} |
| 420 |
+ |
#endif |
| 421 |
+ |
|
| 422 |
|
/* Compute and insert migration along directed edge (may fork child) */ |
| 423 |
|
static MIGRATION * |
| 424 |
|
create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) |
| 474 |
|
for (j = to_rbf->nrbf; j--; ) |
| 475 |
|
mtx_coef(newmig,i,j) *= nf; /* row now sums to 1.0 */ |
| 476 |
|
} |
| 477 |
+ |
#ifdef DUMP_MATRIX |
| 478 |
+ |
dump_matrix(newmig, &pmtx); |
| 479 |
+ |
#endif |
| 480 |
|
end_subprocess(); /* exit here if subprocess */ |
| 481 |
|
free_routes(&pmtx); /* free working arrays */ |
| 482 |
|
free(src_rem); |