X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Frsmain.c;h=04d08ffbf48e9ecc6a2ce4fa34e57c00c6475e33;hb=d14a97ff4e453ad1540a02b465bb7e398303edde;hp=00e918e8aedbfe320bdd7628d35f35c694b66086;hpb=3ca67ce14212ba4421029d7b8db90f03f106c67c;p=ypp-sc-tools.db-live.git diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index 00e918e..04d08ff 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -2,12 +2,211 @@ #include "rscommon.h" +#include + +int o_quiet= 0; +double max_mass=-1, max_volu=-1, max_capi=-1; +double distance_loss_factor_per_league; +int max_dist= -1; + +FILE *debug_file; +FILE *output; + +#define tabdebugf printf + + +#define CTR(x) int ctr_##x; +#define CTRA(x,n) int ctr_##x[n]; + COUNTER_LIST +#undef CTR +#undef CTRA + +static PotentialResult ****results[GRANUS]; + /* results[GRANUS][start_isle_ix][finalisle][midisle]-> */ + +static pid_t debugoutpid; + int main(int argc, const char **argv) { - int ia[argc], ni=0; const char *arg; - while ((arg= *++argv)) { - ia[ni++]= atoi(arg); + int i, ap; + int granui; + +#ifndef debug_flags + debug_flags= ~( dbg_sql2 ); +#endif + + for (;;) { + arg= *++argv; + if (arg[0] != '-') break; +#ifndef debug_flags + if (!strcmp(arg,"-DN")) { + debug_flags= 0; + } else +#endif + { + abort(); + } + } + + if (debug_flags) { + /* glpk insists on writing stuff to stdout, and it does buffering, + * so we route all our debug through it this too */ + int realstdout; + sysassert( (realstdout= dup(1)) > 2 ); + sysassert( output= fdopen(realstdout,"w") ); + + int pfd[2]; + sysassert(! pipe(pfd) ); + sysassert( (debugoutpid= fork()) >=0 ); + if (!debugoutpid) { + sysassert( dup2(pfd[0],0)==0 ); + sysassert( dup2(2,1)==1 ); + sysassert(! close(pfd[0]) ); + sysassert(! close(pfd[1]) ); + sysassert(! execlp("cat","cat",(char*)0) ); + } + sysassert( dup2(pfd[1],1)==1 ); + sysassert(! close(pfd[0]) ); + sysassert(! close(pfd[1]) ); + + debug_file= stdout; + } else { + output= stdout; + debug_file= stderr; + } + + const char *database= *argv++; + + sysassert( !setvbuf(debug,0,_IOLBF,0) ); + + max_mass= atof(*argv++); + max_volu= atof(*argv++); + max_capi= atof(*argv++); + double loss_per_league= atof(*argv++); + distance_loss_factor_per_league= 1.0 - loss_per_league; + + setup_sql(database); + setup_value(); + setup_search(); + + 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[granui][ap] - 1 - pos, + ports[0], midarch,midisle, finarch,finisle, + (int)hs->value, (int)pr->value[A], (int)pr->value[P]); + for (i=0; i