X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Frssearch.c;h=6674c02952a263dde69b7c4c1838e737f2a8a63d;hp=c51aae02f655571571b246aec89e578e2aef2b58;hb=d0f65e91f071ebb0fbc6791ee168e2be5ba8e5ae;hpb=0145dc7f4fcaf62090a77fb2d69d5d7807c8d48d diff --git a/yarrg/rssearch.c b/yarrg/rssearch.c index c51aae0..6674c02 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; @@ -20,7 +23,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 +36,101 @@ 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 ***strat_base; + + +static inline int isle2arch(int isle) { + int arch= islandid2arch[isle]; + assert(arch>=0); + return arch; +} - fprintf(stderr,"value %20f route", value); +static double process_route(int nports, int totaldist, + double overestimate_excepting_tail) { int i; + int leagues_divisor= totaldist + nports; + + ctr_routes_considered++; + + debugf("========== ROUTE"); for (i=0; i=2) { + int pair[2], i; + pair[1]= ports[nports-1]; + double guess_absolute= 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_absolute += ip->route_tail_value; + } + double guess_perleague= guess_absolute / leagues_divisor; + + if (guess_absolute <= strat->absolute && + guess_perleague <= strat->perleague) { + ctr_routes_eliminated++; + debugf(" ELIM %f %f\n", guess_absolute, guess_perleague); + return guess_absolute; + } + debugf(" COMPUTE %f %f\n", guess_absolute, guess_perleague); + } + + ctr_routes_valued++; + + double absolute= value_route(nports, ports, 0); + double perleague= absolute / leagues_divisor; + + if (absolute <= strat->absolute && + perleague <= strat->perleague) + return absolute; + + debugf(" SOMEHOW BEST\n"); + + fildebugf("final %d:%3d mid %d:%3d ",finarch,finisle,midarch,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) + + fildebugf(" route"); + + for (i=0; i= MAX_ROUTELEN) return; Neighbour *add; @@ -59,17 +138,50 @@ 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, PotentialResult ****strat_base_io) { + strat_base= ONDEMAND(*strat_base_io, narches); + recurse(start_isle,0,0,1e6); } + +int narches; +char **archnames; +int *islandid2arch; + void setup_search(void) { - neighbours= mcalloc(sizeof(*neighbours) * islandtablesz); + MCALLOC(neighbours, islandtablesz); SQL_PREPARE(ss_neigh, "SELECT biid, dist FROM routes WHERE aiid=?"); + + int max_narches= + sql_single_int(" SELECT count(*) FROM (\n" + " SELECT DISTINCT archipelago\n" + " FROM islands\n" + " )"); + MCALLOC(archnames, max_narches); + MCALLOC_INITEACH(islandid2arch, islandtablesz, *this=-1); + + sqlite3_stmt *archs; + SQL_PREPARE(archs, + " SELECT islandid, archipelago\n" + " FROM islands\n" + " ORDER BY archipelago"); + while (SQL_STEP(archs)) { + int isle= sqlite3_column_int(archs,0); + const char *archname= (const char*)sqlite3_column_text(archs,1); + int arch; + for (arch=0; arch