X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Frssearch.c;h=5ad6136180fa528ab220c06b8c74ad78771954af;hp=c51aae02f655571571b246aec89e578e2aef2b58;hb=65f040fe1768142719f2ac268904ed0e1d8f1ec0;hpb=0145dc7f4fcaf62090a77fb2d69d5d7807c8d48d diff --git a/yarrg/rssearch.c b/yarrg/rssearch.c index c51aae0..5ad6136 100644 --- a/yarrg/rssearch.c +++ b/yarrg/rssearch.c @@ -2,6 +2,9 @@ #include "rscommon.h" +DEBUG_DEFINE_DEBUGF(search); +DEBUG_DEFINE_SOME_DEBUGF(filter,fildebugf); + typedef struct Neighbour { struct Neighbour *next; int islandid; @@ -12,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]; @@ -20,7 +24,8 @@ static Neighbour *get_neighbours(int isle) { SQL_BIND(ss_neigh, 1, isle); while (SQL_STEP(ss_neigh)) { - Neighbour *add= mmalloc(sizeof(*add)); + Neighbour *add; + NEW(add); add->islandid= sqlite3_column_int(ss_neigh, 0); add->dist= sqlite3_column_int(ss_neigh, 1); add->next= head; @@ -32,26 +37,160 @@ static Neighbour *get_neighbours(int isle) { return head; } -static double bestsofar; -static void process_route(int nports) { - double value= value_route(nports, ports); - if (value < bestsofar) return; +static PotentialResult ***buckets_base[GRANUS]; + + +static double process_route(int nports, int totaldist, + double overestimate_excepting_tail) { + int i, ap; + int leagues_divisor= totaldist + nports; + + ctr_routes_considered++; + + int wrong_final= final_isle && ports[nports-1] != final_isle; + + debugf("========== ROUTE"); + for (i=0; i=2) { + int pair[2], i; + pair[1]= ports[nports-1]; + guess[A]= overestimate_excepting_tail; + + for (i=0; iroute_tail_value < 0) { + ctr_subroute_tails_valued++; + ip->route_tail_value= value_route(2, pair, pair[0]!=pair[1]); + } + guess[A] += ip->route_tail_value; + } + guess[P]= guess[A] / leagues_divisor; + + if (wrong_final) { + ctr_routes_wrongfinalelim++; + debugf(" WFELIM\n"); + return guess[A]; + } + + 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]; + } + } + + int finisle= ports[nports-1]; + int finarch= isle2arch(finisle); + + int midisle= ports[nports/2]; + int midarch= route2midarch(ports,nports); + + PotentialResult *buckets[GRANUS]; + int granui; + for (granui=mingranu; granui=2) { + 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]; + } + debugf(" COMPUTE %f %f\n", guess[A], guess[P]); + } + + ctr_routes_valued++; + + double value[AP]; + value[A]= value_route(nports, ports, 0); + value[P]= value[A] / leagues_divisor; + + if (wrong_final) { + ctr_routes_wrongfinal++; + return value[0]; + } + + for (granui=mingranu; granuivalue[A] && + value[P] <= bucket->value[P]) + continue; + + debugf(" SOMEHOW %d BEST\n",granui); + + fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch); + + for (ap=0; apvalue[ap]) { + debugf(" "); + } else { + int pos; + 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 == bucket) goto found; + /* not found */ + pos= -1; + found: + for (;;) { + pos++; + if (pos >= *nscores-1) break; /* new top */ + if (scores[pos].value >= value[ap]) break; /* found spot */ + if (pos>0) + scores[pos-1]= scores[pos]; + } + pos--; + if (pos>0) { + scores[pos].value= value[ap]; + scores[pos].pr= bucket; + } + fildebugf("@%2d", pos); + } + } + } + + fildebugf(" route"); - fprintf(stderr,"value %20f route", value); - int i; for (i=0; i= MAX_ROUTELEN) return; Neighbour *add; @@ -59,17 +198,63 @@ static void recurse(int last_isle, int newdist= totaldist + add->dist; if (newdist > max_dist) continue; - recurse(add->islandid, nports, newdist); + recurse(add->islandid, nports, newdist, estimate); } } -void search(int start_isle) { - recurse(start_isle,0,0); +void search(int start_isle, int final_isle_spec, + PotentialResult ****buckets_base_io[GRANUS]) { + int granui; + for (granui=0; granui