chiark / gitweb /
routesearch: change granu to be higher for more specific (more granularity)
[ypp-sc-tools.db-test.git] / yarrg / rssearch.c
index bb84785..9676640 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[GRANUS-1][A][0].value &&
+       guess[P] <= highscores[GRANUS-1][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=0; granui<granus; granui++) {
+    PotentialResult **buckets_fin;
     int mid, fin;
-    switch (strati) {
-    case 0: fin=finisle; mid=midisle; break;
+    switch (granui) {
+    case 0: fin=finarch; mid=midarch; break;
     case 1: fin=finisle; mid=midarch; break;
-    case 2: fin=finarch; mid=midarch; break;
+    case 2: fin=finisle; mid=midisle; 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[0]->value[A] &&
+       guess[P] <= buckets[0]->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=granus-1; granui>=0; 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[granui*AP+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 granus=GRANUS, 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]= narches;
+  granusz_fin[1]= islandtablesz; granusz_mid[1]= narches;
+  granusz_fin[2]=                granusz_mid[2]= islandtablesz;
 }