chiark / gitweb /
WIP routesearch; route tail guesswork pruning optimisation
[ypp-sc-tools.db-live.git] / yarrg / rscommon.h
1 #ifndef RSCOMMON_H
2 #define RSCOMMON_H
3
4 #include <sqlite3.h>
5
6 #define DEBUG_FLAG_LIST                         \
7    DF(sql)                                      \
8    DF(sql2)                                     \
9    DF(value)                                    \
10    DF(search)                                   \
11    DF(check)                                    \
12    DF(lp)
13
14 #define debug stdout
15 #define DEBUG_DEV "/dev/stdout"
16
17 #include "common.h"
18
19
20 #define SQL_MUST( call ) ({                                              \
21     /* `call' is an expression returning result, using  const char *sqe; \
22      * chk1 and chk2 are blocks using sqe and  int sqr; */               \
23     const char *sql_must_call_string= #call;                             \
24     int sqr;                                                             \
25     if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string);    \
26     sqr= (call);                                                         \
27     if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr);                    \
28     if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string);          \
29   })                                                                     \
30
31 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
32
33 #define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__))
34 int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string,
35                   const char *file, int line);
36
37 int sql_single_int(const char *stmt);
38
39 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
40 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
41
42 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
43 void sql_bind(sqlite3_stmt *ss, int index, int value,
44               const char *ss_what, const char *val_what);
45
46 #define MAX_ROUTELEN 20
47
48 extern sqlite3 *db;
49
50 void setup_sql(void);
51
52
53 typedef struct {
54   double distance_loss_factor;
55   int ntrades;
56   struct TradesBlock *trades;
57   double route_tail_value;
58 } IslandPair;
59
60 IslandPair *ipair_get(int si, int di);
61
62 double value_route(int nislands, const int *islands, int exclude_arbitrage);
63 void setup_value(void);
64
65 void setup_search(void);
66 void search(int start_isle);
67
68 extern double max_mass, max_volu, max_capi;
69 extern double distance_loss_factor_per_league;
70 extern int max_dist;
71
72 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
73
74 extern int islandtablesz;
75
76
77 #endif /*RSCOMMON_H*/