6 #define DEBUG_FLAG_LIST \
15 #define DEBUG_DEV "/dev/stdout"
20 #define COUNTER_LIST \
21 CTR(commodities_loaded) \
23 CTR(quantities_loaded) \
24 CTR(routes_considered) \
25 CTR(routes_eliminated) \
27 CTR(subroute_tails_valued) \
28 CTR(subroutes_valued) \
29 CTR(subroutes_nonempty)
30 #define CTR(x) extern int ctr_##x;
34 #define SQL_MUST( call ) ({ \
35 /* `call' is an expression returning result, using const char *sqe; \
36 * chk1 and chk2 are blocks using sqe and int sqr; */ \
37 const char *sql_must_call_string= #call; \
39 if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string); \
41 if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr); \
42 if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string); \
45 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
47 #define SQL_STEP(ssh) (sql_step((ssh), #ssh, __FILE__, __LINE__))
48 int sql_step(sqlite3_stmt *ssh, const char *ssh_string,
49 const char *file, int line);
51 #define SQL_DISTINCT_DECL(cols, nintcols) \
54 #define SQL_DISTINCT_STEP(ssh, cols, nkeycols) \
55 (sql_step_distinct((ssh), #ssh, __FILE__, __LINE__, \
56 (cols), sizeof((cols))/sizeof((cols)[0]), nkeycols))
57 int sql_step_distinct(sqlite3_stmt *ssh, const char *ssh_string,
58 const char *file, int line,
59 int *cols, int ncols, int nkeycols);
60 /* These work if we're making a query whose columns consist of:
61 * - keys: integer column(s) on which the results are sorted by the query
62 * - consequences: zero or more integer cols strictly dependent on the keys
63 * - extra: zero or more further (possibly non-integer) columns
65 * Call SQL_DISTINCT_DECL, passing intcols = the total number of keys and
66 * consequences; it will declare int cols[intfields];
68 * Then each SQL_DISTINCT_STEP is like SQL_STEP only you have to
69 * pass the number of key columns and it only returns rows with
70 * distinct keys. Rows with all-identical keys are asserted to
71 * have identical consequences. After each call to
72 * SQL_DISTINCT_STEP the keys and consequences will be stored in
76 int sql_single_int(const char *stmt);
78 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
79 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
81 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
82 void sql_bind(sqlite3_stmt *ss, int index, int value,
83 const char *ss_what, const char *val_what);
85 #define MAX_ROUTELEN 20
93 double distance_loss_factor;
94 struct TradesBlock *trades;
95 double route_tail_value;
98 IslandPair *ipair_get_maybe(int si, int di);
100 double value_route(int nislands, const int *islands, int exclude_arbitrage);
101 void setup_value(void);
103 void setup_search(void);
104 void search(int start_isle);
106 extern double max_mass, max_volu, max_capi;
107 extern double distance_loss_factor_per_league;
110 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
112 extern int islandtablesz;
115 #endif /*RSCOMMON_H*/