chiark / gitweb /
Merge branch 'stable-5.x'
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 14 Nov 2009 17:16:48 +0000 (17:16 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 14 Nov 2009 17:16:48 +0000 (17:16 +0000)
1  2 
yarrg/web/docs
yarrg/web/routetrade

diff --combined yarrg/web/docs
index 0f6249199c07344c4b17a919c4387ce4187cd0ab,010fd456966164a95a054278ca1267aa94ec947d..2be018e810270b3b14cb3feb7ccb5db2c439031b
@@@ -178,6 -178,20 +178,20 @@@ You can enter the value in the box eith
  fraction 1/<em>divisor</em>, eg 1/2000 is the same as 0.05%; in each
  case it is taken as the loss for each league of the voyage.
  
+ <h3><a name="poelimit">Caution about stalls' poe reserves</a></h3>
+ If you select <b>Also be cautious about stalls' poe reserves</b>,
+ YARRG will calculate a minimum amount of poe that each stall has on
+ hand (by looking at all the offers that stall is making), and never
+ plan for you to sell goods at that stall for more than the available
+ poe.
+ <p>
+ Goods planned to be bought at the stall (which might boost the stall's
+ poe reserves) are not considered, to avoid having to calculate the
+ stall's cash reserves at various different times.
  <h3><a name="capital">Available capital</a></h3>
  
  If you don't specify the amount of capital you have available to
@@@ -196,55 -210,5 +210,55 @@@ them for 20 PoE each, and then buy 200
  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!
  
 +<h3><a name="posinclass">Locating commodities in the YPP client UI</a></h3>
 +
 +In the Voyage Trading Plan, YARRG indicates after the commodity name
 +where in the YPP commodity UI each commodity can be found.  First
 +comes the initial letter of the category:
 +%     my $dbh= dbw_connect('Midnight');
 +%     my $getclasses= $dbh->prepare(
 +%        "SELECT commodclass FROM commodclasses ORDER BY commodclass");
 +%     $getclasses->execute();
 +<%
 +    join '; ', map { $_->[0] =~ m/^./ or die; "<strong>$&</strong>$'" }
 +        @{ $getclasses->fetchall_arrayref() }
 +%>.
 +<p>
 +
 +Then, if applicable, follows a number from <strong>0</strong> to
 +<strong>9</strong> indicating roughly where the commodity is in the
 +list of commodities of the same class.  The number indicates which
 +tenth of the list is: <strong>0</strong> for the first (top) tenth,
 +<strong>1</strong> for the 2nd, and so on, up to <strong>9</strong>
 +for the final tenth.
 +
 +<p>
 +For example,
 +<blockquote>
 +<table><tr>
 +<td>Fine pink cloth&nbsp;&nbsp;
 +<td><div class=mouseover
 + title="Fine pink cloth is under Cloth, commodity 14 of 55">C 2</div>
 +</table>
 +</blockquote>
 +indicates that Fine pink cloth can be found under Cloth,
 +between 20% and 30% of the way down through the types of Cloth.
 +If you mouseover that in a suitably equipped browser you should see the
 +text:
 +<blockquote>
 +Fine pink cloth is under Cloth, commodity 14 of 55
 +</blockquote>
 +<p>
 +
 +The position indicator digit isn't shown for very small
 +categories.
 +
 +The exact location of the commodity in the actual game
 +client may vary because YARRG only considers the list of all possible
 +commodities, not the list of actual offers at the island in question.
 +
 +Also, not all commodities are always completely categorised or
 +ordered; we are working to add the additional data
 +
  </div>
  <& footer &>
diff --combined yarrg/web/routetrade
index 59a856631b5a1cfdc042664a3d7c67815453c61f,7db07721efa2b04da634b27eaef3ade6cab34621..9660094532aa1544fb5db23092546991c098ee75
@@@ -140,9 -140,6 +140,9 @@@ my $stmt= 
                commods.commodid                                commodid,
                commods.unitmass                                unitmass,
                commods.unitvolume                              unitvolume,
 +              commods.ordval                                  ordval,
 +              commods.posinclass                              posinclass,
 +              commods.commodclassid                           commodclassid,
                dist                                            dist,
                buy.price - sell.price                          unitprofit
        FROM commods
@@@ -410,11 -407,17 +410,17 @@@ Maximiz
    totalprofit:
  ";
  
+ my %stall_poe_limits;
  foreach my $sf (@subflows) {
        my $eup= $sf->{Flow}{ExpectedUnitProfit};
        $eup *= (1.0-$loss_per_delay_slot) ** $sf->{Org};
        $cplex .= sprintf "
                %+.20f %s", $eup, $sf->{Var};
+       if ($qa->{ShowStalls}>=2) {
+               my $stall= $sf->{Flow}{'dst_stallid'};
+               push @{ $stall_poe_limits{$stall} }, $sf;
+       }
  }
  $cplex .= "
  
@@@ -488,6 -491,24 +494,24 @@@ foreach my $ci (0..($#islandids-1)) 
        $cplex.= "\n";
  }
  
+ if ($qa->{ShowStalls}>=2) {
+       my $stallpoe= $dbh->prepare(<<END);
+ SELECT max(qty*price) FROM buy WHERE stallid=?
+ END
+       foreach my $stallid (sort { $a <=> $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";
+ }
  $cplex.= "
  Bounds
          ".(join "
@@@ -515,7 -536,7 +539,7 @@@ if ($qa->{'debug'}) 
        my $input= pipethrough_prep();
        print $input $cplex or die $!;
        my $output= pipethrough_run_along($input, undef, 'glpsol',
-               qw(glpsol --tmlim 2 --memlim 5 --intopt --cuts --bfs
+               qw(glpsol --tmlim 5 --memlim 5 --intopt --cuts --bfs
                          --cpxlp /dev/stdin -o /dev/stdout));
        print "<pre>\n" if $qa->{'debug'};
        my $found_section= 0;
@@@ -638,18 -659,14 +662,18 @@@ Generated by YARRG at <strong><
  %
  % foreach my $i (0..$#islandids) {
  <% $tbody->(1) %>
 -<tr><td colspan=4>
 +<tr>
  %     $iquery->execute($islandids[$i]);
  %     my ($islandname) = $iquery->fetchrow_array();
  %     if (!$i) {
 +<td colspan=2>
  <strong>Start at <% $islandname |h %></strong>
 +<td colspan=2><a href="docs#posinclass">[what are these codes?]</a>
 +<td>
  %     } else {
  %             my $this_dist= $distance->($islandids[$i-1],$islandids[$i]);
  %             $total_dist += $this_dist;
 +<td colspan=5>
  <%perl>
                my $total_value= 0;
                foreach my $sf (@subflows) {
  <%perl>
       my $age_reported= 0;
       my %flowlists;
 -     #print "<tr><td colspan=6>" if $qa->{'debug'};
 +     #print "<tr><td colspan=7>" if $qa->{'debug'};
       foreach my $od (qw(org dst)) {
        #print " [[ i $i od $od " if $qa->{'debug'};
        foreach my $sf (@subflows) {
                my $price= $f->{"${od}_price"};
                my $stallname= $f->{"${od}_stallname"};
                my $todo= \$flowlists{$od}{
 +                              (sprintf "%010d", $f->{'ordval'}),
                                $f->{'commodname'},
                                (sprintf "%07d", ($od eq 'dst' ?
                                                9999999-$price : $price)),
                        dstArbitrage => 0,
                } unless $$todo;
                $$todo->{'commodname'}= $f->{'commodname'};
 +              $$todo->{'posinclass'}= '';
 +              my $incl= $f->{'posinclass'};
 +
 +              my $findclass= $dbh->prepare(<<END);
 +SELECT commodclass, maxposinclass FROM commodclasses WHERE commodclassid = ?
 +END
 +              $findclass->execute($f->{'commodclassid'});
 +              my $classinfo= $findclass->fetchrow_hashref();
 +              if ($classinfo) {
 +                      my $clname= $classinfo->{'commodclass'};
 +                      my $desc= encode_entities(sprintf "%s is under %s",
 +                                      $f->{'commodname'}, $clname);
 +                      my $abbrev= substr($clname,0,1);
 +                      if ($incl) {
 +                              my $maxpic= $classinfo->{'maxposinclass'};
 +                              $desc.= (sprintf ", commodity %d of %d",
 +                                      $incl, $maxpic);
 +                              if ($classinfo->{'maxposinclass'} >= 8) {
 +                                      my @tmbs= qw(0 1 2 3 4 5 6 7 8 9);
 +                                      my $tmbi= ($incl+0.5)*$#tmbs/$maxpic;
 +                                      $abbrev.= " ".$tmbs[$tmbi]."&nbsp;";
 +                              }
 +                      }
 +                      $$todo->{'posinclass'}=
 +                              "<div class=mouseover title=\"$desc\">"
 +                              .$abbrev."</div>";
 +              }
                $$todo->{'stallname'}= $stallname;
                $$todo->{Price}= $price;
                $$todo->{Timestamp}= $f->{"${od}_timestamp"};
  </%perl>
  <tr>
  <td colspan=1>
 -<td colspan=2><% $xinfo %>
 +<td colspan=3><% $xinfo %>
  <td colspan=2 align=right><% $totaldesc %>
  <td align=right><% $totalwas |h %> total
  <%perl>
  % tr_datarow($m,$dline);
  <<% $td %>><% $collectdeliver %>
  <<% $td %>><% $t->{'commodname'} |h %>
 +<<% $td %>><% $t->{'posinclass'} %>
  %
  %             my @stalls= sort keys %{ $t->{Stalls} };
  %             my $pstall= sub {
  }
  </%perl><a name="summary"></a>
  <% $tbody->(1) %><tr>
 -<td colspan=2>Total distance: <% $total_dist %> leagues.
 +<td colspan=3>Total distance: <% $total_dist %> leagues.
  <td colspan=3 align=right>Overall net cash flow
  <td align=right><strong><%
    $total_total < 0 ? -$total_total." loss" : $total_total." gain"