chiark / gitweb /
Implement constraint on available capital
authorStephen Early <steve@greenend.org.uk>
Wed, 16 Sep 2009 01:03:52 +0000 (02:03 +0100)
committerStephen Early <steve@greenend.org.uk>
Wed, 16 Sep 2009 01:03:52 +0000 (02:03 +0100)
yarrg/web/check_capitalstring [new file with mode: 0644]
yarrg/web/check_lossperleague
yarrg/web/docs
yarrg/web/lookup
yarrg/web/query_route
yarrg/web/routetrade

diff --git a/yarrg/web/check_capitalstring b/yarrg/web/check_capitalstring
new file mode 100644 (file)
index 0000000..90148c6
--- /dev/null
@@ -0,0 +1,63 @@
+<%doc>
+
+ This is part of the YARRG website.  YARRG is a tool and website
+ for assisting players of Yohoho Puzzle Pirates.
+
+ Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ Copyright (C) 2009 Clare Boothby
+
+  YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
+  The YARRG website is covered by the GNU Affero GPL v3 or later, which
+   basically means that every installation of the website will let you
+   download the source.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
+ are used without permission.  This program is not endorsed or
+ sponsored by Three Rings.
+
+
+ This Mason component simply defines how to interpret capital.
+
+</%doc>
+
+<%attr>
+</%attr>
+
+<%method preparse>
+<%args>
+$h
+</%args>
+<%perl>
+
+$_= ${ $h->{String} };
+s/^\s+//; s/\s+$//;
+
+my $res= sub {
+       my ($capital) = @_;
+       push @{ $h->{Results} }, [ $capital ];
+       ${ $h->{Canon} }= "$capital PoE";
+};
+
+if (!m/\S/) {
+} elsif (m/^([1-9]\d*)( PoE)?$/i) {
+       $res->( $1 );
+} else {
+       ${ $h->{Emsg} }= "Cannot understand capital \`$_'.";
+       return;
+}
+
+</%perl>
+</%method>
index 5994f6fdd8373831c1402499a5de0f7ddbc02fa7..41ed4b3f1a02fdb964691df18453eb6de70f4f53 100644 (file)
@@ -29,7 +29,7 @@
  sponsored by Three Rings.
 
 
  sponsored by Three Rings.
 
 
- This Mason component simply defines how to interpret capacities.
+ This Mason component simply defines how to interpret losses per league.
 
 </%doc>
 
 
 </%doc>
 
index 6f754bff46e258472de8c5d413723ab7fa8eb117..9db9320af0dfd60bea0962cb2019972522807735 100755 (executable)
@@ -179,4 +179,22 @@ You can enter the value in the box either as a percentage, or as a
 fraction 1/<em>divisor</em>, eg 1/200 is the same as 0.5%; in each
 case it is taken as the loss for each league of the voyage.
 
 fraction 1/<em>divisor</em>, eg 1/200 is the same as 0.5%; in each
 case it is taken as the loss for each league of the voyage.
 
+<h3><a name="capital">Available capital</a></h3>
+
+If you don't specify the amount of capital you have available to
+invest in the voyage, the trading plan will assume that your capital
+is unlimited.  If you specify an amount in PoE here, the trading plan
+will never require you to spend more than that amount on commodities.
+
+<p>
+
+The trading plan does not take into account accumulated profits from
+each leg of the journey when applying the available capital
+constraint.  For example, if you specify a journey from A to B to C
+and a capital limit of 10000 PoE, the trading plan will not tell you
+to buy 1000 peas at A for 10 PoE each, sail them to B and sell all of
+them for 20 PoE each, and then buy 2000 beans at B for 10 PoE each and
+sail them to C to sell for 20 PoE each even if such a trade would in
+fact be possible.  In practice this is unlikely to be a problem!
+
 <& footer &>
 <& footer &>
index 7b3100ee17b28b541416d63f2fe4aed1506d9207..661095079e5576c1964ddf3d2f94a0a71b99a49e 100755 (executable)
@@ -157,7 +157,7 @@ foreach my $var (@vars) {
 
 foreach my $var (keys %ARGS) {
        next unless $var =~
 
 foreach my $var (keys %ARGS) {
        next unless $var =~
-               m/^(?: (?:route|commod|capacity)string |
+               m/^(?: (?:route|commod|capacity|capital)string |
                        lossperleague |
                        commodid |
                        islandid \d |
                        lossperleague |
                        commodid |
                        islandid \d |
index 9a6ca0829114c622552209991c1fb6e1901094f4..81e91bcca2334c023edefb73060f544ebb77c08c 100644 (file)
@@ -40,6 +40,7 @@ $prselector
 $routestring => '';
 $capacitystring => '';
 $lossperleague => '';
 $routestring => '';
 $capacitystring => '';
 $lossperleague => '';
+$capitalstring => '';
 $someresults
 $emsgokorprint
 </%args>
 $someresults
 $emsgokorprint
 </%args>
@@ -51,6 +52,7 @@ my @islandids;
 my %islandid2;
 my ($max_volume, $max_mass);
 my $lossperleaguepct;
 my %islandid2;
 my ($max_volume, $max_mass);
 my $lossperleaguepct;
+my $capital;
 
 my $qa= \%ARGS;
 
 
 my $qa= \%ARGS;
 
@@ -119,7 +121,20 @@ Expected losses:
  &>
  size=9
 </&>
  &>
  size=9
 </&>
+</tr>
+<tr>
 
 
+<td>Available capital:
+
+<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'ac',
+    thingstring => 'capitalstring', emsgstore => \$emsg,
+    helpref => 'capital',
+    perresult => sub { ($capital)= @_; }
+ &>
+ size=9
+</&>
+</td>
+</tr>
 </table>
 
 % } else { #---------- dropdowns, user selects from menus ----------
 </table>
 
 % } else { #---------- dropdowns, user selects from menus ----------
@@ -220,7 +235,7 @@ function ms_Setarch(dd) {
 
 <input type=submit name=submit value="<% $goupdate->() %>">
 % my $ours= sub { $_[0] =~
 
 <input type=submit name=submit value="<% $goupdate->() %>">
 % my $ours= sub { $_[0] =~
-%  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^[RT]/;
+%  m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^capitalstring|^[RT]/;
 % };
 <& "lookup:formhidden", ours => $ours &>
 
 % };
 <& "lookup:formhidden", ours => $ours &>
 
@@ -268,7 +283,8 @@ for my $dd (0..$qa->{Dropdowns}-1) {
    qa => $qa,
    max_mass => $max_mass,
    max_volume => $max_volume,
    qa => $qa,
    max_mass => $max_mass,
    max_volume => $max_volume,
-   lossperleaguepct => $lossperleaguepct
+   lossperleaguepct => $lossperleaguepct,
+   max_capital => $capital
  &>
 </form>
 % }
  &>
 </form>
 % }
index 0da1fd80a81929454605e46df2064d56d26d3083..73740ea346621e5b678a9641e2b9ef5911afc412 100644 (file)
@@ -41,6 +41,7 @@ $qa
 $max_mass
 $max_volume
 $lossperleaguepct
 $max_mass
 $max_volume
 $lossperleaguepct
+$max_capital
 </%args>
 <&| script &>
   da_pageload= Date.now();
 </%args>
 <&| script &>
   da_pageload= Date.now();
@@ -451,6 +452,12 @@ foreach my $ci (0..($#islandids-1)) {
        join(" + ", map { ($_->{"unit$mv"}*1e-3).' f'.$_->{Ix} } @rel_flows).
        " <= $max";
        }
        join(" + ", map { ($_->{"unit$mv"}*1e-3).' f'.$_->{Ix} } @rel_flows).
        " <= $max";
        }
+       if (defined $max_capital) {
+          $cplex .= "
+   ". sprintf("%-10s","capital_$ci:")." ".
+       join(" + ", map { ($_->{"org_price"}).' f'.$_->{Ix} } @rel_flows).
+        " <= $max_capital";
+        }
        $cplex.= "\n";
 }
 
        $cplex.= "\n";
 }