X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Frsvalue.c;h=22b3d2988f89c857196509f83b14678df629073d;hb=b0df3bd887cce71fdbd60332b89db0a076b1ee4e;hp=d2190dc289a9a3cc4879333da794b4c9c5f1b691;hpb=8fecbed75b67d8e1ebbb84ac2ad7a2173e5e5c7c;p=ypp-sc-tools.db-test.git diff --git a/yarrg/rsvalue.c b/yarrg/rsvalue.c index d2190dc..22b3d29 100644 --- a/yarrg/rsvalue.c +++ b/yarrg/rsvalue.c @@ -5,6 +5,7 @@ #include "rscommon.h" DEBUG_DEFINE_DEBUGF(value); +DEBUG_DEFINE_SOME_DEBUGF(value2,debug2f); typedef struct { int mass, volu; } CommodInfo; static int commodstabsz; @@ -13,6 +14,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 { @@ -135,16 +137,19 @@ static IslandPair *ipair_get_create(int si, int di) { assert(di < islandtablesz); if (!(ipa= ipairs[si])) { - ipa= ipairs[si]= mcalloc(sizeof(*ipa) * islandtablesz); + ipairs[si]= MCALLOC(ipa, islandtablesz); } if ((ip= ipa[di])) return ip; - ipa[di]= ip= mmalloc(sizeof(*ip)); + ipa[di]= NEW(ip); ip->trades= 0; ip->route_tail_value= -1; - debugf("VALUE ipair_get(i%d,i%d) running...\n", si,di); + if (si==di) ctr_islands_arbitrage++; + else ctr_ipairs_relevant++; + + debug2f("VALUE ipair_get(i%d,i%d) running...\n", si,di); SQL_MUST( sqlite3_bind_int(ss_ipair_dist, 1, si) ); SQL_MUST( sqlite3_bind_int(ss_ipair_dist, 2, di) ); assert(SQL_STEP(ss_ipair_dist)); @@ -158,6 +163,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. * @@ -195,6 +202,7 @@ double value_route(int nislands, const int *islands, int exclude_arbitrage) { lp= lpx_create_prob(); lpx_set_obj_dir(lp, LPX_MAX); lpx_set_int_parm(lp, LPX_K_MSGLEV, DEBUGP(lp) ? 3 : 1); + lpx_set_int_parm(lp, LPX_K_PRESOL, 1); if (DEBUGP(value)) { lpx_set_prob_name(lp,(char*)"value_route"); @@ -288,6 +296,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); @@ -305,6 +315,9 @@ double value_route(int nislands, const int *islands, int exclude_arbitrage) { lpx_delete_prob(lp); lp= 0; + debugf(" %s %f\n", + exclude_arbitrage ? "base value" : "route value", + profit); return profit; } @@ -327,10 +340,11 @@ 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) { - block= mmalloc(sizeof(*block)); + NEW(block); block->next= ip->trades; ip->trades= block; block->ntrades= 0; @@ -357,6 +371,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]; @@ -371,7 +386,7 @@ static void read_islandtradeends(const char *bs, int srcdstoff) { goto found; /* not found, add new end */ - search= mmalloc(sizeof(*search)); + NEW(search); search->commodid= commodid; search->price= price; search->next= *trades; @@ -387,16 +402,16 @@ static void read_islandtradeends(const char *bs, int srcdstoff) { void setup_value(void) { sqlite3_stmt *sst; - int i; commodstabsz= sql_single_int("SELECT max(commodid) FROM commods") + 1; - commodstab= mmalloc(sizeof(*commodstab)*commodstabsz); - for (i=0; imass= this->volu= -1 + ); 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