chiark / gitweb /
WIP routesearch; stratify results by significant bits of route
authorIan Jackson <ian@liberator.(none)>
Wed, 7 Oct 2009 21:13:39 +0000 (22:13 +0100)
committerIan Jackson <ian@liberator.(none)>
Wed, 7 Oct 2009 21:13:39 +0000 (22:13 +0100)
yarrg/rscommon.h
yarrg/rsmain.c
yarrg/rssearch.c

index 7c70ca4..873ff30 100644 (file)
@@ -8,6 +8,7 @@
    DF(sql2)                                    \
    DF(value)                                   \
    DF(search)                                  \
+   DF(filter)                                  \
    DF(check)                                   \
    DF(lp)
 
@@ -100,8 +101,14 @@ IslandPair *ipair_get_maybe(int si, int di);
 double value_route(int nislands, const int *islands, int exclude_arbitrage);
 void setup_value(void);
 
+typedef struct {
+  double absolute, perleague;
+  int absolute_ports[MAX_ROUTELEN], perleague_ports[MAX_ROUTELEN];
+} PotentialResult;
+
 void setup_search(void);
-void search(int start_isle);
+void search(int start_isle, PotentialResult ****strat_base_io
+                                /* strat_base[finalisle][midisle]-> */);
 
 extern double max_mass, max_volu, max_capi;
 extern double distance_loss_factor_per_league;
@@ -112,4 +119,9 @@ extern int max_dist;
 extern int islandtablesz;
 
 
+#define ONDEMAND(pointer_lvalue, calloc_size_count)                         \
+  ((pointer_lvalue) ? :                                                             \
+   ((pointer_lvalue) = mcalloc(sizeof(*(pointer_lvalue)) * calloc_size_count)))
+
+
 #endif /*RSCOMMON_H*/
index da05f47..0e43d5d 100644 (file)
@@ -11,6 +11,9 @@ int max_dist= -1;
   COUNTER_LIST
 #undef CTR
 
+static PotentialResult ****results;
+  /* results[start_isle_ix][finalisle][midisle]-> */
+
 int main(int argc, const char **argv) {
   const char *arg;
 
@@ -55,9 +58,43 @@ int main(int argc, const char **argv) {
     double val= value_route(ni, ia, 0);
     printf("route value is %g\n", val);
   } else if (!strcmp(arg,"search")) {
+    results= mcalloc(sizeof(*results)*argc);
     max_dist= atoi(*argv++);
-    while ((arg= *argv++))
-      search(atoi(arg));
+    int resultsix= 0;
+    while ((arg= *argv++)) {
+      search(atoi(arg), &results[resultsix]);
+      resultsix++;
+    }
+
+    int i, midisle, finisle;
+    for (i=0; i<resultsix; i++) {
+      fprintf(stderr,"================== start #%d ==================\n",i);
+      PotentialResult ***strat_resultsix= results[i];
+      if (!strat_resultsix) continue;
+      fprintf(stderr,"    ");
+      for (midisle=0; midisle<islandtablesz; midisle++) {
+       fprintf(stderr,"|mi%-3d",midisle);
+      }
+      fprintf(stderr,"\n");
+      for (finisle=0; finisle<islandtablesz; finisle++) {
+       PotentialResult **strat_finisle= strat_resultsix[finisle];
+       if (!strat_finisle) continue;
+       fprintf(stderr,"f%-3d",finisle);
+       for (midisle=0; midisle<islandtablesz; midisle++) {
+         PotentialResult *result= strat_finisle[midisle];
+         if (!result) {
+           fprintf(stderr,"|     ");
+         } else {
+           if (result->absolute < 1000) fprintf(stderr,"| <");
+           else fprintf(stderr,"|%2d",(int)(result->absolute / 1000));
+           fprintf(stderr," ");
+           if (result->perleague < 100) fprintf(stderr," <");
+           else fprintf(stderr,"%2d",(int)(result->perleague / 100));
+         }
+       }
+       fprintf(stderr,"\n");
+      }
+    }
   } else {
     abort();
   }
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);
 }