chiark / gitweb /
WIP routesearch; bugfixes
authorIan Jackson <ian@liberator.(none)>
Sat, 3 Oct 2009 20:38:54 +0000 (21:38 +0100)
committerIan Jackson <ian@liberator.(none)>
Sat, 3 Oct 2009 20:38:54 +0000 (21:38 +0100)
yarrg/rscommon.h
yarrg/rsvalue.c

index d81551443a3269402f5d3208680c22b32be5a9ef..a9bca8c1fdadc87dfab844bcde2f28d9f4fe8350 100644 (file)
@@ -8,6 +8,7 @@
    DF(sql2)                                    \
    DF(value)                                   \
    DF(search)                                  \
    DF(sql2)                                    \
    DF(value)                                   \
    DF(search)                                  \
+   DF(check)                                   \
    DF(lp)
 
 #define debug stdout
    DF(lp)
 
 #define debug stdout
index f86731923f873524a80e7446600f9d4a0f1f9694..b4e23227d2b42ca598612ac21cb8248150cee9a4 100644 (file)
@@ -94,9 +94,18 @@ static void avail_c(const Trade *t, IslandTradeEnd **trades,
     search->rownum= lpx_add_rows(lp, 1);
     lpx_set_row_bnds(lp, search->rownum, LPX_UP, 0, search->qty);
 
     search->rownum= lpx_add_rows(lp, 1);
     lpx_set_row_bnds(lp, search->rownum, LPX_UP, 0, search->qty);
 
-    if (DEBUGP(value)) {
-      char *name= masprintf("%s_c%d_%d",srcdst,t->commodid,price);
+    if (DEBUGP(value) || DEBUGP(check)) {
+      char *name= masprintf("%s_i%d_c%d_%d_all",
+                           srcdst, islandid, t->commodid, price);
       lpx_set_row_name(lp,search->rownum,name);
       lpx_set_row_name(lp,search->rownum,name);
+
+      if (DEBUGP(check)) {
+       int nrows= lpx_get_num_rows(lp);
+       assert(search->rownum == nrows);
+       int i;
+       for (i=1; i<nrows; i++)
+         assert(strcmp(name, lpx_get_row_name(lp,i)));
+      }
       free(name);
     }
     search->generation= generation;
       free(name);
     }
     search->generation= generation;
@@ -113,7 +122,7 @@ static int setup_leg_constraints(double max_thing, int legs, const char *wh) {
     int row= leg+startrow;
     lpx_set_row_bnds(lp, row, LPX_UP, 0, max_thing);
     if (DEBUGP(value)) {
     int row= leg+startrow;
     lpx_set_row_bnds(lp, row, LPX_UP, 0, max_thing);
     if (DEBUGP(value)) {
-      char *name= masprintf("max_leg%d_%s",leg,wh);
+      char *name= masprintf("%s_%d",wh,leg);
       lpx_set_row_name(lp,row,name);
       free(name);
     }
       lpx_set_row_name(lp,row,name);
       free(name);
     }
@@ -259,6 +268,9 @@ double value_route(int nislands, const int *islands) {
       int col= lpx_add_cols(lp,ip->ntrades);
 
       double loss_factor= delay_slot_loss_factor * ip->distance_loss_factor;
       int col= lpx_add_cols(lp,ip->ntrades);
 
       double loss_factor= delay_slot_loss_factor * ip->distance_loss_factor;
+      debugf(" SOME   i%d#%d..i%d#%d  dslf=%g dlf=%g  lf=%g\n",
+            si,s, di,d,
+            delay_slot_loss_factor, ip->distance_loss_factor, loss_factor);
 
       while (tradestodo-- >0) {
        if (inblock >= TRADES_PER_BLOCK) {
 
       while (tradestodo-- >0) {
        if (inblock >= TRADES_PER_BLOCK) {
@@ -267,22 +279,22 @@ double value_route(int nislands, const int *islands) {
        }
        Trade *t= &block->t[inblock++];
 
        }
        Trade *t= &block->t[inblock++];
 
-       debugf("  TRADE %d#%d..%d#%d %d %d-%d\n",
+       debugf("  TRADE i%d#%d..i%d#%d c%d %d-%d  ",
               si,s, di,d, t->commodid, t->src_price, t->dst_price);
 
        nconstraint_rows=0;
 
               si,s, di,d, t->commodid, t->src_price, t->dst_price);
 
        nconstraint_rows=0;
 
-       avail_c(t, &itradeends[s].src, t->src_price, "src", si, ss_ite_sell);
-       avail_c(t, &itradeends[d].dst, t->dst_price, "dst", di, ss_ite_buy);
+       avail_c(t, &itradeends[si].src, t->src_price, "src", si, ss_ite_sell);
+       avail_c(t, &itradeends[di].dst, t->dst_price, "dst", di, ss_ite_buy);
 
        int leg;
        for (leg=s; leg<d; leg++) {
 
        int leg;
        for (leg=s; leg<d; leg++) {
-         add_leg_c(mass_constraints, leg, commodstable[t->commodid].mass);
-         add_leg_c(volu_constraints, leg, commodstable[t->commodid].volu);
-         add_leg_c(capi_constraints, leg, t->src_price);
+         add_leg_c(mass_constraints,leg, commodstable[t->commodid].mass*1e-3);
+         add_leg_c(volu_constraints,leg, commodstable[t->commodid].volu*1e-3);
+         add_leg_c(capi_constraints,leg, t->src_price);
        }
 
        }
 
-       double unit_profit= (t->dst_price - t->src_price) * loss_factor;
+       double unit_profit= t->dst_price * loss_factor - t->src_price;
        debugf("    unit profit %f\n", unit_profit);
 
        lpx_set_col_bnds(lp, col, LPX_LO, 0, 0);
        debugf("    unit profit %f\n", unit_profit);
 
        lpx_set_col_bnds(lp, col, LPX_LO, 0, 0);