chiark / gitweb /
WIP routesearch; summary stratification output table shows 100s and 10s
[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     results= mcalloc(sizeof(*results)*argc);
62     max_dist= atoi(*argv++);
63     int resultsix= 0;
64     while ((arg= *argv++)) {
65       search(atoi(arg), &results[resultsix]);
66       resultsix++;
67     }
68
69     int i, midisle, finisle;
70     for (i=0; i<resultsix; i++) {
71       fprintf(stderr,"================== start #%d ==================\n",i);
72       PotentialResult ***strat_resultsix= results[i];
73       if (!strat_resultsix) continue;
74       fprintf(stderr,"    ");
75       for (midisle=0; midisle<islandtablesz; midisle++) {
76         fprintf(stderr,"|mi%-3d",midisle);
77       }
78       fprintf(stderr,"\n");
79       for (finisle=0; finisle<islandtablesz; finisle++) {
80         PotentialResult **strat_finisle= strat_resultsix[finisle];
81         if (!strat_finisle) continue;
82         fprintf(stderr,"f%-3d",finisle);
83         for (midisle=0; midisle<islandtablesz; midisle++) {
84           PotentialResult *result= strat_finisle[midisle];
85           if (!result) {
86             fprintf(stderr,"|       ");
87           } else {
88             if (result->absolute < 100) fprintf(stderr,"|  .");
89             else fprintf(stderr,"|%3d",(int)(result->absolute / 100));
90             fprintf(stderr," ");
91             if (result->perleague < 10) fprintf(stderr,"  .");
92             else fprintf(stderr,"%3d",(int)(result->perleague / 10));
93           }
94         }
95         fprintf(stderr,"\n");
96       }
97     }
98   } else {
99     abort();
100   }
101
102 #define CTR(x) fprintf(stderr,"  %-30s %10d\n",#x,ctr_##x);
103   COUNTER_LIST
104 #undef CTR
105
106   return 0;
107 }