chiark / gitweb /
Allow computing and using dest stall poe limit
[ypp-sc-tools.main.git] / yarrg / web / routetrade
index b198b9b3867ab7cff6ca4fb2150f2b33d037c921..7db07721efa2b04da634b27eaef3ade6cab34621 100644 (file)
@@ -407,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 .= "
 
@@ -485,6 +491,24 @@ foreach my $ci (0..($#islandids-1)) {
        $cplex.= "\n";
 }
 
+if ($qa->{ShowStalls}>=2) {
+       my $stallpoe= $dbh->prepare(<<END);
+SELECT max(qty*price) FROM buy WHERE stallid=?
+END
+       foreach my $stallid (sort { $a <=> $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 "
@@ -512,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 "<pre>\n" if $qa->{'debug'};
        my $found_section= 0;