X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=9cd57122d66b8fd421fd040dc00ee45abbf66422;hb=43454422b2df5e0dcfe144fcb871a2b6f9c1a3d0;hp=41340201bfc8f4d7ab99d2e87a65046d6178b784;hpb=4ee718187692e362a0e274020a0ad61701f1b2de;p=ypp-sc-tools.web-test.git diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 4134020..9cd5712 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -39,6 +39,7 @@ $dbh @archipelagoes $qa $routeparams +$reset_suppressions <& query_age:pageload &> @@ -48,6 +49,8 @@ my $loss_per_league= defined $routeparams->{LossPerLeaguePct} ? $routeparams->{LossPerLeaguePct}*0.01 : 1e-7; my $loss_per_delay_slot= 1e-8; +my $minprofit= $routeparams->{MinProfit} || 0; + my $now= time; my @flow_conds; @@ -275,13 +278,19 @@ Searched for arbitrage trades only, in <% $archipelagoes[0] |h %> <%perl> -my @sail_total; - if (!@flows) { print 'No profitable trading opportunities were found.'; return; } +my @sail_total; +my %opportunity_value; + +my $oppo_key= sub { + my ($f) = @_; + return join '_', map { $f->{$_} } qw(org_id dst_id commodid); +}; + foreach my $f (@flows) { $f->{MaxQty}= $f->{'org_qty_agg'} < $f->{'dst_qty_agg'} @@ -306,6 +315,8 @@ foreach my $f (@flows) { $dists{'org_id'}{'dst_id'}= $f->{'dist'}; + $opportunity_value{ $oppo_key->($f) } += $f->{MaxProfit}; + my @uid= $f->{commodid}; foreach my $od (qw(org dst)) { push @uid, @@ -368,11 +379,20 @@ foreach my $f (@flows) { $f->{UidLong} eq $recons_long or die "$f->{UidLong} = $f->{UidShort} = $recons_long ?"; } +} + +foreach my $f (@flows) { - if (defined $qa->{"R$f->{UidShort}"} && - !defined $qa->{"T$f->{UidShort}"}) { - $f->{Suppress}= 1; + if ($reset_suppressions || !defined $qa->{"R$f->{UidShort}"}) { + if ($opportunity_value{ $oppo_key->($f) } < $minprofit) { + $f->{Suppress}= 1; + } } else { + if (!defined $qa->{"T$f->{UidShort}"}) { + $f->{Suppress}= 1; + } + } + if (!$f->{Suppress}) { my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}}; foreach my $sfi (@$sfis) { my $subflow= { @@ -410,11 +430,17 @@ Maximize totalprofit: "; +my %stall_poe_limits; + foreach my $sf (@subflows) { my $eup= $sf->{Flow}{ExpectedUnitProfit}; $eup *= (1.0-$loss_per_delay_slot) ** $sf->{Org}; $cplex .= sprintf " %+.20f %s", $eup, $sf->{Var}; + if ($qa->{ShowStalls}>=2) { + my $stall= $sf->{Flow}{'dst_stallid'}; + push @{ $stall_poe_limits{$stall} }, $sf; + } } $cplex .= " @@ -488,6 +514,24 @@ foreach my $ci (0..($#islandids-1)) { $cplex.= "\n"; } +if ($qa->{ShowStalls}>=2) { + my $stallpoe= $dbh->prepare(< $b } keys %stall_poe_limits) { + $stallpoe->execute($stallid); + my ($lim)= $stallpoe->fetchrow_array(); + $stallpoe->finish(); + $cplex.= " + ". sprintf("%-15s","poe_$stallid:")." ". + join(" + ", map { + sprintf "%d %s", $_->{Flow}{'dst_price'}, $_->{Var}; + } @{ $stall_poe_limits{$stallid} }). + " <= $lim"; + } + $cplex.= "\n"; +} + $cplex.= " Bounds ".(join " @@ -515,7 +559,7 @@ if ($qa->{'debug'}) { my $input= pipethrough_prep(); print $input $cplex or die $!; my $output= pipethrough_run_along($input, undef, 'glpsol', - qw(glpsol --tmlim 2 --memlim 5 --intopt --cuts --bfs + qw(glpsol --tmlim 5 --memlim 5 --intopt --cuts --bfs --cpxlp /dev/stdin -o /dev/stdout)); print "
\n" if $qa->{'debug'};
 	my $found_section= 0;
@@ -638,14 +682,18 @@ Generated by YARRG at <%
 %
 % foreach my $i (0..$#islandids) {
 <% $tbody->(1) %>
-
+
 %	$iquery->execute($islandids[$i]);
 %	my ($islandname) = $iquery->fetchrow_array();
 %	if (!$i) {
+
 Start at <% $islandname |h %>
+[what are these codes?]
+
 %	} else {
 %		my $this_dist= $distance->($islandids[$i-1],$islandids[$i]);
 %		$total_dist += $this_dist;
+
 <%perl>
 		my $total_value= 0;
 		foreach my $sf (@subflows) {
@@ -689,32 +737,31 @@ Generated by YARRG at <%
 		} unless $$todo;
 		$$todo->{'commodname'}= $f->{'commodname'};
 		$$todo->{'posinclass'}= '';
-		if ($f->{'posinclass'}) {
-			my $findclass= $dbh->prepare(<{'posinclass'};
+
+		my $findclass= $dbh->prepare(<execute($f->{'commodclassid'});
-			my $classinfo= $findclass->fetchrow_hashref();
-			if ($classinfo->{'maxposinclass'} >= 8) {
+		$findclass->execute($f->{'commodclassid'});
+		my $classinfo= $findclass->fetchrow_hashref();
+		if ($classinfo) {
+			my $clname= $classinfo->{'commodclass'};
+			my $desc= encode_entities(sprintf "%s is under %s",
+					$f->{'commodname'}, $clname);
+			my $abbrev= substr($clname,0,1);
+			if ($incl) {
 				my $maxpic= $classinfo->{'maxposinclass'};
-				my $inpic= $f->{'posinclass'};
-				my @tmbs= qw(TT T M B BB);
-				my @tmbds= (	'in Top fifth of list',
-						'in 2nd fifth of the list',
-						'in Middle fifth of the list',
-						'in 2nd-bottom fifth of list',
-						'in Bottom fifth of the list');
-				my $tmbi= ($inpic+0.5)*$#tmbs/$maxpic;
-				my $desc= (sprintf "%s is under %s,".
-					" commodity %d of %d;".
-					" i.e. %s or %s",
-					$f->{'commodname'},
-					$classinfo->{'commodclass'},
-					$inpic, $maxpic,
-					$tmbs[$tmbi], $tmbds[$tmbi]);
-				$$todo->{'posinclass'}=
- "
$tmbs[$tmbi]
"; + $desc.= (sprintf ", commodity %d of %d", + $incl, $maxpic); + if ($classinfo->{'maxposinclass'} >= 8) { + my @tmbs= qw(0 1 2 3 4 5 6 7 8 9); + my $tmbi= ($incl+0.5)*$#tmbs/$maxpic; + $abbrev.= " ".$tmbs[$tmbi]." "; + } } + $$todo->{'posinclass'}= + "
" + .$abbrev."
"; } $$todo->{'stallname'}= $stallname; $$todo->{Price}= $price;