X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Frsvalue.c;h=b469378303de295f3c12d17b20cc9b65f44ac772;hp=8fe5f229b04b00355817b7225475a9068e8d9621;hb=ee1e57fa0fab5d840206d73a3968fd59d7fa7127;hpb=4ed298fb2ac975783ad1a350659f5ae22825e24e diff --git a/yarrg/rsvalue.c b/yarrg/rsvalue.c index 8fe5f22..b469378 100644 --- a/yarrg/rsvalue.c +++ b/yarrg/rsvalue.c @@ -1,10 +1,36 @@ -/**/ +/* + * Route searcher - route evaluation + */ +/* + * This is part of the YARRG website, a tool for assisting + * players of Yohoho Puzzle Pirates. + * + * Copyright (C) 2009 Ian Jackson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + * are used without permission. This program is not endorsed or + * sponsored by Three Rings. + */ #include #include "rscommon.h" DEBUG_DEFINE_DEBUGF(value); +DEBUG_DEFINE_SOME_DEBUGF(value2,debug2f); typedef struct { int mass, volu; } CommodInfo; static int commodstabsz; @@ -61,18 +87,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); @@ -148,7 +178,7 @@ static IslandPair *ipair_get_create(int si, int di) { if (si==di) ctr_islands_arbitrage++; else ctr_ipairs_relevant++; - debugf("VALUE ipair_get(i%d,i%d) running...\n", si,di); + 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)); @@ -254,10 +284,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