chiark / gitweb /
WIP routesearch; better debugging output
[ypp-sc-tools.main.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(lp)
12
13 #define debug stdout
14 #define DEBUG_DEV "/dev/stdout"
15
16 #include "common.h"
17
18
19 #define SQL_MUST( call ) ({                                              \
20     /* `call' is an expression returning result, using  const char *sqe; \
21      * chk1 and chk2 are blocks using sqe and  int sqr; */               \
22     const char *sql_must_call_string= #call;                             \
23     int sqr;                                                             \
24     if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string);    \
25     sqr= (call);                                                         \
26     if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr);                    \
27     if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string);          \
28   })                                                                     \
29
30 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
31
32 #define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__))
33 int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string,
34                   const char *file, int line);
35
36 int sql_single_int(const char *stmt);
37
38 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
39 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
40
41 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
42 void sql_bind(sqlite3_stmt *ss, int index, int value,
43               const char *ss_what, const char *val_what);
44
45 #define MAX_ROUTELEN 20
46
47 extern sqlite3 *db;
48
49 void setup_sql(void);
50 double value_route(int nislands, const int *islands);
51 void setup_value(void);
52 void setup_search(void);
53 void search(int start_isle);
54
55 extern double max_mass, max_volu, max_capi;
56 extern double distance_loss_factor_per_league;
57 extern int max_dist;
58
59 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
60
61 extern int islandtablesz;
62
63
64 #endif /*RSCOMMON_H*/