chiark / gitweb /
routesearch: allow constraining destination island
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 9 Oct 2009 21:29:49 +0000 (22:29 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 9 Oct 2009 21:31:08 +0000 (22:31 +0100)
yarrg/rscommon.h
yarrg/rsmain.c
yarrg/rssearch.c
yarrg/x.gdb

index 0933e0f..0a6f306 100644 (file)
    CTR(ipairs_relevant)                                \
    CTR(quantities_loaded)                      \
    CTR(routes_considered)                      \
+   CTR(routes_wrongfinalelim)                  \
    CTR(routes_quickelim)                       \
    CTR(routes_stratelim)                       \
    CTR(routes_valued)                          \
+   CTR(routes_wrongfinal)                      \
    CTR(newbests_strat_absolute)                        \
-   CTR(newbests_strat_perleague)                       \
+   CTR(newbests_strat_perleague)               \
    CTR(subroute_tails_valued)                  \
    CTR(subroutes_valued)                       \
    CTR(subroutes_nonempty)
@@ -112,8 +114,9 @@ typedef struct {
 } PotentialResult;
 
 void setup_search(void);
-void search(int start_isle, PotentialResult ****strat_base_io
-                                /* strat_base[finalarch][midarch]-> */);
+void search(int start_isle, int final_isle /* -1 means any */,
+           PotentialResult ****strat_base_io
+               /* strat_base[finalarch][midarch]-> */);
 
 extern double max_mass, max_volu, max_capi;
 extern double distance_loss_factor_per_league;
index 9283fbc..c76e7da 100644 (file)
@@ -2,6 +2,8 @@
 
 #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;
@@ -63,19 +65,28 @@ int main(int argc, const char **argv) {
     max_dist= atoi(*argv++);
     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])) {
-      search(atoi(arg), &results[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 ==============\n",
+      fprintf(stderr,"============== start #%d %s [PARTIAL] ==============\n",
              i, argv[i]);
       PotentialResult ***strat_resultsix= results[i];
       if (!strat_resultsix) continue;
index 5c6cc66..fd2e66a 100644 (file)
@@ -15,6 +15,7 @@ static Neighbour **neighbours; /* neighbours[islandid]->islandid etc. */
 static sqlite3_stmt *ss_neigh;
 
 static int ports[MAX_ROUTELEN];
+static int final_isle;
 
 static Neighbour *get_neighbours(int isle) {
   Neighbour **np= &neighbours[isle];
@@ -47,6 +48,8 @@ static double process_route(int nports, int totaldist,
 
   ctr_routes_considered++;
 
+  int wrong_final= final_isle && ports[nports-1] != final_isle;
+
   debugf("========== ROUTE");
   for (i=0; i<nports; i++)
     debugf(" %d",ports[i]);
@@ -70,6 +73,12 @@ static double process_route(int nports, int totaldist,
     }
     guess_perleague= guess_absolute / leagues_divisor;
 
+    if (wrong_final) {
+      ctr_routes_wrongfinalelim++;
+      debugf(" WFELIM\n");
+      return guess_absolute;
+    }
+
     if (guess_absolute <= highscores_absolute[0].value &&
        guess_perleague <= highscores_perleague[0].value) {
       ctr_routes_quickelim++;
@@ -99,6 +108,11 @@ static double process_route(int nports, int totaldist,
   double absolute= value_route(nports, ports, 0);
   double perleague= absolute / leagues_divisor;
 
+  if (wrong_final) {
+    ctr_routes_wrongfinal++;
+    return absolute;
+  }
+
   if (absolute <= strat->absolute &&
       perleague <= strat->perleague)
     return absolute;
@@ -167,8 +181,10 @@ static void recurse(int last_isle,
   }
 }
 
-void search(int start_isle, PotentialResult ****strat_base_io) {
+void search(int start_isle, int final_isle_spec,
+           PotentialResult ****strat_base_io) {
   strat_base= ONDEMAND(*strat_base_io, narches);
+  final_isle= final_isle_spec <= 0 ? 0 : final_isle_spec;
   recurse(start_isle,0,0,1e6);
 }
 
index e83ccaf..37eff38 100644 (file)
@@ -1,5 +1,5 @@
 file ./routesearch
-set args -DN 13460 20210 -1 0.0005 search 30 20 20  4 19 134 32 13 24 36
+set args -DN 13460 20210 -1 0.0005 search 30 20 20 36  4 19 134 32 13 24 36
 break setup_search
 run
 finish