chiark / gitweb /
WIP routesearch; route tail guesswork pruning optimisation
[ypp-sc-tools.db-live.git] / yarrg / rscommon.h
index 6fd394ea008d7eb0829189426633106b6572a5b0..f62fd99d9ed15cdf4d9cd873a6406c3d7a60d38b 100644 (file)
@@ -4,13 +4,74 @@
 #include <sqlite3.h>
 
 #define DEBUG_FLAG_LIST                                \
-   DF(sql)
+   DF(sql)                                     \
+   DF(sql2)                                    \
+   DF(value)                                   \
+   DF(search)                                  \
+   DF(check)                                   \
+   DF(lp)
 
+#define debug stdout
+#define DEBUG_DEV "/dev/stdout"
 
 #include "common.h"
 
-extern struct sqlite *db;
 
-void value_route(int nislands, const int *islands);
+#define SQL_MUST( call ) ({                                             \
+    /* `call' is an expression returning result, using  const char *sqe; \
+     * chk1 and chk2 are blocks using sqe and  int sqr; */              \
+    const char *sql_must_call_string= #call;                            \
+    int sqr;                                                            \
+    if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string);   \
+    sqr= (call);                                                        \
+    if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr);                   \
+    if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string);                 \
+  })                                                                    \
+
+void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
+
+#define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__))
+int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string,
+                 const char *file, int line);
+
+int sql_single_int(const char *stmt);
+
+#define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
+sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
+
+#define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
+void sql_bind(sqlite3_stmt *ss, int index, int value,
+             const char *ss_what, const char *val_what);
+
+#define MAX_ROUTELEN 20
+
+extern sqlite3 *db;
+
+void setup_sql(void);
+
+
+typedef struct {
+  double distance_loss_factor;
+  int ntrades;
+  struct TradesBlock *trades;
+  double route_tail_value;
+} IslandPair;
+
+IslandPair *ipair_get(int si, int di);
+
+double value_route(int nislands, const int *islands, int exclude_arbitrage);
+void setup_value(void);
+
+void setup_search(void);
+void search(int start_isle);
+
+extern double max_mass, max_volu, max_capi;
+extern double distance_loss_factor_per_league;
+extern int max_dist;
+
+#define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
+
+extern int islandtablesz;
+
 
 #endif /*RSCOMMON_H*/