chiark / gitweb /
routesearch: rename strat to granu and bucket
authorIan Jackson <ian@liberator.(none)>
Wed, 14 Oct 2009 17:36:05 +0000 (18:36 +0100)
committerIan Jackson <ian@liberator.(none)>
Wed, 14 Oct 2009 17:36:05 +0000 (18:36 +0100)
yarrg/rscommon.h
yarrg/rsmain.c
yarrg/rssearch.c

index 9e1032a..f02ffc0 100644 (file)
@@ -30,10 +30,10 @@ extern FILE *debug_file;
    CTR(routes_considered)                      \
    CTR(routes_wrongfinalelim)                  \
    CTR(routes_quickelim)                       \
-   CTR(routes_stratelim)                       \
+   CTR(routes_bucketelim)                      \
    CTR(routes_valued)                          \
    CTR(routes_wrongfinal)                      \
-   CTRA(newbests_strat,2)                      \
+   CTRA(newbests_granu,2)                      \
    CTR(subroute_tails_valued)                  \
    CTR(subroutes_valued)                       \
    CTR(subroutes_nonempty)
@@ -121,12 +121,12 @@ typedef struct {
   int ports[AP][MAX_ROUTELEN];
 } PotentialResult;
 
-#define STRATS 3
+#define GRANUS 3
 
 void setup_search(void);
 void search(int start_isle, int final_isle /* -1 means any */,
-           PotentialResult ****strat_base_io[STRATS]
-               /* strat_base[strati][finalthing][midthing]-> */);
+           PotentialResult ****buckets_base_io[GRANUS]
+               /* bucket_base[granui][finalthing][midthing]-> */);
 
 extern double max_mass, max_volu, max_capi;
 extern double distance_loss_factor_per_league;
@@ -140,7 +140,7 @@ extern int narches;
 extern char **archnames;
 extern int *islandid2arch;
 
-extern int stratsz_fin[STRATS], stratsz_mid[STRATS];
+extern int granusz_fin[GRANUS], granusz_mid[GRANUS];
 
 
 extern FILE *output;
@@ -165,9 +165,9 @@ typedef struct {
   PotentialResult *pr;
 } HighScoreEntry;
 
-extern int minstrat;
-extern int nhighscores[STRATS][AP];
-extern HighScoreEntry *highscores[STRATS][AP];
+extern int mingranu;
+extern int nhighscores[GRANUS][AP];
+extern HighScoreEntry *highscores[GRANUS][AP];
 
 
 #define ONDEMAND(pointer_lvalue, calloc_size_count)                         \
index 50b7348..04d08ff 100644 (file)
@@ -21,15 +21,15 @@ FILE *output;
 #undef CTR
 #undef CTRA
 
-static PotentialResult ****results[STRATS];
-  /* results[STRATS][start_isle_ix][finalisle][midisle]-> */
+static PotentialResult ****results[GRANUS];
+  /* results[GRANUS][start_isle_ix][finalisle][midisle]-> */
 
 static pid_t debugoutpid;
 
 int main(int argc, const char **argv) {
   const char *arg;
   int i, ap;
-  int strati;
+  int granui;
 
 #ifndef debug_flags
   debug_flags= ~( dbg_sql2 );
@@ -102,16 +102,16 @@ int main(int argc, const char **argv) {
     double val= value_route(ni, ia, 0);
     fprintf(output, "route value is %g\n", val);
   } else if (!strcmp(arg,"search")) {
-    for (strati=0; strati<STRATS; strati++)
-      MCALLOC(results[strati], argc);
+    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 (strati=0; strati<STRATS; strati++) {
-       nhighscores[strati][ap]= nhs;
-       MCALLOC(highscores[strati][ap], nhs);
+      for (granui=0; granui<GRANUS; granui++) {
+       nhighscores[granui][ap]= nhs;
+       MCALLOC(highscores[granui][ap], nhs);
       }
     }
     const char *final_isle_spec= *argv++;
@@ -126,33 +126,33 @@ int main(int argc, const char **argv) {
       else final_isle= atoi(final_isle_spec);
       assert(final_isle);
 
-      PotentialResult ****strat_base_io[STRATS];
-      for (strati=0; strati<STRATS; strati++)
-       strat_base_io[strati]= &results[strati][resultsix];
+      PotentialResult ****buckets_base_io[GRANUS];
+      for (granui=0; granui<GRANUS; granui++)
+       buckets_base_io[granui]= &results[granui][resultsix];
        
-      search(init_isle, final_isle, strat_base_io);
+      search(init_isle, final_isle, buckets_base_io);
       resultsix++;
     }
 
     int mid, fin;
-    for (strati=minstrat; strati<STRATS; strati++) {
+    for (granui=mingranu; granui<GRANUS; granui++) {
       fprintf(output,"\n");
       for (i=0; i<resultsix; i++) {
-       tabdebugf("========== start #%d strati%d %s [PARTIAL] ==========\n",
-                 i, strati, argv[i]);
-       PotentialResult ***strat_resultsix= results[strati][i];
-       if (!strat_resultsix) continue;
+       tabdebugf("========== start #%d granui%d %s [PARTIAL] ==========\n",
+                 i, granui, argv[i]);
+       PotentialResult ***buckets_resultsix= results[granui][i];
+       if (!buckets_resultsix) continue;
        tabdebugf("    ");
-       for (mid=0; mid<stratsz_mid[strati]; mid++) {
+       for (mid=0; mid<granusz_mid[granui]; mid++) {
          tabdebugf("|   m%-3d   ",mid);
        }
        tabdebugf("\n");
-       for (fin=0; fin<stratsz_fin[strati]; fin++) {
-         PotentialResult **strat_fin= strat_resultsix[fin];
-         if (!strat_fin) continue;
+       for (fin=0; fin<granusz_fin[granui]; fin++) {
+         PotentialResult **buckets_fin= buckets_resultsix[fin];
+         if (!buckets_fin) continue;
          tabdebugf("f%-3d",fin);
-         for (mid=0; mid<stratsz_mid[strati]; mid++) {
-           PotentialResult *result= strat_fin[mid];
+         for (mid=0; mid<granusz_mid[granui]; mid++) {
+           PotentialResult *result= buckets_fin[mid];
            if (!result) {
              tabdebugf("|          ");
            } else {
@@ -167,10 +167,10 @@ int main(int argc, const char **argv) {
 
       for (ap=0; ap<AP; ap++) {
        int pos;
-       fprintf(output,"============== strati%d ap=%d ==============\n",
-               strati, ap);
-       for (pos=0; pos<nhighscores[strati][ap]; pos++) {
-         HighScoreEntry *hs= &highscores[strati][ap][pos];
+       fprintf(output,"============== granui%d ap=%d ==============\n",
+               granui, ap);
+       for (pos=0; pos<nhighscores[granui][ap]; pos++) {
+         HighScoreEntry *hs= &highscores[granui][ap][pos];
          PotentialResult *pr= hs->pr;
          if (!pr) continue;
          const int *const ports= pr->ports[ap];
@@ -182,14 +182,14 @@ int main(int argc, const char **argv) {
          int midarch= route2midarch(ports,nports);
          fprintf(output,
                  " @%2d #%2d | start%3d mid%d:%3d f%d:%3d | %5d %5d %4d |",
-                 pos, nhighscores[strati][ap] - 1 - pos,
+                 pos, nhighscores[granui][ap] - 1 - 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 */
-    } /* strati */
+    } /* granui */
     fprintf(output,"\n");
 
   } else {
index bb84785..91bbc22 100644 (file)
@@ -38,7 +38,7 @@ static Neighbour *get_neighbours(int isle) {
 }
 
 
-static PotentialResult ***strat_base[STRATS];
+static PotentialResult ***buckets_base[GRANUS];
 
 
 static double process_route(int nports, int totaldist,
@@ -79,8 +79,8 @@ static double process_route(int nports, int totaldist,
       return guess[A];
     }
 
-    if (guess[A] <= highscores[minstrat][A][0].value &&
-       guess[P] <= highscores[minstrat][P][0].value) {
+    if (guess[A] <= highscores[mingranu][A][0].value &&
+       guess[P] <= highscores[mingranu][P][0].value) {
       ctr_routes_quickelim++;
       debugf(" QELIM %f %f\n", guess[A], guess[P]);
       return guess[A];
@@ -93,25 +93,25 @@ static double process_route(int nports, int totaldist,
   int midisle= ports[nports/2];
   int midarch= route2midarch(ports,nports);
 
-  PotentialResult *strats[STRATS];
-  int strati;
-  for (strati=minstrat; strati<STRATS; strati++) {
-    PotentialResult **strat_fin;
+  PotentialResult *buckets[GRANUS];
+  int granui;
+  for (granui=mingranu; granui<GRANUS; granui++) {
+    PotentialResult **buckets_fin;
     int mid, fin;
-    switch (strati) {
+    switch (granui) {
     case 0: fin=finisle; mid=midisle; break;
     case 1: fin=finisle; mid=midarch; break;
     case 2: fin=finarch; mid=midarch; break;
     default: abort();
     }
-    strat_fin= ONDEMAND(strat_base[strati][fin], stratsz_mid[strati]);
-    strats[strati]= ONDEMAND(strat_fin[mid], 1);
+    buckets_fin= ONDEMAND(buckets_base[granui][fin], granusz_mid[granui]);
+    buckets[granui]= ONDEMAND(buckets_fin[mid], 1);
   }
 
   if (nports>=2) {
-    if (guess[A] <= strats[minstrat]->value[A] &&
-       guess[P] <= strats[minstrat]->value[P]) {
-      ctr_routes_stratelim++;
+    if (guess[A] <= buckets[mingranu]->value[A] &&
+       guess[P] <= buckets[mingranu]->value[P]) {
+      ctr_routes_bucketelim++;
       debugf(" ELIM %f %f\n", guess[A], guess[P]);
       return guess[A];
     }
@@ -129,33 +129,33 @@ static double process_route(int nports, int totaldist,
     return value[0];
   }
 
-  for (strati=minstrat; strati<STRATS; strati++) {
-    PotentialResult *strat= strats[strati];
+  for (granui=mingranu; granui<GRANUS; granui++) {
+    PotentialResult *bucket= buckets[granui];
 
-    if (value[A] <= strat->value[A] &&
-       value[P] <= strat->value[P])
+    if (value[A] <= bucket->value[A] &&
+       value[P] <= bucket->value[P])
       continue;
 
-    debugf(" SOMEHOW %d BEST\n",strati);
+    debugf(" SOMEHOW %d BEST\n",granui);
 
     fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch);
 
     for (ap=0; ap<AP; ap++) {
-      HighScoreEntry *scores= highscores[strati][ap];
-      int *nscores= &nhighscores[strati][ap];
+      HighScoreEntry *scores= highscores[granui][ap];
+      int *nscores= &nhighscores[granui][ap];
 
       fildebugf("ap=%d %15f", ap, value[ap]);
-      if (value[ap] < strat->value[ap]) {
+      if (value[ap] < bucket->value[ap]) {
        debugf("      ");
       } else {
        int pos;
-       ctr_newbests_strat[ap]++;
-       strat->value[ap]= value[ap];
-       memcpy(strat->ports[ap], ports, sizeof(*ports) * nports);
-       if (nports < MAX_ROUTELEN-1) strat->ports[ap][nports]= -1;
+       ctr_newbests_granu[ap]++;
+       bucket->value[ap]= value[ap];
+       memcpy(bucket->ports[ap], ports, sizeof(*ports) * nports);
+       if (nports < MAX_ROUTELEN-1) bucket->ports[ap][nports]= -1;
        fildebugf("** ");
        for (pos=0; pos < *nscores; pos++)
-         if (scores[pos].pr == strat) goto found;
+         if (scores[pos].pr == bucket) goto found;
        /* not found */
        pos= -1;
       found:
@@ -169,7 +169,7 @@ static double process_route(int nports, int totaldist,
        pos--;
        if (pos>0) {
          scores[pos].value= value[ap];
-         scores[pos].pr= strat;
+         scores[pos].pr= bucket;
        }
        fildebugf("@%2d", pos);
       }
@@ -203,18 +203,19 @@ static void recurse(int last_isle,
 }
 
 void search(int start_isle, int final_isle_spec,
-           PotentialResult ****strat_base_io[STRATS]) {
-  int strati;
-  for (strati=0; strati<STRATS; strati++)
-    strat_base[strati]= ONDEMAND(*strat_base_io[strati], stratsz_fin[strati]);
+           PotentialResult ****buckets_base_io[GRANUS]) {
+  int granui;
+  for (granui=0; granui<GRANUS; granui++)
+    buckets_base[granui]=
+      ONDEMAND(*buckets_base_io[granui], granusz_fin[granui]);
 
   final_isle= final_isle_spec <= 0 ? 0 : final_isle_spec;
   recurse(start_isle,0,0,1e6);
 }
 
-int nhighscores[STRATS][AP];
-HighScoreEntry *highscores[STRATS][AP];
-int minstrat, stratsz_fin[STRATS], stratsz_mid[STRATS];
+int nhighscores[GRANUS][AP];
+HighScoreEntry *highscores[GRANUS][AP];
+int mingranu, granusz_fin[GRANUS], granusz_mid[GRANUS];
 
 int narches;
 char **archnames;
@@ -253,7 +254,7 @@ void setup_search(void) {
   }
   sqlite3_finalize(archs);
 
-  stratsz_fin[0]=                stratsz_mid[0]= islandtablesz;
-  stratsz_fin[1]= islandtablesz; stratsz_mid[1]= narches;
-  stratsz_fin[2]=                stratsz_mid[2]= narches;
+  granusz_fin[0]=                granusz_mid[0]= islandtablesz;
+  granusz_fin[1]= islandtablesz; granusz_mid[1]= narches;
+  granusz_fin[2]=                granusz_mid[2]= narches;
 }