chiark / gitweb /
routesearch: middle arch is middle in list of arches, not arch of middle isle
[ypp-sc-tools.db-live.git] / yarrg / rsmain.c
1 /**/
2
3 #include "rscommon.h"
4
5 int o_quiet= 0;
6 double max_mass=-1, max_volu=-1, max_capi=-1;
7 double distance_loss_factor_per_league;
8 int max_dist= -1;
9
10 #define CTR(x) int ctr_##x;
11   COUNTER_LIST
12 #undef CTR
13
14 static PotentialResult ****results;
15   /* results[start_isle_ix][finalisle][midisle]-> */
16
17 int main(int argc, const char **argv) {
18   const char *arg;
19
20 #ifndef debug_flags
21   debug_flags= ~( dbg_sql2 );
22 #endif
23   sysassert( !setvbuf(debug,0,_IOLBF,0) );
24   
25   for (;;) {
26     arg= *++argv;
27     if (arg[0] != '-') break;
28 #ifndef debug_flags
29     if (!strcmp(arg,"-DN")) {
30       debug_flags= 0;
31     } else
32 #endif
33     {
34       abort();
35     }
36   }
37
38   max_mass= atof(*argv++);
39   max_volu= atof(*argv++);
40   max_capi= atof(*argv++);
41   double loss_per_league= atof(*argv++);
42
43   if (!loss_per_league) loss_per_league= 1e-7;
44   distance_loss_factor_per_league= 1.0 - loss_per_league;
45
46   setup_sql();
47   setup_value();
48   setup_search();
49
50   fprintf(stderr,"setup complete, starting search\n");
51   
52   arg= *argv++;
53   if (!strcmp(arg,"specific")) {
54     int ia[argc], ni=0;
55     while ((arg= *argv++))
56       ia[ni++]= atoi(arg);
57
58     double val= value_route(ni, ia, 0);
59     printf("route value is %g\n", val);
60   } else if (!strcmp(arg,"search")) {
61     MCALLOC(results, argc);
62
63     max_dist= atoi(*argv++);
64     nhighscores_absolute= atoi(*argv++);
65     nhighscores_perleague= atoi(*argv++);
66
67     MCALLOC(highscores_absolute, nhighscores_absolute);
68     MCALLOC(highscores_perleague, nhighscores_perleague);
69
70     int resultsix= 0;
71     while ((arg= argv[resultsix])) {
72       search(atoi(arg), &results[resultsix]);
73       resultsix++;
74     }
75
76     int i, midarch, finarch;
77     for (i=0; i<resultsix; i++) {
78       fprintf(stderr,"============== start #%d %s ==============\n",
79               i, argv[i]);
80       PotentialResult ***strat_resultsix= results[i];
81       if (!strat_resultsix) continue;
82       fprintf(stderr,"  ");
83       for (midarch=0; midarch<narches; midarch++) {
84         fprintf(stderr,"|   mid %d  ",midarch);
85       }
86       fprintf(stderr,"\n");
87       for (finarch=0; finarch<narches; finarch++) {
88         PotentialResult **strat_finarch= strat_resultsix[finarch];
89         if (!strat_finarch) continue;
90         fprintf(stderr,"f%d",finarch);
91         for (midarch=0; midarch<narches; midarch++) {
92           PotentialResult *result= strat_finarch[midarch];
93           if (!result) {
94             fprintf(stderr,"|          ");
95           } else {
96             fprintf(stderr,"|%5d",(int)(result->absolute));
97             fprintf(stderr," ");
98             fprintf(stderr,"%4d",(int)(result->perleague));
99           }
100         }
101         fprintf(stderr,"\n");
102       }
103     }
104
105     int pos;
106 #define OUT(absperl)                                                          \
107     fprintf(stderr,"\n================== " #absperl " ==================\n"); \
108     for (pos=0; pos<nhighscores_##absperl; pos++) {                           \
109       HighScoreEntry *hs= &highscores_##absperl[pos];                         \
110       PotentialResult *pr= hs->pr;                                            \
111       if (!pr) continue;                                                      \
112       const int *const ports= pr->absperl##_ports;                            \
113       int nports;                                                             \
114       for (nports=0; nports<MAX_ROUTELEN && ports[nports]>=0; nports++);      \
115       int finisle= ports[nports-1]; int finarch= isle2arch(finisle);          \
116       int midarch= route2midarch(ports,nports);                               \
117       fprintf(stderr,                                                         \
118               " @%2d #%2d | start%3d mid%d f%d:%3d | %5d %5d %4d |",     \
119               pos, nhighscores_##absperl - 1 - pos,                           \
120               ports[0], midarch, finarch,finisle,                     \
121               (int)hs->value, (int)pr->absolute, (int)pr->perleague);         \
122       for (i=0; i<nports; i++) fprintf(stderr," %d",ports[i]);                \
123       fprintf(stderr,"\n");                                                   \
124     }
125     OUT(absolute)
126     OUT(perleague)
127     
128   } else {
129     abort();
130   }
131
132 #define CTR(x) fprintf(stderr,"  %-30s %10d\n",#x,ctr_##x);
133   COUNTER_LIST
134 #undef CTR
135
136   return 0;
137 }