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=67d338b502d961dc3279874cacb1344ab173e4ba;hp=524cbece8159c6b19dd0be8e6d18e4abfb8d17b0;hb=2aa3a575e41e6c9ed3b58e822dde0cf73502012b;hpb=d66f27768708df0b8ce256e2d868ff4f7060ef3f diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index 524cbec..67d338b 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -1,4 +1,29 @@ -/**/ +/* + * Route searcher - command line parsing and result printing + */ +/* + * This is part of the YARRG website, a tool for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ #include "rscommon.h" @@ -7,12 +32,12 @@ 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; -DEBUG_DEFINE_SOME_DEBUGF(tableau,tabdebugf); +#define tabdebugf printf #define CTR(x) int ctr_##x; @@ -21,14 +46,18 @@ DEBUG_DEFINE_SOME_DEBUGF(tableau,tabdebugf); #undef CTR #undef CTRA -static PotentialResult ****results; - /* results[start_isle_ix][finalisle][midisle]-> */ +static Bucket ****results[GRANUS]; + /* results[GRANUS][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 ); @@ -37,12 +66,22 @@ int main(int argc, const char **argv) { 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(); } } @@ -80,11 +119,33 @@ int main(int argc, const char **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(); @@ -101,12 +162,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 (granui=0; granuivalue[A])); - tabdebugf(" "); - tabdebugf("%4d",(int)(result->value[P])); - } + int mid, fin; + for (granui=0; granuipr; - 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; iprs[A].value[A])); + tabdebugf(" "); + tabdebugf("%4d",(int)(result->prs[P].value[P])); + } + } + tabdebugf("\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