From 1a64a4e4703ade43ff0b26150f8128969be0ec8b Mon Sep 17 00:00:00 2001 From: Stephen Early Date: Wed, 16 Sep 2009 02:03:52 +0100 Subject: [PATCH] Implement constraint on available capital --- yarrg/web/check_capitalstring | 63 +++++++++++++++++++++++++++++++++++ yarrg/web/check_lossperleague | 2 +- yarrg/web/docs | 18 ++++++++++ yarrg/web/lookup | 2 +- yarrg/web/query_route | 20 +++++++++-- yarrg/web/routetrade | 7 ++++ 6 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 yarrg/web/check_capitalstring diff --git a/yarrg/web/check_capitalstring b/yarrg/web/check_capitalstring new file mode 100644 index 0000000..90148c6 --- /dev/null +++ b/yarrg/web/check_capitalstring @@ -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 + 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 . + + 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. + + + +<%attr> + + +<%method preparse> +<%args> +$h + +<%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; +} + + + diff --git a/yarrg/web/check_lossperleague b/yarrg/web/check_lossperleague index 5994f6f..41ed4b3 100644 --- a/yarrg/web/check_lossperleague +++ b/yarrg/web/check_lossperleague @@ -29,7 +29,7 @@ sponsored by Three Rings. - This Mason component simply defines how to interpret capacities. + This Mason component simply defines how to interpret losses per league. diff --git a/yarrg/web/docs b/yarrg/web/docs index 6f754bf..9db9320 100755 --- a/yarrg/web/docs +++ b/yarrg/web/docs @@ -179,4 +179,22 @@ You can enter the value in the box either as a percentage, or as a fraction 1/divisor, eg 1/200 is the same as 0.5%; in each case it is taken as the loss for each league of the voyage. +

Available capital

+ +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. + +

+ +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 &> diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 7b3100e..6610950 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -157,7 +157,7 @@ foreach my $var (@vars) { foreach my $var (keys %ARGS) { next unless $var =~ - m/^(?: (?:route|commod|capacity)string | + m/^(?: (?:route|commod|capacity|capital)string | lossperleague | commodid | islandid \d | diff --git a/yarrg/web/query_route b/yarrg/web/query_route index 9a6ca08..81e91bc 100644 --- a/yarrg/web/query_route +++ b/yarrg/web/query_route @@ -40,6 +40,7 @@ $prselector $routestring => ''; $capacitystring => ''; $lossperleague => ''; +$capitalstring => ''; $someresults $emsgokorprint @@ -51,6 +52,7 @@ my @islandids; my %islandid2; my ($max_volume, $max_mass); my $lossperleaguepct; +my $capital; my $qa= \%ARGS; @@ -119,7 +121,20 @@ Expected losses: &> size=9 + + +Available capital: + +<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'ac', + thingstring => 'capitalstring', emsgstore => \$emsg, + helpref => 'capital', + perresult => sub { ($capital)= @_; } + &> + size=9 + + + % } else { #---------- dropdowns, user selects from menus ---------- @@ -220,7 +235,7 @@ function ms_Setarch(dd) { % my $ours= sub { $_[0] =~ -% m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^[RT]/; +% m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^capitalstring|^[RT]/; % }; <& "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, - lossperleaguepct => $lossperleaguepct + lossperleaguepct => $lossperleaguepct, + max_capital => $capital &> % } diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 0da1fd8..73740ea 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -41,6 +41,7 @@ $qa $max_mass $max_volume $lossperleaguepct +$max_capital <&| 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"; } + if (defined $max_capital) { + $cplex .= " + ". sprintf("%-10s","capital_$ci:")." ". + join(" + ", map { ($_->{"org_price"}).' f'.$_->{Ix} } @rel_flows). + " <= $max_capital"; + } $cplex.= "\n"; } -- 2.30.2