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