chiark / gitweb /
routesearch: event counters
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 4 Oct 2009 23:56:39 +0000 (00:56 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 4 Oct 2009 23:56:39 +0000 (00:56 +0100)
yarrg/rscommon.h
yarrg/rsmain.c
yarrg/rssearch.c
yarrg/rsvalue.c

index 965b6db7205413286a3ba65a2cf7966809a915cb..7c70ca4d800a647dbc2d322f8e9fdb59cc305480 100644 (file)
 #include "common.h"
 
 
+#define COUNTER_LIST                           \
+   CTR(commodities_loaded)                     \
+   CTR(trades_loaded)                          \
+   CTR(quantities_loaded)                      \
+   CTR(routes_considered)                      \
+   CTR(routes_eliminated)                      \
+   CTR(routes_valued)                          \
+   CTR(subroute_tails_valued)                  \
+   CTR(subroutes_valued)                       \
+   CTR(subroutes_nonempty)
+#define CTR(x) extern int ctr_##x;
+  COUNTER_LIST
+#undef CTR
+
 #define SQL_MUST( call ) ({                                             \
     /* `call' is an expression returning result, using  const char *sqe; \
      * chk1 and chk2 are blocks using sqe and  int sqr; */              \
index ed21fe88e441cba93ce1c940b99a7fe5585166e5..da05f4780fb30ed0256b684aee3c7cea241f5477 100644 (file)
@@ -7,6 +7,10 @@ double max_mass=-1, max_volu=-1, max_capi=-1;
 double distance_loss_factor_per_league;
 int max_dist= -1;
 
+#define CTR(x) int ctr_##x;
+  COUNTER_LIST
+#undef CTR
+
 int main(int argc, const char **argv) {
   const char *arg;
 
@@ -39,6 +43,8 @@ int main(int argc, const char **argv) {
   setup_sql();
   setup_value();
   setup_search();
+
+  fprintf(stderr,"setup complete, starting search\n");
   
   arg= *argv++;
   if (!strcmp(arg,"specific")) {
@@ -55,5 +61,10 @@ int main(int argc, const char **argv) {
   } else {
     abort();
   }
+
+#define CTR(x) fprintf(stderr,"  %-30s %10d\n",#x,ctr_##x);
+  COUNTER_LIST
+#undef CTR
+
   return 0;
 }
index d5a97a488604fb74db3f5c6ceaa7c686ef2613ed..87914a8cd89232748821b717791ade6810e6196e 100644 (file)
@@ -41,6 +41,8 @@ static double process_route(int nports, int totaldist,
   int i;
   int leagues_divisor= totaldist + nports;
 
+  ctr_routes_considered++;
+
   debugf("========== ROUTE");
   for (i=0; i<nports; i++)
     debugf(" %d",ports[i]);
@@ -55,19 +57,24 @@ static double process_route(int nports, int totaldist,
       pair[0]= ports[i];
       IslandPair *ip= ipair_get_maybe(pair[0], pair[1]);
       if (!ip) continue;
-      if (ip->route_tail_value < 0)
+      if (ip->route_tail_value < 0) {
+       ctr_subroute_tails_valued++;
        ip->route_tail_value= value_route(2, pair, pair[0]!=pair[1]);
+      }
       guess_absolute += ip->route_tail_value;
     }
     double guess_perleague= guess_absolute / leagues_divisor;
 
     if (guess_absolute <= best_absolute && guess_perleague <= best_perleague) {
+      ctr_routes_eliminated++;
       debugf(" ELIM %f %f\n", guess_absolute, guess_perleague);
       return guess_absolute;
     }
     debugf(" COMPUTE %f %f\n", guess_absolute, guess_perleague);
   }
 
+  ctr_routes_valued++;
+
   double absolute= value_route(nports, ports, 0);
   double perleague= absolute / leagues_divisor;
 
index d2190dc289a9a3cc4879333da794b4c9c5f1b691..3bf98b47b397f8bca433d55045b193305de099c2 100644 (file)
@@ -13,6 +13,7 @@ static CommodInfo *commodstab;
 static sqlite3_stmt *ss_ipair_dist;
 static sqlite3_stmt *ss_ite_buy, *ss_ite_sell;
 
+
 #define MAX_LEGS (MAX_ROUTELEN-1)
 
 typedef struct {
@@ -158,6 +159,8 @@ static IslandPair *ipair_get_create(int si, int di) {
 double value_route(int nislands, const int *islands, int exclude_arbitrage) {
   int s,d;
 
+  ctr_subroutes_valued++;
+
   /* We need to construct the LP problem.  GLPK talks
    * about rows and columns, which are numbered from 1.
    *
@@ -288,6 +291,8 @@ double value_route(int nislands, const int *islands, int exclude_arbitrage) {
   double profit= 0;
 
   if (lpx_get_num_cols(lp)) {
+    ctr_subroutes_nonempty++;
+    
     if (DEBUGP(lp))
       lpx_write_cpxlp(lp, (char*)DEBUG_DEV);
 
@@ -327,6 +332,7 @@ static void read_trades(void) {
 
   SQL_DISTINCT_DECL(cols,5);
   while (SQL_DISTINCT_STEP(ss_trades,cols,5)) {    
+    ctr_trades_loaded++;
     IslandPair *ip= ipair_get_create(cols[1], cols[3]);
     TradesBlock *block= ip->trades;
     if (!block || ip->trades->ntrades >= TRADES_PER_BLOCK) {
@@ -357,6 +363,7 @@ static void read_islandtradeends(const char *bs, int srcdstoff) {
 
   SQL_DISTINCT_DECL(cols,5);
   while (SQL_DISTINCT_STEP(ss,cols,3)) {
+    ctr_quantities_loaded++;
     IslandTradeEnd *search;
 
     int commodid= cols[0];
@@ -397,6 +404,7 @@ void setup_value(void) {
   SQL_PREPARE(sst,
              "SELECT commodid,unitmass,unitvolume FROM commods");
   while (SQL_STEP(sst)) {
+    ctr_commodities_loaded++;
     int id= sqlite3_column_int(sst,0);
     assert(id>=0 && id<commodstabsz);
     commodstab[id].mass= sqlite3_column_int(sst,1);