chiark / gitweb /
routesearch: link to full voyage plans
[ypp-sc-tools.db-live.git] / yarrg / web / routetrade
index d90bf40fb7afe7993c0f0924e4ea38c2e6dc2ba0..d66e8b1772c8bb8a4b8db0dceedac4e244dff740 100644 (file)
@@ -38,10 +38,7 @@ $dbh
 @islandids
 @archipelagoes
 $qa
-$max_mass
-$max_volume
-$lossperleaguepct
-$max_capital
+$routeparams
 </%args>
 <&| script &>
   da_pageload= Date.now();
@@ -49,7 +46,8 @@ $max_capital
 
 <%perl>
 
-my $loss_per_league= defined $lossperleaguepct ? $lossperleaguepct*0.01 : 1e-7;
+my $loss_per_league= defined $routeparams->{LossPerLeaguePct}
+       ? $routeparams->{LossPerLeaguePct}*0.01 : 1e-7;
 my $loss_per_delay_slot= 1e-8;
 
 my $now= time;
@@ -57,6 +55,7 @@ my $now= time;
 my @flow_conds;
 my @query_params;
 my %dists;
+my $expected_total_profit;
 
 my $sd_condition= sub {
        my ($bs, $ix) = @_;
@@ -292,7 +291,11 @@ foreach my $f (@flows) {
                        Flow => $f,
                        Org => $sfi->[0],
                        Dst => $sfi->[1],
-                       Var => sprintf "f%ss%s", $f->{Ix}, $sfi->[0]
+                       Var => sprintf "f%ss%s_c%d_p%d_%d_p%d_%d",
+                               $f->{Ix}, $sfi->[0],
+                               $f->{'commodid'},
+                               $sfi->[0], $f->{'org_price'},
+                               $sfi->[1], $f->{'dst_price'}
                };
                push @{ $f->{Subflows} }, $subflow;
                push @subflows, $subflow;
@@ -420,10 +423,9 @@ foreach my $flow (@flows) {
        }
        foreach my $od (qw(org dst)) {
                my $limname= join '_', (
-                       'avail',
-                       $flow->{'commodid'},
                        $od,
-                       $flow->{"${od}_id"},
+                       'i'.$flow->{"${od}_id"},
+                       'c'.$flow->{'commodid'},
                        $flow->{"${od}_price"},
                        $flow->{"${od}_stallid"},
                );
@@ -464,7 +466,8 @@ foreach my $ci (0..($#islandids-1)) {
        }
 
        my $applylimit= sub {
-               my ($mv, $max, $f2val) = @_;
+               my ($mv, $f2val) = @_;
+               my $max= $routeparams->{"Max".ucfirst $mv};
                $max= 1e9 unless defined $max;
 #print " DEFINED MAX $mv $max ";
                $cplex .= "
@@ -476,9 +479,9 @@ foreach my $ci (0..($#islandids-1)) {
                " <= $max";
        };
 
-       $applylimit->('mass',   $max_mass,   sub { $_[0]{'unitmass'}  *1e-3 });
-       $applylimit->('volume', $max_volume, sub { $_[0]{'unitvolume'}*1e-3 });
-       $applylimit->('capital',$max_capital,sub { $_[0]{'org_price'}       });
+       $applylimit->('mass',    sub { $_[0]{'unitmass'}  *1e-3 });
+       $applylimit->('volume',  sub { $_[0]{'unitvolume'}*1e-3 });
+       $applylimit->('capital', sub { $_[0]{'org_price'}       });
        $cplex.= "\n";
 }
 
@@ -523,6 +526,9 @@ if ($qa->{'debug'}) {
                        $found_section= 1;
                        next;
                }
+               if (m/^Objective:\s+totalprofit = (\d+\.\d*) /) {
+                       $expected_total_profit= $1;
+               }
                next unless $found_section==1;
                if (!length $continuation) {
                        next if !$continuation &&  m/^[- ]+$/;
@@ -542,7 +548,7 @@ if ($qa->{'debug'}) {
                        (\w+) \s+ (?: [A-Z*]+ \s+ )?
                        ([0-9.]+) \s
                        /x or die "$_ ?";
-               if ($varname =~ m/^f(\d+)s(\d+)$/) {
+               if ($varname =~ m/^f(\d+)s(\d+)_/) {
                        my ($ix,$orgix) = ($1,$2);
                        my $flow= $flows[$ix] or die;
                        my @relsubflow= grep { $_->{Org} == $orgix }
@@ -858,8 +864,8 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
                $totals .= sprintf "%g %s", ($max-$got), $units;
                $delim= ', ';
        };
-       $domv->($max_mass,   $sail_total[$i]{mass},   'kg');
-       $domv->($max_volume, $sail_total[$i]{volume}, 'l');
+       $domv->($routeparams->{MaxMass},   $sail_total[$i]{mass},   'kg');
+       $domv->($routeparams->{MaxVolume}, $sail_total[$i]{volume}, 'l');
        $totals .= ".\n";
      }
      $show_total_now->($totals);
@@ -873,6 +879,9 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
  %></strong>
 </table>
 <& query_age:dataages, id2age => \%da_ages &>
+Expected average profit:
+ approx. <strong><% sprintf "%d", $expected_total_profit %></strong> poe
+ (considering expected losses, but ignoring rum consumed)
 %
 % } # ========== TRADING PLAN ==========