chiark / gitweb /
WIP routesearch; stratify results by significant bits of route
[ypp-sc-tools.main.git] / yarrg / rssearch.c
index 87914a8..0a17adf 100644 (file)
@@ -3,6 +3,7 @@
 #include "rscommon.h"
 
 DEBUG_DEFINE_DEBUGF(search);
+DEBUG_DEFINE_SOME_DEBUGF(filter,fildebugf);
 
 typedef struct Neighbour {
   struct Neighbour *next;
@@ -34,7 +35,9 @@ static Neighbour *get_neighbours(int isle) {
   return head;
 }
 
-static double best_absolute, best_perleague;
+
+static PotentialResult ***strat_base;
+
 
 static double process_route(int nports, int totaldist,
                            double overestimate_excepting_tail) {
@@ -48,6 +51,12 @@ static double process_route(int nports, int totaldist,
     debugf(" %d",ports[i]);
   debugf("\n");
 
+  int finalisle= ports[nports-1];
+  int midisle= ports[nports/2];
+
+  PotentialResult **strat_fin= ONDEMAND(strat_base[finalisle], islandtablesz);
+  PotentialResult *strat= ONDEMAND(strat_fin[midisle], 1);
+
   if (nports>=2) {
     int pair[2], i;
     pair[1]= ports[nports-1];
@@ -65,7 +74,8 @@ static double process_route(int nports, int totaldist,
     }
     double guess_perleague= guess_absolute / leagues_divisor;
 
-    if (guess_absolute <= best_absolute && guess_perleague <= best_perleague) {
+    if (guess_absolute <= strat->absolute &&
+       guess_perleague <= strat->perleague) {
       ctr_routes_eliminated++;
       debugf(" ELIM %f %f\n", guess_absolute, guess_perleague);
       return guess_absolute;
@@ -78,24 +88,32 @@ static double process_route(int nports, int totaldist,
   double absolute= value_route(nports, ports, 0);
   double perleague= absolute / leagues_divisor;
 
-  if (absolute <= best_absolute && perleague <= best_perleague)
+  if (absolute <= strat->absolute &&
+      perleague <= strat->perleague)
     return absolute;
 
   debugf(" SOMEHOW BEST\n");
 
-#define CHK(absperl)                                   \
-  fprintf(stderr,#absperl " %15f", absperl);           \
-  if (absperl < best_##absperl) fputs("   ",stderr);   \
-  else { best_##absperl= absperl; fputs("** ",stderr); }
+  fildebugf("final %3d mid %3d ",finalisle,midisle);
+
+#define CHK(absperl)                                                   \
+  fildebugf(#absperl " %15f", absperl);                                        \
+  if (absperl < strat->absperl) {                                      \
+    debugf("   ");                                                     \
+  } else {                                                             \
+    strat->absperl= absperl;                                           \
+    memcpy(strat->absperl##_ports, ports, sizeof(*ports) * nports);    \
+    fildebugf("** ");                                                  \
+  }
 
   CHK(absolute)
   CHK(perleague)
 
-  fputs(" route",stderr);
+  fildebugf(" route");
 
   for (i=0; i<nports; i++)
-    fprintf(stderr," %d",ports[i]);
-  putc('\n',stderr);
+    fildebugf(" %d",ports[i]);
+  fildebugf("\n");
 
   return absolute;
 }
@@ -117,7 +135,8 @@ static void recurse(int last_isle,
   }
 }
 
-void search(int start_isle) {
+void search(int start_isle, PotentialResult ****strat_base_io) {
+  strat_base= ONDEMAND(*strat_base_io, islandtablesz);
   recurse(start_isle,0,0,1e6);
 }