chiark / gitweb /
routesearch: allow constraining destination island
[ypp-sc-tools.db-live.git] / yarrg / rsmain.c
index 7904c01..c76e7da 100644 (file)
@@ -2,31 +2,41 @@
 
 #include "rscommon.h"
 
+#include <ctype.h>
+
 int o_quiet= 0;
 double max_mass=-1, max_volu=-1, max_capi=-1;
 double distance_loss_factor_per_league;
 int max_dist= -1;
 
+#define CTR(x) int ctr_##x;
+  COUNTER_LIST
+#undef CTR
+
+static PotentialResult ****results;
+  /* results[start_isle_ix][finalisle][midisle]-> */
+
 int main(int argc, const char **argv) {
   const char *arg;
 
+#ifndef debug_flags
   debug_flags= ~( dbg_sql2 );
+#endif
   sysassert( !setvbuf(debug,0,_IOLBF,0) );
   
   for (;;) {
     arg= *++argv;
     if (arg[0] != '-') break;
+#ifndef debug_flags
     if (!strcmp(arg,"-DN")) {
       debug_flags= 0;
-    } else {
+    } else
+#endif
+    {
       abort();
     }
   }
 
-  setup_sql();
-  setup_value();
-  setup_search();
-
   max_mass= atof(*argv++);
   max_volu= atof(*argv++);
   max_capi= atof(*argv++);
@@ -34,6 +44,12 @@ int main(int argc, const char **argv) {
 
   if (!loss_per_league) loss_per_league= 1e-7;
   distance_loss_factor_per_league= 1.0 - loss_per_league;
+
+  setup_sql();
+  setup_value();
+  setup_search();
+
+  fprintf(stderr,"setup complete, starting search\n");
   
   arg= *argv++;
   if (!strcmp(arg,"specific")) {
@@ -41,14 +57,92 @@ int main(int argc, const char **argv) {
     while ((arg= *argv++))
       ia[ni++]= atoi(arg);
 
-    double val= value_route(ni, ia);
+    double val= value_route(ni, ia, 0);
     printf("route value is %g\n", val);
   } else if (!strcmp(arg,"search")) {
+    MCALLOC(results, argc);
+
     max_dist= atoi(*argv++);
-    while ((arg= *argv++))
-      search(atoi(arg));
+    nhighscores_absolute= atoi(*argv++);
+    nhighscores_perleague= atoi(*argv++);
+    const char *final_isle_spec= *argv++;
+
+    MCALLOC(highscores_absolute, nhighscores_absolute);
+    MCALLOC(highscores_perleague, nhighscores_perleague);
+
+    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);
+
+      search(init_isle, final_isle, &results[resultsix]);
+      resultsix++;
+    }
+
+    int i, midarch, finarch;
+    for (i=0; i<resultsix; i++) {
+      fprintf(stderr,"============== start #%d %s [PARTIAL] ==============\n",
+             i, argv[i]);
+      PotentialResult ***strat_resultsix= results[i];
+      if (!strat_resultsix) continue;
+      fprintf(stderr,"  ");
+      for (midarch=0; midarch<narches; midarch++) {
+       fprintf(stderr,"|   mid %d  ",midarch);
+      }
+      fprintf(stderr,"\n");
+      for (finarch=0; finarch<narches; finarch++) {
+       PotentialResult **strat_finarch= strat_resultsix[finarch];
+       if (!strat_finarch) continue;
+       fprintf(stderr,"f%d",finarch);
+       for (midarch=0; midarch<narches; midarch++) {
+         PotentialResult *result= strat_finarch[midarch];
+         if (!result) {
+           fprintf(stderr,"|          ");
+         } else {
+           fprintf(stderr,"|%5d",(int)(result->absolute));
+           fprintf(stderr," ");
+           fprintf(stderr,"%4d",(int)(result->perleague));
+         }
+       }
+       fprintf(stderr,"\n");
+      }
+    }
+
+    int pos;
+#define OUT(absperl)                                                         \
+    fprintf(stderr,"\n================== " #absperl " ==================\n"); \
+    for (pos=0; pos<nhighscores_##absperl; pos++) {                          \
+      HighScoreEntry *hs= &highscores_##absperl[pos];                        \
+      PotentialResult *pr= hs->pr;                                           \
+      if (!pr) continue;                                                     \
+      const int *const ports= pr->absperl##_ports;                           \
+      int nports;                                                            \
+      for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);      \
+      int finisle= ports[nports-1]; int finarch= isle2arch(finisle);         \
+      int midarch= route2midarch(ports,nports);                                      \
+      fprintf(stderr,                                                        \
+             " @%2d #%2d | start%3d mid%d f%d:%3d | %5d %5d %4d |",     \
+             pos, nhighscores_##absperl - 1 - pos,                           \
+             ports[0], midarch, finarch,finisle,                     \
+             (int)hs->value, (int)pr->absolute, (int)pr->perleague);         \
+      for (i=0; i<nports; i++) fprintf(stderr," %d",ports[i]);               \
+      fprintf(stderr,"\n");                                                  \
+    }
+    OUT(absolute)
+    OUT(perleague)
+    
   } else {
     abort();
   }
+
+#define CTR(x) fprintf(stderr,"  %-30s %10d\n",#x,ctr_##x);
+  COUNTER_LIST
+#undef CTR
+
   return 0;
 }