chiark / gitweb /
WIP routesearch; searcher
[ypp-sc-tools.web-live.git] / yarrg / rsvalue.c
index f1a8d224cab316a116012ff74b41c45d09704560..f046c99a896c56ee753a9430144ebd99b6fe7857 100644 (file)
@@ -32,7 +32,6 @@ typedef struct {
   TradesBlock *trades;
 } IslandPair;
 
-int nislands;
 IslandPair ***ipairs; /* ipairs[sislandid][dislandid] */
 
 typedef struct IslandTradeEnd {
@@ -108,7 +107,7 @@ static int setup_leg_constraints(double max_thing, int legs, const char *wh) {
   int leg, startrow;
   if (max_thing < 0 || !legs) return -1;
   startrow= lpx_add_rows(lp, legs);
-  for (leg=0; leg<nislands-1; leg++) {
+  for (leg=0; leg<legs; leg++) {
     int row= leg+startrow;
     lpx_set_row_bnds(lp, row, LPX_UP, 0, max_thing);
     if (DEBUGP(value)) {
@@ -129,11 +128,11 @@ static void add_leg_c(int startrow, int leg, double value) {
 static IslandPair *ipair_get(int si, int di) {
   IslandPair *ip, **ipa;
 
-  assert(si < nislands);
-  assert(di < nislands);
+  assert(si < islandtablesz);
+  assert(di < islandtablesz);
 
   if (!(ipa= ipairs[si])) {
-    ipa= ipairs[si]= mcalloc(sizeof(*ipa) * nislands);
+    ipa= ipairs[si]= mcalloc(sizeof(*ipa) * islandtablesz);
   }
   if ((ip= ipa[di]))
     return ip;
@@ -301,7 +300,6 @@ double value_route(int nislands, const int *islands) {
 
        double unit_profit= (t->dst_price - t->src_price) * loss_factor;
        debugf("    unit profit %f\n", unit_profit);
-assert(unit_profit < 1e6);
 
        lpx_set_col_bnds(lp, col, LPX_LO, 0, 0);
        lpx_set_obj_coef(lp, col, unit_profit);
@@ -325,17 +323,21 @@ assert(unit_profit < 1e6);
   next_s:;
   } /* for (s) */
 
-  if (DEBUGP(lp))
-    lpx_write_cpxlp(lp, (char*)"/dev/stdout");
+  double profit= 0;
 
-  int ipr= lpx_interior(lp);
-  assert(ipr==LPX_E_OK);
+  if (lpx_get_num_cols(lp)) {
+    if (DEBUGP(lp))
+      lpx_write_cpxlp(lp, (char*)DEBUG_DEV);
 
-  if (DEBUGP(lp))
-    lpx_print_ips(lp, (char*)"/dev/stdout");
+    int ipr= lpx_interior(lp);
+    assert(ipr==LPX_E_OK);
 
-  assert(lpx_ipt_status(lp) == LPX_T_OPT);
-  double profit= lpx_ipt_obj_val(lp);
+    if (DEBUGP(lp))
+      lpx_print_ips(lp, (char*)DEBUG_DEV);
+
+    assert(lpx_ipt_status(lp) == LPX_T_OPT);
+    profit= lpx_ipt_obj_val(lp);
+  }
 
   lpx_delete_prob(lp);
   lp= 0;
@@ -347,9 +349,6 @@ void setup_value(void) {
   sqlite3_stmt *sst;
   int i;
 
-  nislands= sql_single_int("SELECT max(islandid) FROM islands") + 1;
-  debugf("VALUE nislands=%d\n",nislands);
-
   commodstablesz= sql_single_int("SELECT max(commodid) FROM commods") + 1;
   commodstable= mmalloc(sizeof(*commodstable)*commodstablesz);
   for (i=0; i<commodstablesz; i++)
@@ -392,5 +391,5 @@ void setup_value(void) {
   BS(sell)
 #undef BS
 
-  ipairs= mcalloc(sizeof(*ipairs) * nislands);
+  ipairs= mcalloc(sizeof(*ipairs) * islandtablesz);
 }