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;
extern char **archnames;
extern int *islandid2arch;
+extern int stratsz_fin[STRATS], stratsz_mid[STRATS];
+
extern FILE *output;
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) \
#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 );
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; strati<STRATS; strati++)
+ MCALLOC(results[strati], argc);
max_dist= atoi(*argv++);
+
for (ap=0; ap<AP; ap++) {
- nhighscores[ap]= atoi(*argv++);
- MCALLOC(highscores[ap], nhighscores[ap]);
+ int nhs= atoi(*argv++);
+ for (strati=0; strati<STRATS; strati++) {
+ nhighscores[strati][ap]= nhs;
+ MCALLOC(highscores[strati][ap], nhs);
+ }
}
const char *final_isle_spec= *argv++;
else final_isle= atoi(final_isle_spec);
assert(final_isle);
- search(init_isle, final_isle, &results[resultsix]);
+ PotentialResult ****strat_base_io[STRATS];
+ for (strati=0; strati<STRATS; strati++)
+ strat_base_io[strati]= &results[strati][resultsix];
+
+ search(init_isle, final_isle, strat_base_io);
resultsix++;
}
- int midarch, finarch;
- for (i=0; i<resultsix; i++) {
- tabdebugf("============== start #%d %s [PARTIAL] ==============\n",
- i, argv[i]);
- PotentialResult ***strat_resultsix= results[i];
- if (!strat_resultsix) continue;
- tabdebugf(" ");
- for (midarch=0; midarch<narches; midarch++) {
- tabdebugf("| mid %d ",midarch);
- }
- tabdebugf("\n");
- for (finarch=0; finarch<narches; finarch++) {
- PotentialResult **strat_finarch= strat_resultsix[finarch];
- if (!strat_finarch) continue;
- tabdebugf("f%d",finarch);
- for (midarch=0; midarch<narches; midarch++) {
- PotentialResult *result= strat_finarch[midarch];
- if (!result) {
- tabdebugf("| ");
- } else {
- tabdebugf("|%5d",(int)(result->value[A]));
- tabdebugf(" ");
- tabdebugf("%4d",(int)(result->value[P]));
- }
+ int mid, fin;
+ for (strati=minstrat; strati<STRATS; strati++) {
+ 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(" ");
+ for (mid=0; mid<stratsz_mid[strati]; mid++) {
+ tabdebugf("| m%-3d ",mid);
}
tabdebugf("\n");
- }
- }
-
- for (ap=0; ap<AP; ap++) {
- int pos;
- fprintf(output,"\n================== ap=%d ==================\n", ap);
- for (pos=0; pos<nhighscores[ap]; pos++) {
- HighScoreEntry *hs= &highscores[ap][pos];
- PotentialResult *pr= hs->pr;
- if (!pr) continue;
- const int *const ports= pr->ports[ap];
- int nports;
- for (nports=0; nports<MAX_ROUTELEN && ports[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; i<nports; i++) fprintf(output," %d",ports[i]);
- fprintf(output,"\n");
- }
- }
+ for (fin=0; fin<stratsz_fin[strati]; fin++) {
+ PotentialResult **strat_fin= strat_resultsix[fin];
+ if (!strat_fin) continue;
+ tabdebugf("f%-3d",fin);
+ for (mid=0; mid<stratsz_mid[strati]; mid++) {
+ PotentialResult *result= strat_fin[mid];
+ if (!result) {
+ tabdebugf("| ");
+ } else {
+ tabdebugf("|%5d",(int)(result->value[A]));
+ tabdebugf(" ");
+ tabdebugf("%4d",(int)(result->value[P]));
+ }
+ }
+ tabdebugf("\n");
+ }
+ } /* i */
+
+ 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];
+ PotentialResult *pr= hs->pr;
+ if (!pr) continue;
+ const int *const ports= pr->ports[ap];
+ int nports;
+ for (nports=0; nports<MAX_ROUTELEN && ports[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<nports; i++) fprintf(output," %d",ports[i]);
+ fprintf(output,"\n");
+ } /* pos */
+ } /* ap */
+ } /* strati */
fprintf(output,"\n");
} else {
}
-static PotentialResult ***strat_base;
+static PotentialResult ***strat_base[STRATS];
static double process_route(int nports, int totaldist,
return guess[A];
}
- if (guess[A] <= highscores[A][0].value &&
- guess[P] <= highscores[P][0].value) {
+ if (guess[A] <= highscores[minstrat][A][0].value &&
+ guess[P] <= highscores[minstrat][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 finisle= ports[nports-1];
+ int finarch= isle2arch(finisle);
+
+ int midisle= ports[nports/2];
int midarch= route2midarch(ports,nports);
- PotentialResult **strat_fin= ONDEMAND(strat_base[finarch], narches);
- PotentialResult *strat= ONDEMAND(strat_fin[midarch], 1);
+ PotentialResult *strats[STRATS];
+ int strati;
+ for (strati=minstrat; strati<STRATS; strati++) {
+ PotentialResult **strat_fin;
+ int mid, fin;
+ switch (strati) {
+ 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);
+ }
if (nports>=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];
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; ap<AP; ap++) {
- fildebugf("ap=%d %15f", ap, value[ap]);
- if (value[ap] < strat->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;
- 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; strati<STRATS; strati++) {
+ PotentialResult *strat= strats[strati];
+
+ if (value[A] <= strat->value[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; ap<AP; ap++) {
+ HighScoreEntry *scores= highscores[strati][ap];
+ int *nscores= &nhighscores[strati][ap];
+
+ fildebugf("ap=%d %15f", ap, value[ap]);
+ if (value[ap] < strat->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;
+ 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);
}
}
}
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;
}
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<STRATS; strati++)
+ strat_base[strati]= ONDEMAND(*strat_base_io[strati], stratsz_fin[strati]);
+
final_isle= final_isle_spec <= 0 ? 0 : final_isle_spec;
recurse(start_isle,0,0,1e6);
}
-int nhighscores[AP];
-HighScoreEntry *highscores[AP];
+int nhighscores[STRATS][AP];
+HighScoreEntry *highscores[STRATS][AP];
+int minstrat, stratsz_fin[STRATS], stratsz_mid[STRATS];
int narches;
char **archnames;
islandid2arch[isle]= arch;
}
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;
}
file ./routesearch
-set args -DN 13460 20210 -1 0.0005 search 10 20 20 circ 4 19 134 32 13 24 36
-break setup_search
+set args -DN OCEAN-Midnight.db 13460 20210 -1 0.0005 search 10 20 20 circ 4 19 134 32 13 24 36
run
-finish