8 double max_mass=-1, max_volu=-1, max_capi=-1;
9 double distance_loss_factor_per_league;
10 int max_dist=-1, min_trade_maxprofit=0;
15 #define tabdebugf printf
18 #define CTR(x) int ctr_##x;
19 #define CTRA(x,n) int ctr_##x[n];
24 static Bucket ****results[GRANUS];
25 /* results[GRANUS][start_isle_ix][finalisle][midisle]-> */
27 static pid_t debugoutpid;
29 int main(int argc, const char **argv) {
33 const char *database=0;
36 debug_flags= ~( dbg_sql2 );
41 if (arg[0] != '-') break;
42 if (!strcmp(arg,"-d")) {
44 } else if (!strcmp(arg,"-g")) {
45 granus= atoi(*++argv);
46 assert(granus>=1 && granus<=GRANUS);
48 } else if (!strcmp(arg,"-DN")) {
50 } else if (!strcmp(arg,"-D1")) {
51 debug_flags= ~(dbg_sql2|dbg_lp|dbg_value2);
59 /* glpk insists on writing stuff to stdout, and it does buffering,
60 * so we route all our debug through it this too */
62 sysassert( (realstdout= dup(1)) > 2 );
63 sysassert( output= fdopen(realstdout,"w") );
66 sysassert(! pipe(pfd) );
67 sysassert( (debugoutpid= fork()) >=0 );
69 sysassert( dup2(pfd[0],0)==0 );
70 sysassert( dup2(2,1)==1 );
71 sysassert(! close(pfd[0]) );
72 sysassert(! close(pfd[1]) );
73 sysassert(! execlp("cat","cat",(char*)0) );
75 sysassert( dup2(pfd[1],1)==1 );
76 sysassert(! close(pfd[0]) );
77 sysassert(! close(pfd[1]) );
85 sysassert( !setvbuf(debug,0,_IOLBF,0) );
87 max_mass= atof(*argv++);
88 max_volu= atof(*argv++);
89 max_capi= atof(*argv++);
90 double loss_per_league= atof(*argv++);
91 distance_loss_factor_per_league= 1.0 - loss_per_league;
93 min_trade_maxprofit= atoi(*argv++);
99 for (i=0; i<narches; i++)
100 fprintf(output,"arch %d %s\n",i,archnames[i]);
101 fprintf(output,"setup complete, starting search\n");
104 if (!strcmp(arg,"specific")) {
106 while ((arg= *argv++))
109 double val= value_route(ni, ia, 0);
110 fprintf(output, "route value is %g\n", val);
111 } else if (!strcmp(arg,"search")) {
112 for (granui=0; granui<GRANUS; granui++)
113 MCALLOC(results[granui], argc);
115 max_dist= atoi(*argv++);
117 for (ap=0; ap<AP; ap++) {
118 int nhs= atoi(*argv++);
119 for (granui=0; granui<GRANUS; granui++) {
120 nhighscores[granui][ap]= nhs;
121 MCALLOC(highscores[granui][ap], nhs);
124 const char *final_isle_spec= *argv++;
127 while ((arg= argv[resultsix])) {
128 int init_isle= atoi(arg);
131 if (!strcmp(final_isle_spec,"circ")) final_isle= init_isle;
132 else if (!strcmp(final_isle_spec,"any")) final_isle= -1;
133 else final_isle= atoi(final_isle_spec);
136 Bucket ****buckets_base_io[GRANUS];
137 for (granui=0; granui<GRANUS; granui++)
138 buckets_base_io[granui]= &results[granui][resultsix];
140 search(init_isle, final_isle, buckets_base_io);
145 for (granui=0; granui<granus; granui++) {
146 fprintf(output,"\n");
147 for (i=0; i<resultsix; i++) {
148 tabdebugf("========== start #%d granui%d %s ==========\n",
150 Bucket ***buckets_resultsix= results[granui][i];
151 if (!buckets_resultsix) continue;
153 for (mid=0; mid<granusz_mid[granui]; mid++) {
154 tabdebugf("| m%-3d ",mid);
157 for (fin=0; fin<granusz_fin[granui]; fin++) {
158 Bucket **buckets_fin= buckets_resultsix[fin];
159 if (!buckets_fin) continue;
160 tabdebugf("f%-3d",fin);
161 for (mid=0; mid<granusz_mid[granui]; mid++) {
162 Bucket *result= buckets_fin[mid];
166 tabdebugf("|%5d",(int)(result->prs[A].value[A]));
168 tabdebugf("%4d",(int)(result->prs[P].value[P]));
175 for (ap=0; ap<AP; ap++) {
177 fprintf(output,"============== granui%d ap=%d ==============\n",
179 for (pos=nhighscores[granui][ap]-1; pos>=0; pos--) {
180 HighScoreEntry *hs= &highscores[granui][ap][pos];
181 Bucket *bucket= hs->bucket;
182 if (!bucket) continue;
183 OnePotentialResult *pr= &bucket->prs[ap];
184 const int *const ports= pr->ports;
186 for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);
187 int finisle= ports[nports-1];
188 int finarch= isle2arch(finisle);
189 int midisle= ports[nports/2];
190 int midarch= route2midarch(ports,nports);
192 " @%2d %c#%2d | start%3d mid%d:%3d f%d:%3d | %5d %5d %4d |",
193 pos, "ap"[ap], nhighscores[granui][ap] - pos,
194 ports[0], midarch,midisle, finarch,finisle,
195 (int)hs->value, (int)pr->value[A], (int)pr->value[P]);
196 for (i=0; i<nports; i++) fprintf(output," %d",ports[i]);
197 fprintf(output,"\n");
201 fprintf(output,"\n");
207 #define CTR(x) fprintf(output," %-30s %10d\n",#x,ctr_##x);
208 #define CTRA(x,n) for (i=0;i<n;i++) \
209 fprintf(output," %-27s[%d] %10d\n",#x,i,ctr_##x[i]);
214 sysassert(! fclose(debug) );
215 waitpid_check_exitstatus(debugoutpid,"debug cat",1);
217 sysassert(! fclose(output) );