Drain: the sortie hold is the median of what a seed's sorties mined, not of the full-hold ones

Seeds 2, 3, 69 and 97 stop on a starting stock long before a hold fills, so only seed 1 had a measured sortie.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-11-28 14:33:07 +01:00
commit c874d60a66
3 changed files with 8 additions and 5 deletions

View file

@ -79,6 +79,7 @@ public sealed class EconomyDrainTests
Assert.Equal(Stall.Inputs, roomy.Facilities.Single().HorizonEnd);
Assert.DoesNotContain(EconomyDrain.Report(new[] { made }), f => f.Invariant == EconomyDrain.HStall);
}
[Fact] public void TheSortieHoldIsTheMedianOfWhatSortiesMined() { LoopSample Mined(int units) => new LoopSample { Units = units, Outcome = LoopOutcome.AmmoOut }; Assert.Equal(15, EconomyDrain.SortieUnits(69, new[] { Mined(6), Mined(18), Mined(2), Mined(15), Mined(0) })); Assert.Equal(8, EconomyDrain.SortieUnits(3, new[] { Mined(25), Mined(8), Mined(3) })); Assert.Throws<InvalidOperationException>(() => EconomyDrain.SortieUnits(2, new[] { Mined(0) })); }
[Fact] public void DrainRefusesLoopAndStrayOptions() { foreach (var args in new[] { new[] { "balance", "--drain", "--loop" }, new[] { "balance", "--loop", "1", "--window", "5" }, new[] { "balance", "--drain", "--cap", "5" }, new[] { "balance", "--drain", "--horizon", "0" }, new[] { "balance", "--drain", "--window" } }) { var output = new StringWriter(); Assert.Equal(1, EconomyCommand.Run(args, output)); Assert.Contains("balance --drain [<seed>...]", output.ToString()); } }
[Fact]

View file

@ -129,7 +129,7 @@ public static class EconomyCommand
loop = EconomyLoop.Report(db.Cache, settings, seedList.SelectMany(seed => EconomyLoop.Sorties(db.Root, seed, (float) cap)).ToList());
List<DrainSample> drain = null;
if (drainAt >= 0)
drain = seedList.Select(seed => EconomyDrain.Run(db.Root, seed, window, horizon, EconomyDrain.SortieUnits(EconomyLoop.Sorties(db.Root, seed, EconomyLoop.DefaultCap)))).ToList();
drain = seedList.Select(seed => EconomyDrain.Run(db.Root, seed, window, horizon, EconomyDrain.SortieUnits(seed, EconomyLoop.Sorties(db.Root, seed, EconomyLoop.DefaultCap)))).ToList();
return Balance(db.Cache, settings.EconomyWageSpread, output, loop, drain);
}
if (args.Length > 0 && args[0] == "author")

View file

@ -93,11 +93,13 @@ public static class EconomyDrain
public const double Span = 60;
private const int MaxSorties = 500;
// The seed's median sortie hold, in units: the median over the sorties that mined to a full hold or the cap.
public static int SortieUnits(IReadOnlyList<LoopSample> samples)
// The seed's median sortie hold, in units: the middle of the holds of the sorties that mined something (the upper one of an
// even count), whatever stopped them. Most seeds' sorties stop on a starting stock long before the hold fills.
public static int SortieUnits(uint seed, IReadOnlyList<LoopSample> samples)
{
var units = samples.Where(s => s.Measured).Select(s => s.Units).OrderBy(u => u).ToList();
return units.Count == 0 ? 0 : units[units.Count / 2];
var units = samples.Where(s => s.Units > 0).Select(s => s.Units).OrderBy(u => u).ToList();
if (units.Count == 0) throw new InvalidOperationException($"seed {seed}: no sortie mined anything, so there is no hold to sell");
return units[units.Count / 2];
}
// beforeFill sees the booted arena before any sale (a test empties a bay there); beforeWindow sees it after the fill and before