From 6ab7c759c0aab39bfaf8275041dd39f45062399c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 14 Oct 2009 18:27:32 +0100 Subject: [PATCH] routesearch: three different bucket sizes for better result sets --- yarrg/rscommon.h | 13 +++-- yarrg/rsmain.c | 124 +++++++++++++++++++++++++-------------------- yarrg/rssearch.c | 128 +++++++++++++++++++++++++++++------------------ yarrg/x.gdb | 4 +- 4 files changed, 159 insertions(+), 110 deletions(-) diff --git a/yarrg/rscommon.h b/yarrg/rscommon.h index 38dc629..9e1032a 100644 --- a/yarrg/rscommon.h +++ b/yarrg/rscommon.h @@ -121,10 +121,12 @@ typedef struct { int ports[AP][MAX_ROUTELEN]; } PotentialResult; +#define STRATS 3 + void setup_search(void); void search(int start_isle, int final_isle /* -1 means any */, - PotentialResult ****strat_base_io - /* strat_base[finalarch][midarch]-> */); + PotentialResult ****strat_base_io[STRATS] + /* strat_base[strati][finalthing][midthing]-> */); extern double max_mass, max_volu, max_capi; extern double distance_loss_factor_per_league; @@ -138,6 +140,8 @@ extern int narches; extern char **archnames; extern int *islandid2arch; +extern int stratsz_fin[STRATS], stratsz_mid[STRATS]; + extern FILE *output; @@ -161,8 +165,9 @@ typedef struct { PotentialResult *pr; } HighScoreEntry; -extern int nhighscores[AP]; -extern HighScoreEntry *highscores[AP]; +extern int minstrat; +extern int nhighscores[STRATS][AP]; +extern HighScoreEntry *highscores[STRATS][AP]; #define ONDEMAND(pointer_lvalue, calloc_size_count) \ diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index a186861..50b7348 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -21,14 +21,15 @@ FILE *output; #undef CTR #undef CTRA -static PotentialResult ****results; - /* results[start_isle_ix][finalisle][midisle]-> */ +static PotentialResult ****results[STRATS]; + /* results[STRATS][start_isle_ix][finalisle][midisle]-> */ static pid_t debugoutpid; int main(int argc, const char **argv) { const char *arg; int i, ap; + int strati; #ifndef debug_flags debug_flags= ~( dbg_sql2 ); @@ -101,12 +102,17 @@ 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")) { - MCALLOC(results, argc); + for (strati=0; strativalue[A])); - tabdebugf(" "); - tabdebugf("%4d",(int)(result->value[P])); - } + int mid, fin; + for (strati=minstrat; stratipr; - if (!pr) continue; - const int *const ports= pr->ports[ap]; - int nports; - for (nports=0; nports=0; nports++); - int finisle= ports[nports-1]; int finarch= isle2arch(finisle); - int midarch= route2midarch(ports,nports); - fprintf(output, - " @%2d #%2d | start%3d mid%d f%d:%3d | %5d %5d %4d |", \ - pos, nhighscores[ap] - 1 - pos, - ports[0], midarch, finarch,finisle, \ - (int)hs->value, (int)pr->value[A], (int)pr->value[P]); - for (i=0; ivalue[A])); + tabdebugf(" "); + tabdebugf("%4d",(int)(result->value[P])); + } + } + tabdebugf("\n"); + } + } /* i */ + + for (ap=0; appr; + if (!pr) continue; + const int *const ports= pr->ports[ap]; + int nports; + for (nports=0; nports=0; nports++); + int finisle= ports[nports-1]; + int finarch= isle2arch(finisle); + int midisle= ports[nports/2]; + 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, + ports[0], midarch,midisle, finarch,finisle, + (int)hs->value, (int)pr->value[A], (int)pr->value[P]); + for (i=0; i=2) { - if (guess[A] <= strat->value[A] && - guess[P] <= strat->value[P]) { + if (guess[A] <= strats[minstrat]->value[A] && + guess[P] <= strats[minstrat]->value[P]) { ctr_routes_stratelim++; debugf(" ELIM %f %f\n", guess[A], guess[P]); return guess[A]; @@ -114,43 +129,50 @@ static double process_route(int nports, int totaldist, return value[0]; } - if (value[A] <= strat->value[A] && - value[P] <= strat->value[P]) - return value[A]; - - debugf(" SOMEHOW BEST\n"); - - fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch); - - for (ap=0; apvalue[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; - fildebugf("** "); - for (pos=0; pos < nhighscores[ap]; pos++) - if (highscores[ap][pos].pr == strat) goto found; - /* not found */ - pos= -1; - found: - for (;;) { - pos++; - if (pos >= nhighscores[ap]-1) break; /* new top */ - if (highscores[ap][pos].value >= value[ap]) break; /* found spot */ - if (pos>0) - highscores[ap][pos-1]= highscores[ap][pos]; + for (strati=minstrat; strativalue[A] && + value[P] <= strat->value[P]) + continue; + + debugf(" SOMEHOW %d BEST\n",strati); + + fildebugf("final %d:%3d mid %d ",finarch,finisle,midarch); + + for (ap=0; apvalue[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; + fildebugf("** "); + for (pos=0; pos < *nscores; pos++) + if (scores[pos].pr == strat) 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= strat; + } + fildebugf("@%2d", pos); } - pos--; - if (pos>0) { - highscores[ap][pos].value= value[ap]; - highscores[ap][pos].pr= strat; - } - fildebugf("@%2d", pos); } } @@ -164,7 +186,7 @@ static double process_route(int nports, int totaldist, } static void recurse(int last_isle, - int nports, /* excluding last_isle */ + int nports /* excluding last_isle */, int totaldist /* including last_isle */, double last_estimate) { ports[nports++]= last_isle; @@ -181,14 +203,18 @@ static void recurse(int last_isle, } void search(int start_isle, int final_isle_spec, - PotentialResult ****strat_base_io) { - strat_base= ONDEMAND(*strat_base_io, narches); + PotentialResult ****strat_base_io[STRATS]) { + int strati; + for (strati=0; strati