chiark / gitweb /
Allow computing and using dest stall poe limit
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 14 Nov 2009 17:13:41 +0000 (17:13 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 14 Nov 2009 17:13:41 +0000 (17:13 +0000)
yarrg/web/docs
yarrg/web/lookup
yarrg/web/routetrade

index 8c48814f59faddfb74be9b4b1e6cec516b1f756c..010fd456966164a95a054278ca1267aa94ec947d 100755 (executable)
@@ -178,6 +178,20 @@ You can enter the value in the box either as a percentage, or as a
 fraction 1/<em>divisor</em>, eg 1/2000 is the same as 0.05%; in each
 case it is taken as the loss for each league of the voyage.
 
+<h3><a name="poelimit">Caution about stalls' poe reserves</a></h3>
+
+If you select <b>Also be cautious about stalls' poe reserves</b>,
+YARRG will calculate a minimum amount of poe that each stall has on
+hand (by looking at all the offers that stall is making), and never
+plan for you to sell goods at that stall for more than the available
+poe.
+
+<p>
+
+Goods planned to be bought at the stall (which might boost the stall's
+poe reserves) are not considered, to avoid having to calculate the
+stall's cash reserves at various different times.
+
 <h3><a name="capital">Available capital</a></h3>
 
 If you don't specify the amount of capital you have available to
index 41a25346207ad30ebe8e37916e1761bcad51bd54..fd66f1a7b8ae8c3b1617b255a8309a244370407d 100755 (executable)
@@ -78,6 +78,9 @@ my %styles;
                Before => '',
                Values => [     [ 0, 'Show total quantity at each price' ],
                                [ 1, 'Show individual stalls' ],
+                               [ 2, "Also be cautious about stalls'".
+                                       " poe reserves",
+                                       '<a href="docs#poelimit">[?]</a>' ]
                        ],
                QuerySpecific => 1,
        }, {    Name => 'RouteSearchType',
@@ -191,7 +194,7 @@ my $prselector_core= sub {
        my $cvalix= 0;
        foreach my $valr (@{ $var->{Values} }) {
                print $delim;  $delim= "\n|\n";
-               my ($value,$html) = @$valr;
+               my ($value,$html,$finally) = @$valr;
                my $iscurrent= &{$var->{CmpCanon}}($value) eq $canon;
                my $after;
                if ($iscurrent) {
@@ -200,6 +203,7 @@ my $prselector_core= sub {
                } else {
                        my %qf= (%baseqf,%queryqf);
                        delete $qf{$lname};
+                       delete $qf{$_} foreach grep { m/^[A-Z]/ } keys %qf;
                        $qf{$lname}= $value if $cvalix;
 </%perl>
 <a href="<% $quri->(%qf) |h %>">
@@ -207,6 +211,7 @@ my $prselector_core= sub {
                        $after= '</a>';
                }
                print $html, $after;
+               print " ", $finally if defined $finally;
                $cvalix++;
        }
        print "<p>\n\n";
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;