8 double max_mass=-1, max_volu=-1, max_capi=-1;
9 double distance_loss_factor_per_league;
15 #define tabdebugf printf
18 #define CTR(x) int ctr_##x;
19 #define CTRA(x,n) int ctr_##x[n];
24 static PotentialResult ****results[GRANUS];
25 /* results[GRANUS][start_isle_ix][finalisle][midisle]-> */
27 static pid_t debugoutpid;
29 int main(int argc, const char **argv) {
35 debug_flags= ~( dbg_sql2 );
40 if (arg[0] != '-') break;
42 if (!strcmp(arg,"-DN")) {
52 /* glpk insists on writing stuff to stdout, and it does buffering,
53 * so we route all our debug through it this too */
55 sysassert( (realstdout= dup(1)) > 2 );
56 sysassert( output= fdopen(realstdout,"w") );
59 sysassert(! pipe(pfd) );
60 sysassert( (debugoutpid= fork()) >=0 );
62 sysassert( dup2(pfd[0],0)==0 );
63 sysassert( dup2(2,1)==1 );
64 sysassert(! close(pfd[0]) );
65 sysassert(! close(pfd[1]) );
66 sysassert(! execlp("cat","cat",(char*)0) );
68 sysassert( dup2(pfd[1],1)==1 );
69 sysassert(! close(pfd[0]) );
70 sysassert(! close(pfd[1]) );
78 const char *database= *argv++;
80 sysassert( !setvbuf(debug,0,_IOLBF,0) );
82 max_mass= atof(*argv++);
83 max_volu= atof(*argv++);
84 max_capi= atof(*argv++);
85 double loss_per_league= atof(*argv++);
86 distance_loss_factor_per_league= 1.0 - loss_per_league;
92 for (i=0; i<narches; i++)
93 fprintf(output,"arch %d %s\n",i,archnames[i]);
94 fprintf(output,"setup complete, starting search\n");
97 if (!strcmp(arg,"specific")) {
99 while ((arg= *argv++))
102 double val= value_route(ni, ia, 0);
103 fprintf(output, "route value is %g\n", val);
104 } else if (!strcmp(arg,"search")) {
105 for (granui=0; granui<GRANUS; granui++)
106 MCALLOC(results[granui], argc);
108 max_dist= atoi(*argv++);
110 for (ap=0; ap<AP; ap++) {
111 int nhs= atoi(*argv++);
112 for (granui=0; granui<GRANUS; granui++) {
113 nhighscores[granui][ap]= nhs;
114 MCALLOC(highscores[granui][ap], nhs);
117 const char *final_isle_spec= *argv++;
120 while ((arg= argv[resultsix])) {
121 int init_isle= atoi(arg);
124 if (!strcmp(final_isle_spec,"circ")) final_isle= init_isle;
125 else if (!strcmp(final_isle_spec,"any")) final_isle= -1;
126 else final_isle= atoi(final_isle_spec);
129 PotentialResult ****buckets_base_io[GRANUS];
130 for (granui=0; granui<GRANUS; granui++)
131 buckets_base_io[granui]= &results[granui][resultsix];
133 search(init_isle, final_isle, buckets_base_io);
138 for (granui=0; granui<granus; granui++) {
139 fprintf(output,"\n");
140 for (i=0; i<resultsix; i++) {
141 tabdebugf("========== start #%d granui%d %s [PARTIAL] ==========\n",
143 PotentialResult ***buckets_resultsix= results[granui][i];
144 if (!buckets_resultsix) continue;
146 for (mid=0; mid<granusz_mid[granui]; mid++) {
147 tabdebugf("| m%-3d ",mid);
150 for (fin=0; fin<granusz_fin[granui]; fin++) {
151 PotentialResult **buckets_fin= buckets_resultsix[fin];
152 if (!buckets_fin) continue;
153 tabdebugf("f%-3d",fin);
154 for (mid=0; mid<granusz_mid[granui]; mid++) {
155 PotentialResult *result= buckets_fin[mid];
159 tabdebugf("|%5d",(int)(result->value[A]));
161 tabdebugf("%4d",(int)(result->value[P]));
168 for (ap=0; ap<AP; ap++) {
170 fprintf(output,"============== granui%d ap=%d ==============\n",
172 for (pos=nhighscores[granui][ap]-1; pos>=0; pos--) {
173 HighScoreEntry *hs= &highscores[granui][ap][pos];
174 PotentialResult *pr= hs->pr;
176 const int *const ports= pr->ports[ap];
178 for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);
179 int finisle= ports[nports-1];
180 int finarch= isle2arch(finisle);
181 int midisle= ports[nports/2];
182 int midarch= route2midarch(ports,nports);
184 " @%2d %c#%2d | start%3d mid%d:%3d f%d:%3d | %5d %5d %4d |",
185 pos, "ap"[ap], nhighscores[granui][ap] - 1 - pos,
186 ports[0], midarch,midisle, finarch,finisle,
187 (int)hs->value, (int)pr->value[A], (int)pr->value[P]);
188 for (i=0; i<nports; i++) fprintf(output," %d",ports[i]);
189 fprintf(output,"\n");
193 fprintf(output,"\n");
199 #define CTR(x) fprintf(output," %-30s %10d\n",#x,ctr_##x);
200 #define CTRA(x,n) for (i=0;i<n;i++) \
201 fprintf(output," %-27s[%d] %10d\n",#x,i,ctr_##x[i]);
206 sysassert(! fclose(debug) );
207 waitpid_check_exitstatus(debugoutpid,"debug cat",1);
209 sysassert(! fclose(output) );