X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=7db07721efa2b04da634b27eaef3ade6cab34621;hb=ae926461ebeb67c806caa7be5d85d18a02a08177;hp=68f9d2703bd4c97ab8d4bd115a01be6ffae1bd9f;hpb=60709393692d3e50630639ad391e4c37dbeca006;p=ypp-sc-tools.db-test.git diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 68f9d27..7db0772 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -292,22 +292,6 @@ foreach my $f (@flows) { $f->{"Max$v"}= sprintf "%.1f", $f->{"Max${v}SortKey"} * 1e-6; } - my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}}; - foreach my $sfi (@$sfis) { - my $subflow= { - Flow => $f, - Org => $sfi->[0], - Dst => $sfi->[1], - Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d", - $f->{Ix}, $sfi->[0], - $f->{'commodid'}, - $sfi->[0], $f->{'org_price'}, - $sfi->[1], $f->{'dst_price'} - }; - push @{ $f->{Subflows} }, $subflow; - push @subflows, $subflow; - } - $f->{MarginSortKey}= sprintf "%d", $f->{'dst_price'} * 10000 / $f->{'org_price'}; $f->{Margin}= sprintf "%3.1f%%", @@ -385,8 +369,23 @@ foreach my $f (@flows) { if (defined $qa->{"R$f->{UidShort}"} && !defined $qa->{"T$f->{UidShort}"}) { $f->{Suppress}= 1; + } else { + my $sfis= $ipair2subflowinfs{$f->{'org_id'},$f->{'dst_id'}}; + foreach my $sfi (@$sfis) { + my $subflow= { + Flow => $f, + Org => $sfi->[0], + Dst => $sfi->[1], + Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d", + $f->{Ix}, $sfi->[0], + $f->{'commodid'}, + $sfi->[0], $f->{'org_price'}, + $sfi->[1], $f->{'dst_price'} + }; + push @{ $f->{Subflows} }, $subflow; + push @subflows, $subflow; + } } - } @@ -408,11 +407,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 .= " @@ -421,13 +426,7 @@ Subject To my %avail_lims; foreach my $flow (@flows) { - if ($flow->{Suppress}) { - foreach my $sf (@{ $flow->{Subflows} }) { - $cplex .= " - $sf->{Var} = 0"; - } - next; - } + next if $flow->{Suppress}; foreach my $od (qw(org dst)) { my $limname= join '_', ( $od, @@ -492,6 +491,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 " @@ -519,7 +536,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;
@@ -533,7 +550,7 @@ if ($qa->{'debug'}) {
 			$found_section= 1;
 			next;
 		}
-		if (m/^Objective:\s+totalprofit = (\d+\.\d*) /) {
+		if (m/^Objective:\s+totalprofit = (\d+(?:\.\d*)?) /) {
 			$expected_total_profit= $1;
 		}
 		next unless $found_section==1;
@@ -553,8 +570,8 @@ if ($qa->{'debug'}) {
 		my ($varname, $qty) = m/^
 			\s* \d+ \s+
 			(\w+) \s+ (?: [A-Z*]+ \s+ )?
-			([0-9.]+) \s
-			/x or die "$_ ?";
+			([+-e0-9.]+) \s
+			/x or die "$cplex \n==\n $glpsol_out $_ ?";
 		if ($varname =~ m/^f(\d+)s(\d+)_/) {
 			my ($ix,$orgix) = ($1,$2);
 			my $flow= $flows[$ix] or die;
@@ -574,6 +591,7 @@ if ($qa->{'debug'}) {
 	my $prerr= "\n=====\n$cplex\n=====\n$glpsol_out\n=====\n ";
 	pipethrough_run_finish($output,$prerr);
 	map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows;
+	defined $expected_total_profit or die "$prerr ?";
 };
 
 $addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub {
@@ -631,7 +649,7 @@ Generated by YARRG at <%
 %
 

Voyage trading plan

- > +
> % my $tbody= sub { % if (!printable($m)) { return ''; } %# return "' : '';

Relevant trades

-

"; @@ -670,7 +688,6 @@ Generated by YARRG at <% #print " [[ i $i od $od " if $qa->{'debug'}; foreach my $sf (@subflows) { my $f= $sf->{Flow}; - next if $f->{Suppress}; next unless $sf->{ucfirst $od} == $i; #print " FLOW $f->{Ix} SUB #$sf->{Org}..$sf->{Dst} " # if $qa->{'debug'}; @@ -864,7 +881,7 @@ Islands shown in reverse order of visits.
% my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : ''; % my $cdstall= $qa->{ShowStalls} ? '
Stall
+
<% $qa->{ShowStalls} ? '' : '' %> @@ -972,7 +989,7 @@ Islands shown in reverse order of visits.
throw => 'trades_sort', tbrow => 'trades_total' &> ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>; - +

% } # !printable