+
+ sysassert( !setvbuf(debug,0,_IOLBF,0) );
+
+ max_mass= atof(*argv++);
+ max_volu= atof(*argv++);
+ max_capi= atof(*argv++);
+ double loss_per_league= atof(*argv++);
+ distance_loss_factor_per_league= 1.0 - loss_per_league;
+
+ setup_sql(database);
+ setup_value();
+ setup_search();
+
+ for (i=0; i<narches; i++)
+ fprintf(output,"arch %d %s\n",i,archnames[i]);
+ fprintf(output,"setup complete, starting search\n");
+
+ arg= *argv++;
+ if (!strcmp(arg,"specific")) {
+ int ia[argc], ni=0;
+ while ((arg= *argv++))
+ ia[ni++]= atoi(arg);
+
+ double val= value_route(ni, ia, 0);
+ fprintf(output, "route value is %g\n", val);
+ } else if (!strcmp(arg,"search")) {
+ for (granui=0; granui<GRANUS; granui++)
+ MCALLOC(results[granui], argc);
+
+ max_dist= atoi(*argv++);
+
+ for (ap=0; ap<AP; ap++) {
+ int nhs= atoi(*argv++);
+ for (granui=0; granui<GRANUS; granui++) {
+ nhighscores[granui][ap]= nhs;
+ MCALLOC(highscores[granui][ap], nhs);
+ }
+ }
+ const char *final_isle_spec= *argv++;
+
+ int resultsix= 0;
+ while ((arg= argv[resultsix])) {
+ int init_isle= atoi(arg);
+
+ int final_isle;
+ if (!strcmp(final_isle_spec,"circ")) final_isle= init_isle;
+ else if (!strcmp(final_isle_spec,"any")) final_isle= -1;
+ else final_isle= atoi(final_isle_spec);
+ assert(final_isle);
+
+ Bucket ****buckets_base_io[GRANUS];
+ for (granui=0; granui<GRANUS; granui++)
+ buckets_base_io[granui]= &results[granui][resultsix];
+
+ search(init_isle, final_isle, buckets_base_io);
+ resultsix++;
+ }
+
+ int mid, fin;
+ for (granui=0; granui<granus; granui++) {
+ fprintf(output,"\n");
+ for (i=0; i<resultsix; i++) {
+ tabdebugf("========== start #%d granui%d %s ==========\n",
+ i, granui, argv[i]);
+ Bucket ***buckets_resultsix= results[granui][i];
+ if (!buckets_resultsix) continue;
+ tabdebugf(" ");
+ for (mid=0; mid<granusz_mid[granui]; mid++) {
+ tabdebugf("| m%-3d ",mid);
+ }
+ tabdebugf("\n");
+ for (fin=0; fin<granusz_fin[granui]; fin++) {
+ Bucket **buckets_fin= buckets_resultsix[fin];
+ if (!buckets_fin) continue;
+ tabdebugf("f%-3d",fin);
+ for (mid=0; mid<granusz_mid[granui]; mid++) {
+ Bucket *result= buckets_fin[mid];
+ if (!result) {
+ tabdebugf("| ");
+ } else {
+ tabdebugf("|%5d",(int)(result->prs[A].value[A]));
+ tabdebugf(" ");
+ tabdebugf("%4d",(int)(result->prs[P].value[P]));
+ }
+ }
+ tabdebugf("\n");
+ }
+ } /* i */
+
+ for (ap=0; ap<AP; ap++) {
+ int pos;
+ fprintf(output,"============== granui%d ap=%d ==============\n",
+ granui, ap);
+ for (pos=nhighscores[granui][ap]-1; pos>=0; pos--) {
+ HighScoreEntry *hs= &highscores[granui][ap][pos];
+ Bucket *bucket= hs->bucket;
+ if (!bucket) continue;
+ OnePotentialResult *pr= &bucket->prs[ap];
+ const int *const ports= pr->ports;
+ int nports;
+ for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);
+ int finisle= ports[nports-1];
+ int finarch= isle2arch(finisle);
+ int midisle= ports[nports/2];
+ int midarch= route2midarch(ports,nports);
+ fprintf(output,
+ " @%2d %c#%2d | start%3d mid%d:%3d f%d:%3d | %5d %5d %4d |",
+ pos, "ap"[ap], nhighscores[granui][ap] - pos,
+ ports[0], midarch,midisle, finarch,finisle,
+ (int)hs->value, (int)pr->value[A], (int)pr->value[P]);
+ for (i=0; i<nports; i++) fprintf(output," %d",ports[i]);
+ fprintf(output,"\n");
+ } /* pos */
+ } /* ap */
+ } /* granui */
+ fprintf(output,"\n");
+
+ } else {
+ abort();
+ }
+
+#define CTR(x) fprintf(output," %-30s %10d\n",#x,ctr_##x);
+#define CTRA(x,n) for (i=0;i<n;i++) \
+ fprintf(output," %-27s[%d] %10d\n",#x,i,ctr_##x[i]);
+ COUNTER_LIST
+#undef CTR
+
+ if (debug_flags) {
+ sysassert(! fclose(debug) );
+ waitpid_check_exitstatus(debugoutpid,"debug cat",1);
+ }
+ sysassert(! fclose(output) );
+