6 #define DEBUG_FLAG_LIST \
16 #define DEBUG_DEV "/dev/stdout"
21 #define COUNTER_LIST \
22 CTR(commodities_loaded) \
24 CTR(quantities_loaded) \
25 CTR(routes_considered) \
26 CTR(routes_eliminated) \
28 CTR(subroute_tails_valued) \
29 CTR(subroutes_valued) \
30 CTR(subroutes_nonempty)
31 #define CTR(x) extern int ctr_##x;
35 #define SQL_MUST( call ) ({ \
36 /* `call' is an expression returning result, using const char *sqe; \
37 * chk1 and chk2 are blocks using sqe and int sqr; */ \
38 const char *sql_must_call_string= #call; \
40 if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string); \
42 if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr); \
43 if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string); \
46 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
48 #define SQL_STEP(ssh) (sql_step((ssh), #ssh, __FILE__, __LINE__))
49 int sql_step(sqlite3_stmt *ssh, const char *ssh_string,
50 const char *file, int line);
52 #define SQL_DISTINCT_DECL(cols, nintcols) \
55 #define SQL_DISTINCT_STEP(ssh, cols, nkeycols) \
56 (sql_step_distinct((ssh), #ssh, __FILE__, __LINE__, \
57 (cols), sizeof((cols))/sizeof((cols)[0]), nkeycols))
58 int sql_step_distinct(sqlite3_stmt *ssh, const char *ssh_string,
59 const char *file, int line,
60 int *cols, int ncols, int nkeycols);
61 /* These work if we're making a query whose columns consist of:
62 * - keys: integer column(s) on which the results are sorted by the query
63 * - consequences: zero or more integer cols strictly dependent on the keys
64 * - extra: zero or more further (possibly non-integer) columns
66 * Call SQL_DISTINCT_DECL, passing intcols = the total number of keys and
67 * consequences; it will declare int cols[intfields];
69 * Then each SQL_DISTINCT_STEP is like SQL_STEP only you have to
70 * pass the number of key columns and it only returns rows with
71 * distinct keys. Rows with all-identical keys are asserted to
72 * have identical consequences. After each call to
73 * SQL_DISTINCT_STEP the keys and consequences will be stored in
77 int sql_single_int(const char *stmt);
79 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
80 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
82 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
83 void sql_bind(sqlite3_stmt *ss, int index, int value,
84 const char *ss_what, const char *val_what);
86 #define MAX_ROUTELEN 20
94 double distance_loss_factor;
95 struct TradesBlock *trades;
96 double route_tail_value;
99 IslandPair *ipair_get_maybe(int si, int di);
101 double value_route(int nislands, const int *islands, int exclude_arbitrage);
102 void setup_value(void);
105 double absolute, perleague;
106 int absolute_ports[MAX_ROUTELEN], perleague_ports[MAX_ROUTELEN];
109 void setup_search(void);
110 void search(int start_isle, PotentialResult ****strat_base_io
111 /* strat_base[finalisle][midisle]-> */);
113 extern double max_mass, max_volu, max_capi;
114 extern double distance_loss_factor_per_league;
117 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
119 extern int islandtablesz;
122 extern char **archnames;
123 extern int *islandid2arch;
126 #define ONDEMAND(pointer_lvalue, calloc_size_count) \
127 ((pointer_lvalue) ? : \
128 ((pointer_lvalue) = mcalloc(sizeof(*(pointer_lvalue)) * calloc_size_count)))
131 #endif /*RSCOMMON_H*/