X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Frsmain.c;h=774f507e309857db3c603463ed276920a1c8bdb4;hp=0e43d5d471e73114d9e90014d3dfc8eca3db3dca;hb=d892748541adab0a53bbd641a1440f4c65c9cb63;hpb=cf1aa28767bcecb39ff18b2ee80952ed38f40e0d diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index 0e43d5d..774f507 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -2,53 +2,132 @@ #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; +int max_dist=-1, min_trade_maxprofit=0; + +FILE *debug_file; +FILE *output; + +#define tabdebugf printf -#define CTR(x) int ctr_##x; + +#define CTR(x) int ctr_##x; +#define CTRA(x,n) int ctr_##x[n]; COUNTER_LIST #undef CTR +#undef CTRA + +static Bucket ****results[GRANUS]; + /* results[GRANUS][start_isle_ix][finalisle][midisle]-> */ -static PotentialResult ****results; - /* results[start_isle_ix][finalisle][midisle]-> */ +static pid_t debugoutpid; int main(int argc, const char **argv) { const char *arg; + int i, ap; + int granui; + const char *database=0; + const char *concur_base=0, *concur_rhs=0; + int concur_lim=-1; #ifndef debug_flags debug_flags= ~( dbg_sql2 ); #endif - sysassert( !setvbuf(debug,0,_IOLBF,0) ); - + for (;;) { arg= *++argv; if (arg[0] != '-') break; + if (!strcmp(arg,"-d")) { + database= *++argv; + } else if (!strcmp(arg,"-C")) { + concur_base= *++argv; + concur_rhs= *++argv; + concur_lim= atoi(*++argv); + } else if (!strcmp(arg,"-g")) { + granus= atoi(*++argv); + assert(granus>=1 && granus<=GRANUS); #ifndef debug_flags - if (!strcmp(arg,"-DN")) { + } else if (!strcmp(arg,"-DN")) { debug_flags= 0; - } else + } else if (!strcmp(arg,"-D1")) { + debug_flags= ~(dbg_sql2|dbg_lp|dbg_value2); #endif - { + } else { 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; + } + + sysassert( !setvbuf(debug,0,_IOLBF,0) ); + max_mass= atof(*argv++); max_volu= atof(*argv++); max_capi= atof(*argv++); double loss_per_league= atof(*argv++); - - if (!loss_per_league) loss_per_league= 1e-7; distance_loss_factor_per_league= 1.0 - loss_per_league; - setup_sql(); + min_trade_maxprofit= atoi(*argv++); + + if (concur_base) { + for (i=0; i= 0); + struct flock fl; + memset(&fl,0,sizeof(fl)); + fl.l_type= F_WRLCK; + r= fcntl(concfd, F_SETLK, &fl); + free(concfn); + if (!r) goto concur_ok; + sysassert( errno == EWOULDBLOCK ); + close(concfd); + } + fprintf(output,"@@@ concurrency limit exceeded (%d)\n", concur_lim); + exit(0); + + concur_ok: + /* deliberately leak concfd */ + fprintf(output,"concurrency slot %d\n", i); + } + + setup_sql(database); setup_value(); setup_search(); - fprintf(stderr,"setup complete, starting search\n"); - + for (i=0; iabsolute < 1000) fprintf(stderr,"| <"); - else fprintf(stderr,"|%2d",(int)(result->absolute / 1000)); - fprintf(stderr," "); - if (result->perleague < 100) fprintf(stderr," <"); - else fprintf(stderr,"%2d",(int)(result->perleague / 100)); + int mid, fin; + for (granui=0; granuiprs[A].value[A])); + tabdebugf(" "); + tabdebugf("%4d",(int)(result->prs[P].value[P])); + } } + tabdebugf("\n"); } - fprintf(stderr,"\n"); - } - } + } /* i */ + + for (ap=0; ap=0; pos--) { + HighScoreEntry *hs= &highscores[granui][ap][pos]; + Bucket *bucket= hs->bucket; + if (!bucket) continue; + OnePotentialResult *pr= &bucket->prs[ap]; + const int *const ports= pr->ports; + 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 %c#%2d | start%3d mid%d:%3d f%d:%3d" + " | %3dlg | %5d %5d %4d |", + pos, "ap"[ap], nhighscores[granui][ap] - pos, + ports[0], midarch,midisle, finarch,finisle, pr->length, + (int)hs->value, (int)pr->value[A], (int)pr->value[P]); + for (i=0; i