$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";
}
@@ -506,7 +536,8 @@ if ($qa->{'debug'}) {
my $input= pipethrough_prep();
print $input $cplex or die $!;
my $output= pipethrough_run_along($input, undef, 'glpsol',
- qw(glpsol --cpxlp /dev/stdin -o /dev/stdout));
+ qw(glpsol --tmlim 5 --memlim 5 --intopt --cuts --bfs
+ --cpxlp /dev/stdin -o /dev/stdout));
print "\n" if $qa->{'debug'};
my $found_section= 0;
my $glpsol_out= '';
@@ -519,6 +550,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/^[- ]+$/;
@@ -536,9 +570,9 @@ if ($qa->{'debug'}) {
my ($varname, $qty) = m/^
\s* \d+ \s+
(\w+) \s+ (?: [A-Z*]+ \s+ )?
- ([0-9.]+) \s
- /x or die "$_ ?";
- if ($varname =~ m/^f(\d+)s(\d+)$/) {
+ ([+-e0-9.]+) \s
+ /x or die "$cplex \n==\n $glpsol_out $_ ?";
+ if ($varname =~ m/^f(\d+)s(\d+)_/) {
my ($ix,$orgix) = ($1,$2);
my $flow= $flows[$ix] or die;
my @relsubflow= grep { $_->{Org} == $orgix }
@@ -557,6 +591,7 @@ if ($qa->{'debug'}) {
my $prerr= "\n=====\n$cplex\n=====\n$glpsol_out\n=====\n ";
pipethrough_run_finish($output,$prerr);
map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows;
+ defined $expected_total_profit or die "$prerr ?";
};
$addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub {
@@ -577,120 +612,32 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
% } # ========== OPTIMISATION ==========
-% my %ts_sortkeys;
-% {
-% my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';
-% my $cdstall= $qa->{ShowStalls} ? 'Stall | ' : '';
-
-
-
-<% $qa->{ShowStalls} ? '' : '' %>
-
-
-
-
-
-
-% if ($optimise) {
-
-% }
-
-
- | >Collect
- | >Deliver
- |
- | Collect
- | Deliver
- | Profit
- | Max
- |
- | Max
-% if ($optimise) {
- | Planned
-% }
-
- |
-
- | Island <% $cdstall %>
- | Island <% $cdstall %>
- | Commodity
- | Price
- | Qty
- | Price
- | Qty
- | Margin
- | Unit
- | Qty
- | Capital
- | Profit
- | Dist
- | Mass
- | Vol
-% if ($optimise) {
- | Qty
- | Capital
- | Profit
-% }
-% }
-
- |
-% foreach my $col (@cols) {
-
+% if (!printable($m)) {
+Contents
+
+% if ($optimise) {
+ - Voyage trading plan
+
% }
-
-% foreach my $flowix (0..$#flows) {
-% my $flow= $flows[$flowix];
-% my $rowid= "id_row_$flow->{UidShort}";
-
-{UidShort} %> value="">
- {UidShort} %> value=""
- <% $flow->{Suppress} ? '' : 'checked' %> >
-% my $ci= 1;
-% while ($ci < @cols) {
-% my $col= $cols[$ci];
-% my $spec= {
-% Span => 1,
-% Align => ($col->{Text} ? '' : 'align=right')
-% };
-% my $cn= $col->{Name};
-% my $v;
-% if (!$col->{TotalSubflows}) {
-% $v= $flow->{$cn};
-% } else {
-% $v= 0;
-% $v += $_->{$cn} foreach @{ $flow->{Subflows} };
-% }
-% 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;
- | {Span} ? "colspan=$spec->{Span}" : ''
- %> <% $spec->{Align}
- %>><% exists $spec->{String} ? $spec->{String} : $v |h %>
-% $ci += $spec->{Span};
-% }
-% }
- |
-
- | Total
-% foreach my $ci (3..$#cols) {
-% my $col= $cols[$ci];
- |
-% if (defined $col->{Total}) {
-<% $col->{Total} |h %>
-% }
+ - Data age summary
+
- Relevant trades
+
+% } else {
+% my @tl= gmtime $now or die $!;
+
+Generated by YARRG at <%
+ sprintf "%04d-%02d-%02d %02d:%02d:%02d UTC",
+ $tl[5]+1900, @tl[4,3,2,1,0]
+ |h %>.
% }
- | |
-
-<&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow',
- throw => 'trades_sort', tbrow => 'trades_total' &>
- ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
-&tabsort>
-
-
% if ($optimise) { # ========== TRADING PLAN ==========
%
@@ -700,10 +647,18 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
% my $total_total= 0;
% my $total_dist= 0;
%
-Voyage trading plan
-
+
+
+ >
+% my $tbody= sub {
+% if (!printable($m)) { return ''; }
+%# return " ";
+% my ($c)= qw(40 00)[$_[0]];
+% return " |
";
+% };
+%
% foreach my $i (0..$#islandids) {
- |
+<% $tbody->(1) %>
% $iquery->execute($islandids[$i]);
% my ($islandname) = $iquery->fetchrow_array();
@@ -733,7 +688,6 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
#print " [[ i $i od $od " if $qa->{'debug'};
foreach my $sf (@subflows) {
my $f= $sf->{Flow};
- next if $f->{Suppress};
next unless $sf->{ucfirst $od} == $i;
#print " FLOW $f->{Ix} SUB #$sf->{Org}..$sf->{Dst} "
# if $qa->{'debug'};
@@ -808,12 +762,12 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
(Data age: <% prettyprint_age($age) %>)
% } elsif (!defined $total) {
% $total= 0;
- |
+<% $tbody->(0) %>
% }
% $total += $t->{Total};
% my $span= 0 + keys %{ $t->{Stalls} };
% my $td= "td rowspan=$span";
-
+% tr_datarow($m,$dline);
<<% $td %>><% $collectdeliver %>
<<% $td %>><% $t->{'commodname'} |h %>
%
@@ -829,7 +783,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
<<% $td %> align=right><% $t->{Total} |h %> total
%
% foreach my $stallix (1..$#stalls) {
-
+% tr_datarow($m,$dline);
% $pstall->($stallix);
% }
%
@@ -844,7 +798,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
$show_flows->('org',0,'Collect'); $show_total->('Outlay',-1);
my $totals= '';
if ($i < $#islandids) {
- $totals .= "Hold: $sail_total[$i]{mass}kg,".
+ $totals .= "In hold $sail_total[$i]{mass}kg,".
" $sail_total[$i]{volume} l";
my $delim= '; spare ';
my $domv= sub {
@@ -854,14 +808,14 @@ $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);
}
-%perl>
-
+%perl>
+<% $tbody->(1) %>
Total distance: <% $total_dist %> leagues.
| Overall net cash flow
| <%
@@ -869,9 +823,177 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
%>
|
<& query_age:dataages, id2age => \%da_ages &>
+Expected average profit:
+ approx. <% sprintf "%d", $expected_total_profit %> poe
+ (considering expected losses, but ignoring rum consumed)
%
% } # ========== TRADING PLAN ==========
+% if (!printable($m)) {
+
+<%perl>
+ my $sth_i= $dbh->prepare(<prepare(<fetchrow_hashref();
+ if ($row) {
+ next if $idone{$row->{'islandid'}}++;
+ return $row;
+ }
+ }
+ return undef if $ix < 0;
+ my $iid= $islandids[$ix];
+ if (defined $iid) {
+ $sth_i->execute($iid);
+ $sth_current= $sth_i;
+ } else {
+ my $arch= $archipelagoes[$ix];
+ die unless defined $arch && length $arch;
+ $sth_a->execute($arch);
+ $sth_current= $sth_a;
+ }
+ $ix--;
+ }
+ };
+%perl>
+<&| query_age:agestable, now => $now, fetchrow => $fetchrow &>
+Islands shown in reverse order of visits.
+&>
+% }
+
+% if (!printable($m)) {
+% my %ts_sortkeys;
+% {
+% my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';
+% my $cdstall= $qa->{ShowStalls} ? 'Stall | ' : '';
+
+
+
+<&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow',
+ throw => 'trades_sort', tbrow => 'trades_total' &>
+ ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
+&tabsort>
+
+
+
+% } # !printable
+
<%init>
use CommodsWeb;
use Commods;