chiark / gitweb /
Implement percentage loss per league
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 4 Sep 2009 18:26:25 +0000 (19:26 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 4 Sep 2009 18:26:25 +0000 (19:26 +0100)
yarrg/web/routetrade

index 9311f1a4fc508b247e580dda8c278d9294e51f04..831a1b1a26a2d46f051ec4265f8089cb13fbf7da 100644 (file)
@@ -50,16 +50,12 @@ $lossperleaguepct
 <strong>WARNING - VESSEL CAPACITY LIMIT NOT YET IMPLEMENTED</strong>
 <p>
 % }
-% if (defined $lossperleaguepct) {
-<strong>WARNING - DEFINED LOSS PER LEAGUE NOT YET IMPLEMENTED</strong>
-<% $lossperleaguepct |h %>
-<p>
-% }
 
 <%perl>
 
+my $loss_per_league= defined $lossperleaguepct ? $lossperleaguepct*0.01 : 1e-7;
+
 my $now= time;
-my $loss_per_league= 1e-7;
 
 my @flow_conds;
 my @query_params;
@@ -396,9 +392,9 @@ my $cplex= "
 Maximize
 
   totalprofit:
-                  ".(join " +
+                  ".(join "
                   ", map {
-                       sprintf "%.20f %s", $_->{ExpectedUnitProfit}, $_->{Var}
+                       sprintf "%+.20f %s", $_->{ExpectedUnitProfit}, $_->{Var}
                        } @flows)."
 
 Subject To
@@ -485,7 +481,14 @@ if ($qa->{'debug'}) {
        die $prerr unless $found_section;
 };
 
-$addcols->({ DoReverse => 1 }, qw(
+$addcols->({ DoReverse => 1, Special => sub {
+       my ($flow,$col,$v,$spec) = @_;
+       if ($flow->{ExpectedUnitProfit} < 0) {
+               $spec->{Span}= 3;
+               $spec->{String}= '(Small margin)';
+               $spec->{Align}= 'align=center';
+       }
+} }, qw(
                OptQty
        ));
 $addcols->({ Total => 0, DoReverse => 1 }, qw(
@@ -564,16 +567,25 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 <td><input type=hidden   name=R<% $flow->{UidShort} %> value="">
     <input type=checkbox name=T<% $flow->{UidShort} %> value=""
        <% $flow->{Suppress} ? '' : 'checked' %> >
-%      foreach my $ci (1..$#cols) {
+%      my $ci= 1;
+%      while ($ci < @cols) {
 %              my $col= $cols[$ci];
+%              my $spec= {
+%                      Span => 1,
+%                      Align => ($col->{Text} ? '' : 'align=right')
+%              };
 %              my $v= $flow->{$col->{Name}};
+%              if ($col->{Special}) { $col->{Special}($flow,$col,$v,$spec); }
 %              $col->{Total} += $v
 %                      if defined $col->{Total} and not $flow->{Suppress};
 %              $v='' if !$col->{Text} && !$v;
 %              my $sortkey= $col->{SortColKey} ?
 %                      $flow->{$col->{SortColKey}} : $v;
 %              $ts_sortkeys{$ci}{$rowid}= $sortkey;
-<td <% $col->{Text} ? '' : 'align=right' %>><% $v |h %>
+<td <% $spec->{Span} ? "colspan=$spec->{Span}" : ''
+ %> <% $spec->{Align}
+ %>><% exists $spec->{String} ? $spec->{String} : $v |h %>
+%              $ci += $spec->{Span};
 %      }
 % }
 <tr id="trades_total">