chiark / gitweb /
Make colourful pages pass W3C HTML and CSS validators
[ypp-sc-tools.db-test.git] / yarrg / rsvalue.c
index 22b3d29..d3ffeeb 100644 (file)
@@ -62,18 +62,22 @@ static void add_constraint(int row, double coefficient) {
   constraint_coeffs[nconstraint_rows]= coefficient;
 }
 
-static void avail_c(const Trade *t, IslandTradeEnd **trades,
-                   int price, const char *srcdst,
-                   int islandid, sqlite3_stmt *ss_ite) {
-  /* find row number of trade availability constraint */
+static IslandTradeEnd *get_ite(const Trade *t, IslandTradeEnd **trades,
+                              int price) {
   IslandTradeEnd *search;
-
+  
   for (search= *trades; search; search=search->next)
     if (search->commodid==t->commodid && search->price==price)
-      goto found;
+      return search;
   abort();
-  
- found:;
+}
+
+static void avail_c(const Trade *t, IslandTradeEnd *ite,
+                   int price, const char *srcdst,
+                   int islandid, sqlite3_stmt *ss_ite) {
+  /* find row number of trade availability constraint */
+  IslandTradeEnd *search= ite;
+
   if (search->generation != generation) {
     search->rownum= lpx_add_rows(lp, 1);
     lpx_set_row_bnds(lp, search->rownum, LPX_UP, 0, search->qty);
@@ -255,10 +259,22 @@ double value_route(int nislands, const int *islands, int exclude_arbitrage) {
          debugf("  TRADE i%d#%d..i%d#%d c%d %d-%d  ",
                 si,s, di,d, t->commodid, t->src_price, t->dst_price);
 
+         IslandTradeEnd
+           *src_ite= get_ite(t, &itradeends[si].src, t->src_price),
+           *dst_ite= get_ite(t, &itradeends[di].dst, t->dst_price);
+
+         int qty= src_ite->qty < dst_ite->qty ? src_ite->qty : dst_ite->qty;
+         int maxprofit= qty * (t->dst_price - t->src_price);
+         debugf("maxprofit=%d ",maxprofit);
+         if (maxprofit < min_trade_maxprofit) {
+           debugf("trivial\n");
+           continue;
+         }
+
          nconstraint_rows=0;
 
-         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);
+         avail_c(t, src_ite, t->src_price, "src", si,ss_ite_sell);
+         avail_c(t, dst_ite, t->dst_price, "dst", di,ss_ite_buy);
 
          int leg;
          for (leg=s; leg<d; leg++) {