From 2fedbd29b44d71058d0bdf0182028457b21cabce Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 5 Oct 2009 00:56:39 +0100 Subject: [PATCH] routesearch: event counters --- yarrg/rscommon.h | 14 ++++++++++++++ yarrg/rsmain.c | 11 +++++++++++ yarrg/rssearch.c | 9 ++++++++- yarrg/rsvalue.c | 8 ++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/yarrg/rscommon.h b/yarrg/rscommon.h index 965b6db..7c70ca4 100644 --- a/yarrg/rscommon.h +++ b/yarrg/rscommon.h @@ -17,6 +17,20 @@ #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; */ \ diff --git a/yarrg/rsmain.c b/yarrg/rsmain.c index ed21fe8..da05f47 100644 --- a/yarrg/rsmain.c +++ b/yarrg/rsmain.c @@ -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; } diff --git a/yarrg/rssearch.c b/yarrg/rssearch.c index d5a97a4..87914a8 100644 --- a/yarrg/rssearch.c +++ b/yarrg/rssearch.c @@ -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; iroute_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; diff --git a/yarrg/rsvalue.c b/yarrg/rsvalue.c index d2190dc..3bf98b4 100644 --- a/yarrg/rsvalue.c +++ b/yarrg/rsvalue.c @@ -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