$qa
$routeparams
$reset_suppressions
+$quri
</%args>
<& query_age:pageload &>
my $loss_per_league= defined $routeparams->{LossPerLeaguePct}
? $routeparams->{LossPerLeaguePct}*0.01 : 1e-7;
my $loss_per_delay_slot= 1e-8;
+my $max_gems= 24;
my $minprofit= $routeparams->{MinProfit} || 0;
commods.ordval ordval,
commods.posinclass posinclass,
commods.commodclassid commodclassid,
+ commods.flags flags,
dist dist,
buy.price - sell.price unitprofit
FROM commods
return join '_', map { $f->{$_} } qw(org_id dst_id commodid);
};
+my $any_previous_suppression= 0;
+
foreach my $f (@flows) {
$f->{MaxQty}= $f->{'org_qty_agg'} < $f->{'dst_qty_agg'}
}
} else {
if (!defined $qa->{"T$f->{UidShort}"}) {
+ $any_previous_suppression= 1;
$f->{Suppress}= 1;
}
}
}
</%perl>
-% my $optimise= $specific;
-% if (!$optimise) {
+% my $optimise= 1;
-<p>
% if (!$specific) {
+% $optimise= 0;
Route contains archipelago(es), not just specific islands.
+% } elsif (!@subflows) {
+% $optimise= 0;
+% if ($any_previous_suppression) {
+All available trades deselected.
+% } else {
+No available trades meet the specified minimum trade value, so
+all available trades deselected.
+% }
% }
+
+% if (!$optimise) {
+
+<p>
Therefore, optimal voyage trade plan not calculated.
% } else { # ========== OPTMISATION ==========
$applylimit->('mass', sub { $_[0]{'unitmass'} *1e-3 });
$applylimit->('volume', sub { $_[0]{'unitvolume'}*1e-3 });
$applylimit->('capital', sub { $_[0]{'org_price'} });
+
+ my @gem_subflows= grep { $_->{Flow}{flags} =~ m/g/ } @rel_subflows;
+ if (@gem_subflows) {
+ $cplex .= "
+ ". sprintf("%-10s","gems_$ci:")." ".
+ join(" + ", map { $_->{Var} } @gem_subflows). " <= $max_gems";
+ }
+
$cplex.= "\n";
}
<%perl>
}
-{
+my $try_solve= sub {
+ my (@opts) = @_;
my $input= pipethrough_prep();
print $input $cplex or die $!;
my $output= pipethrough_run_along($input, undef, 'glpsol',
- qw(glpsol --tmlim 5 --memlim 5 --intopt --cuts --bfs
- --cpxlp /dev/stdin -o /dev/stdout));
- print "<pre>\n" if $qa->{'debug'};
+ qw(glpsol --tmlim 1 --memlim 5), @opts,
+ qw( --cpxlp /dev/stdin -o /dev/stdout));
+ if ($qa->{'debug'}) {
+ print "<h3>@opts</h3>\n<pre>\n";
+ }
+ $expected_total_profit= undef;
+ $_->{OptQty}= undef foreach @subflows;
my $found_section= 0;
my $glpsol_out= '';
my $continuation='';
+ my $timelimit= 0;
+ my $somemip= 0;
while (<$output>) {
$glpsol_out.= $_;
print encode_entities($_) if $qa->{'debug'};
$found_section= 1;
next;
}
+ if ((m/^Integer optimization begins/ .. 0) &&
+ m/^\+ \s* \d+\: \s* mip \s* = \s* \d/) {
+ $somemip= 1;
+ next;
+ }
+ if (m/^TIME LIMIT EXCEEDED/) {
+ $timelimit= 1;
+ }
if (m/^Objective:\s+totalprofit = (\d+(?:\.\d*)?) /) {
$expected_total_profit= $1;
}
my ($varname, $qty) = m/^
\s* \d+ \s+
(\w+) \s+ (?: [A-Z*]+ \s+ )?
- ([+-e0-9.]+) \s
+ ([-+0-9]+)(?: [.e][-+e0-9.]* )? \s
/x or die "$cplex \n==\n $glpsol_out $_ ?";
if ($varname =~ m/^f(\d+)s(\d+)_/) {
my ($ix,$orgix) = ($1,$2);
pipethrough_run_finish($output,$prerr);
map { defined $_->{OptQty} or die "$prerr $_->{Flow}{Ix}" } @subflows;
defined $expected_total_profit or die "$prerr ?";
+ return $somemip || !$timelimit;
};
+unless ($try_solve->(qw( --intopt --cuts --bfs )) or
+ $try_solve->(qw( --nomip ))) {
+</%perl>
+<h2>Optimisation failed</h2>
+The linear/mixed-integer optimisation failed.
+Please report this problem.
+
+<pre>
+<% $cplex |h %>
+</pre>
+<%perl>
+ return;
+}
+
$addcols->({ DoReverse => 1, TotalSubflows => 1, Special => sub {
my ($flow,$col,$v,$spec) = @_;
if ($flow->{ExpectedUnitProfit} < 0) {
orgArbitrage => 0,
dstArbitrage => 0,
} unless $$todo;
+ $$todo->{'commodid'}= $f->{'commodid'};
$$todo->{'commodname'}= $f->{'commodname'};
$$todo->{'posinclass'}= '';
my $incl= $f->{'posinclass'};
% $total += $t->{Total};
% my $span= 0 + keys %{ $t->{Stalls} };
% my $td= "td rowspan=$span";
+% my %linkqf= (%{ $qa->{'baseqf'} }, %{ $qa->{'queryqf'} });
+% $linkqf{'query'}= 'commod';
+% $linkqf{'commodstring'}= $t->{'commodname'};
+% $linkqf{'commodid'}= $t->{'commodid'};
% tr_datarow($m,$dline);
<<% $td %>><% $collectdeliver %>
-<<% $td %>><% $t->{'commodname'} |h %>
+<<% $td %>><a href="<% $quri->(%linkqf) %>"><% $t->{'commodname'} |h %></a>
<<% $td %>><% $t->{'posinclass'} %>
%
% my @stalls= sort keys %{ $t->{Stalls} };