chiark
/
gitweb
/
~yarrgweb
/
ypp-sc-tools.db-test.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
routetrade: Do not instantiate useless island pairs
[ypp-sc-tools.db-test.git]
/
yarrg
/
rsvalue.c
diff --git
a/yarrg/rsvalue.c
b/yarrg/rsvalue.c
index c3fac1a01f9260c0812ea58c0f0bffe23f395fe0..d2190dc289a9a3cc4879333da794b4c9c5f1b691 100644
(file)
--- a/
yarrg/rsvalue.c
+++ b/
yarrg/rsvalue.c
@@
-118,7
+118,17
@@
static void add_leg_c(int startrow, int leg, double value) {
add_constraint(startrow+leg, value);
}
add_constraint(startrow+leg, value);
}
-IslandPair *ipair_get(int si, int di) {
+IslandPair *ipair_get_maybe(int si, int di) {
+ IslandPair **ipa;
+
+ assert(si < islandtablesz);
+ assert(di < islandtablesz);
+
+ if (!(ipa= ipairs[si])) return 0;
+ return ipa[di];
+}
+
+static IslandPair *ipair_get_create(int si, int di) {
IslandPair *ip, **ipa;
assert(si < islandtablesz);
IslandPair *ip, **ipa;
assert(si < islandtablesz);
@@
-218,9
+228,9
@@
double value_route(int nislands, const int *islands, int exclude_arbitrage) {
/*----- actually add these trades to the LP problem -----*/
/*----- actually add these trades to the LP problem -----*/
- IslandPair *ip= ipair_get(islands[s], islands[d]);
+ IslandPair *ip= ipair_get
_maybe
(islands[s], islands[d]);
- if (!ip->trades)
+ if (!ip
|| !ip
->trades)
goto next_d;
double loss_factor= delay_slot_loss_factor * ip->distance_loss_factor;
goto next_d;
double loss_factor= delay_slot_loss_factor * ip->distance_loss_factor;
@@
-317,7
+327,7
@@
static void read_trades(void) {
SQL_DISTINCT_DECL(cols,5);
while (SQL_DISTINCT_STEP(ss_trades,cols,5)) {
SQL_DISTINCT_DECL(cols,5);
while (SQL_DISTINCT_STEP(ss_trades,cols,5)) {
- IslandPair *ip= ipair_get(cols[1], cols[3]);
+ 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));
TradesBlock *block= ip->trades;
if (!block || ip->trades->ntrades >= TRADES_PER_BLOCK) {
block= mmalloc(sizeof(*block));