6 #define DEBUG_FLAG_LIST \
16 #define debug debug_file
20 extern FILE *debug_file;
21 #define DEBUG_DEV "/dev/stdout" /* just for glpk */
24 #define COUNTER_LIST \
25 CTR(commodities_loaded) \
27 CTR(islands_arbitrage) \
28 CTR(ipairs_relevant) \
29 CTR(quantities_loaded) \
30 CTR(routes_considered) \
31 CTR(routes_wrongfinalelim) \
32 CTR(routes_quickelim) \
33 CTR(routes_stratelim) \
35 CTR(routes_wrongfinal) \
36 CTR(newbests_strat_absolute) \
37 CTR(newbests_strat_perleague) \
38 CTR(subroute_tails_valued) \
39 CTR(subroutes_valued) \
40 CTR(subroutes_nonempty)
41 #define CTR(x) extern int ctr_##x;
45 #define SQL_MUST( call ) ({ \
46 /* `call' is an expression returning result, using const char *sqe; \
47 * chk1 and chk2 are blocks using sqe and int sqr; */ \
48 const char *sql_must_call_string= #call; \
50 if (DEBUGP(sql2)) fprintf(debug,"SQL %s", sql_must_call_string); \
52 if (DEBUGP(sql2)) fprintf(debug," = %d\n", sqr); \
53 if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string); \
56 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
58 #define SQL_STEP(ssh) (sql_step((ssh), #ssh, __FILE__, __LINE__))
59 int sql_step(sqlite3_stmt *ssh, const char *ssh_string,
60 const char *file, int line);
62 #define SQL_DISTINCT_DECL(cols, nintcols) \
65 #define SQL_DISTINCT_STEP(ssh, cols, nkeycols) \
66 (sql_step_distinct((ssh), #ssh, __FILE__, __LINE__, \
67 (cols), sizeof((cols))/sizeof((cols)[0]), nkeycols))
68 int sql_step_distinct(sqlite3_stmt *ssh, const char *ssh_string,
69 const char *file, int line,
70 int *cols, int ncols, int nkeycols);
71 /* These work if we're making a query whose columns consist of:
72 * - keys: integer column(s) on which the results are sorted by the query
73 * - consequences: zero or more integer cols strictly dependent on the keys
74 * - extra: zero or more further (possibly non-integer) columns
76 * Call SQL_DISTINCT_DECL, passing intcols = the total number of keys and
77 * consequences; it will declare int cols[intfields];
79 * Then each SQL_DISTINCT_STEP is like SQL_STEP only you have to
80 * pass the number of key columns and it only returns rows with
81 * distinct keys. Rows with all-identical keys are asserted to
82 * have identical consequences. After each call to
83 * SQL_DISTINCT_STEP the keys and consequences will be stored in
87 int sql_single_int(const char *stmt);
89 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
90 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
92 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
93 void sql_bind(sqlite3_stmt *ss, int index, int value,
94 const char *ss_what, const char *val_what);
96 #define MAX_ROUTELEN 20
100 void setup_sql(void);
104 double distance_loss_factor;
105 struct TradesBlock *trades;
106 double route_tail_value;
109 IslandPair *ipair_get_maybe(int si, int di);
111 double value_route(int nislands, const int *islands, int exclude_arbitrage);
112 void setup_value(void);
115 double absolute, perleague;
116 int absolute_ports[MAX_ROUTELEN], perleague_ports[MAX_ROUTELEN];
119 void setup_search(void);
120 void search(int start_isle, int final_isle /* -1 means any */,
121 PotentialResult ****strat_base_io
122 /* strat_base[finalarch][midarch]-> */);
124 extern double max_mass, max_volu, max_capi;
125 extern double distance_loss_factor_per_league;
128 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
130 extern int islandtablesz;
133 extern char **archnames;
134 extern int *islandid2arch;
140 #define NEW(ptr) ((ptr)= mmalloc(sizeof(*ptr)))
142 #define MCALLOC(array, count) ((array)= mcalloc(sizeof(*(array)) * (count)))
144 #define MCALLOC_INITEACH(array, count, init_this) ({ \
145 MCALLOC((array), (count)); \
147 typeof(&(array)[0]) this; \
148 for (initi=0, this=(array); initi<(count); initi++, this++) { \
159 extern int nhighscores_absolute, nhighscores_perleague;
160 extern HighScoreEntry *highscores_absolute;
161 extern HighScoreEntry *highscores_perleague;
164 #define ONDEMAND(pointer_lvalue, calloc_size_count) \
165 ((pointer_lvalue) ? : \
166 ((pointer_lvalue) = mcalloc(sizeof(*(pointer_lvalue)) * calloc_size_count)))
169 static inline int isle2arch(int isle) {
170 int arch= islandid2arch[isle];
175 static inline int route2midarch(const int *ports, int nports) {
176 int archs[nports], last_arch=-1, narchs=0, i;
177 for (i=0; i<nports; i++) {
178 int arch= isle2arch(ports[i]);
179 if (arch==last_arch) continue;
180 archs[narchs++]= last_arch= arch;
182 return archs[narchs/2];
186 #endif /*RSCOMMON_H*/