27 |
|
#define GRIDRES 200 /* grid resolution per side */ |
28 |
|
#endif |
29 |
|
|
30 |
+ |
#define MAXSAMPORD 7 /* don't sample finer than this */ |
31 |
+ |
|
32 |
|
#define RSCA 2.7 /* radius scaling factor (empirical) */ |
33 |
|
|
34 |
|
/* convert to/from coded radians */ |
97 |
|
|
98 |
|
char *progname; |
99 |
|
|
100 |
< |
#ifdef DEBUG /* percentage to cull (<0 to turn off) */ |
99 |
< |
int pctcull = -1; |
100 |
< |
#else |
100 |
> |
/* percentage to cull (<0 to turn off) */ |
101 |
|
int pctcull = 90; |
102 |
– |
#endif |
102 |
|
/* number of processes to run */ |
103 |
|
int nprocs = 1; |
104 |
+ |
|
105 |
|
/* number of children (-1 in child) */ |
106 |
|
int nchild = 0; |
107 |
|
|
269 |
|
insert_dsf(newnode); |
270 |
|
/* adjust sampling resolution */ |
271 |
|
samp_order = log(2./R2ANG(minrad))/M_LN2 + .5; |
272 |
+ |
if (samp_order > MAXSAMPORD) |
273 |
+ |
samp_order = MAXSAMPORD; |
274 |
|
|
275 |
|
return(newnode); |
276 |
|
} |
578 |
|
static double |
579 |
|
migration_step(MIGRATION *mig, double *src_rem, double *dst_rem, const float *pmtx) |
580 |
|
{ |
581 |
+ |
const double maxamt = .1; |
582 |
|
static double *src_cost = NULL; |
583 |
|
static int n_alloc = 0; |
581 |
– |
const double maxamt = .1; /* 2./(mtx_nrows(mig)*mtx_ncols(mig)); */ |
582 |
– |
double amt = 0; |
584 |
|
struct { |
585 |
|
int s, d; /* source and destination */ |
586 |
|
double price; /* price estimate per amount moved */ |
622 |
|
src_rem[cur.s] : dst_rem[cur.d]; |
623 |
|
if (cur.amt > maxamt) cur.amt = maxamt; |
624 |
|
dst_rem[cur.d] -= cur.amt; /* add up differential costs */ |
625 |
< |
for (i = mtx_nrows(mig); i--; ) { |
626 |
< |
if (i == cur.s) continue; |
627 |
< |
cost_others += min_cost(src_rem[i], dst_rem, price, mtx_ncols(mig)) |
625 |
> |
for (i = mtx_nrows(mig); i--; ) |
626 |
> |
if (i != cur.s) |
627 |
> |
cost_others += min_cost(src_rem[i], dst_rem, |
628 |
> |
price, mtx_ncols(mig)) |
629 |
|
- src_cost[i]; |
628 |
– |
} |
630 |
|
dst_rem[cur.d] += cur.amt; /* undo trial move */ |
631 |
|
cur.price += cost_others/cur.amt; /* adjust effective price */ |
632 |
|
if (cur.price < best.price) /* are we better than best? */ |
804 |
|
#ifdef DEBUG |
805 |
|
if (!nchild) fputs("\ndone.\n", stderr); |
806 |
|
#endif |
806 |
– |
|
807 |
– |
free(pmtx); /* free working arrays */ |
808 |
– |
free(src_rem); |
809 |
– |
free(dst_rem); |
807 |
|
for (i = from_rbf->nrbf; i--; ) { /* normalize final matrix */ |
808 |
|
float nf = rbf_volume(&from_rbf->rbfa[i]); |
809 |
|
int j; |
813 |
|
newmig->mtx[mtx_ndx(newmig,i,j)] *= nf; |
814 |
|
} |
815 |
|
end_subprocess(); /* exit here if subprocess */ |
816 |
+ |
free(pmtx); /* free working arrays */ |
817 |
+ |
free(src_rem); |
818 |
+ |
free(dst_rem); |
819 |
|
return(newmig); |
820 |
|
} |
821 |
|
|
1102 |
|
mesh_from_edge(create_migration(shrt_edj[0], shrt_edj[1])); |
1103 |
|
else |
1104 |
|
mesh_from_edge(create_migration(shrt_edj[1], shrt_edj[0])); |
1105 |
– |
/* complete migrations */ |
1106 |
– |
await_children(nchild); |
1105 |
|
/* draw edge list into grid */ |
1106 |
|
draw_edges(); |
1107 |
+ |
/* complete migrations */ |
1108 |
+ |
await_children(nchild); |
1109 |
|
} |
1110 |
|
|
1111 |
|
/* Identify enclosing triangle for this position (flood fill raster check) */ |