Region harness: rigs and skimmers are facilities with recipes, and the ground decides what stalls them
An extractor is a facility whose run list is all raw; it ran when it started a cycle (FacilityRun.Cycles), so the region line reads extraction running. A raw recipe the ground under a rig holds none of reads Barren whatever else the rig reads (Room, once its bays fill), and a recipe every facility of which ended Barren is the placement's (extraction-aware-placement), shown in the table and no fault of the chain. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6004fbc8d8
commit
a4f4f299ed
2 changed files with 90 additions and 20 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Caching;
|
||||
|
|
@ -83,31 +84,51 @@ public sealed class EconomyRegionTests
|
|||
var ranFed = fed.Recipes.Where(recipe => recipe.Ran).Select(recipe => recipe.Output).ToList();
|
||||
Assert.NotEmpty(ranFed.Except(baseline.Recipes.Where(recipe => recipe.Ran).Select(recipe => recipe.Output)));
|
||||
var idle = EconomyRegion.Report(new[] { fed }).Where(fault => fault.Invariant == EconomyRegion.HIdle).Select(fault => fault.Record).OrderBy(record => record, StringComparer.Ordinal).ToArray();
|
||||
Assert.Equal(fed.Recipes.Where(recipe => !recipe.Ran).Select(recipe => $"seed 1 {recipe.Output}").OrderBy(record => record, StringComparer.Ordinal), idle);
|
||||
Assert.Equal(fed.Recipes.Where(recipe => !recipe.Ran && !recipe.Final.Keys.All(stall => stall == Stall.Barren)).Select(recipe => $"seed 1 {recipe.Output}").OrderBy(record => record, StringComparer.Ordinal), idle);
|
||||
Assert.All(ranFed, output => Assert.DoesNotContain($"seed 1 {output}", idle));
|
||||
}
|
||||
|
||||
|
||||
// With no extraction running, an idle recipe's cause is upstream, and no line blames cargo movement for it.
|
||||
// The rigs and skimmers of the region are facilities with recipes of their own: with the ground worked, an idle refinery's cause is the
|
||||
// ore that no haul leg brings it, and the report says extraction runs.
|
||||
[Fact]
|
||||
public void IdleCauseIsNamedAndUpstreamWhenNothingIsExtracted()
|
||||
public void ExtractionRunsAndTheIdleCauseIsTheHaulLeg()
|
||||
{
|
||||
var sample = EconomyRegion.Run(Root, 1, 0.05);
|
||||
Assert.True(sample.Extractors > 0);
|
||||
Assert.True(sample.NoExtraction, "an extraction facility ran: the premise of this test is gone");
|
||||
Assert.True(sample.ExtractorsRunning > 0, "no rig or skimmer started a cycle");
|
||||
Assert.False(sample.NoExtraction);
|
||||
var idle = EconomyRegion.Report(new[] { sample }).Where(fault => fault.Invariant == EconomyRegion.HIdle).Select(fault => fault.Message).ToList();
|
||||
Assert.NotEmpty(idle);
|
||||
// A recipe that draws raw ore says so; one that draws an intermediate names the idle recipe above it instead.
|
||||
Assert.Contains(idle, message => message.Contains("no extraction runs"));
|
||||
Assert.Contains(idle, message => message.Contains("whose recipe is itself idle"));
|
||||
Assert.All(idle, message => Assert.Contains("missing ", message));
|
||||
Assert.Contains(idle, message => message.Contains("whose recipe ran but whose units are not held where this one is made: no haul leg"));
|
||||
Assert.All(idle, message => Assert.DoesNotContain("no extraction runs", message));
|
||||
Assert.All(idle, message => Assert.DoesNotContain("moves no cargo", message));
|
||||
var text = new StringWriter();
|
||||
EconomyRegion.Print(sample, text);
|
||||
Assert.Contains("no extraction runs in the region: every downstream recipe starves", text.ToString());
|
||||
Assert.Contains($"extraction runs in {sample.ExtractorsRunning} of {sample.Extractors} extraction facilities", text.ToString());
|
||||
Assert.DoesNotContain("no extraction runs in the region", text.ToString());
|
||||
Assert.Contains("at least", text.ToString());
|
||||
}
|
||||
|
||||
// With every extraction facility switched off, the report names it, and the idle cause is the idle extraction above.
|
||||
[Fact]
|
||||
public void NoExtractionIsNamedWhenNoRigStarts()
|
||||
{
|
||||
var sample = EconomyRegion.Run(Root, 1, 0.05, beforeRun: demo =>
|
||||
{
|
||||
foreach (var unit in demo.Galaxy.Zones.SelectMany(zone => zone.Contents.Entities).SelectMany(entity => entity.Equipment).ToList())
|
||||
if (unit.Behaviors.OfType<Facility>().Any() && Production.RunList(demo.Cache, unit.EquippableItem.Data.Key).All(recipe => Recipes.IsRaw(demo.Cache, recipe)))
|
||||
unit.Enabled.Value = false;
|
||||
});
|
||||
Assert.True(sample.Extractors > 0);
|
||||
Assert.True(sample.NoExtraction);
|
||||
var idle = EconomyRegion.Report(new[] { sample }).Where(fault => fault.Invariant == EconomyRegion.HIdle).Select(fault => fault.Message).ToList();
|
||||
Assert.Contains(idle, message => message.Contains("whose recipe is itself idle"));
|
||||
var text = new StringWriter();
|
||||
EconomyRegion.Print(sample, text);
|
||||
Assert.Contains("no extraction runs in the region: every downstream recipe starves", text.ToString());
|
||||
}
|
||||
|
||||
// Cause branches on hand-built samples, each the true cause of its own: the booted region has only one of them today.
|
||||
private static RegionRecipe Recipe(string output, Stall final, double cycle = 60, params string[] missing)
|
||||
{
|
||||
|
|
@ -145,6 +166,40 @@ public sealed class EconomyRegionTests
|
|||
Assert.DoesNotContain("no extraction runs", message);
|
||||
}
|
||||
|
||||
// A rig stalls as a whole, but a raw recipe the ground under it holds none of is Barren whatever the rig reads (Room once its bays fill):
|
||||
// an ore no belt of the region holds is no fault of the chain.
|
||||
[Fact]
|
||||
public void ARigRecipeTheGroundLacksIsBarrenWhateverTheRigReads()
|
||||
{
|
||||
var lackedEverywhere = new List<CultRecordKey>();
|
||||
var sample = EconomyRegion.Run(Root, 1, Hours, atEnd: demo =>
|
||||
{
|
||||
var holds = demo.Galaxy.Zones.SelectMany(zone => zone.Contents.Entities.OfType<OrbitalEntity>()).Select(station => new EntityHold(station)).ToList();
|
||||
lackedEverywhere.AddRange(demo.Cache.GetAll<FieldKindData>().SelectMany(kind => kind.Yields).Select(yield => yield.Commodity.Key).Distinct()
|
||||
.Where(ore => holds.All(hold => !(hold.Deposit(ore) > 0f))));
|
||||
});
|
||||
var lacking = sample.Recipes.Where(recipe => lackedEverywhere.Contains(recipe.OutputKey)).ToList();
|
||||
Assert.NotEmpty(lacking);
|
||||
// The premise: by the horizon the rigs' bays have filled, so the rigs themselves read Room.
|
||||
Assert.Contains(sample.Recipes, recipe => recipe.Final.ContainsKey(Stall.Room));
|
||||
Assert.All(lacking, recipe => Assert.Equal(new[] { Stall.Barren }, recipe.Final.Keys));
|
||||
var faulted = EconomyRegion.Report(new[] { sample }).Select(fault => fault.Record).ToHashSet();
|
||||
Assert.All(lacking, recipe => Assert.DoesNotContain($"seed 1 {recipe.Output}", faulted));
|
||||
}
|
||||
|
||||
// A recipe on ground that holds none of its good is the placement's to fix (extraction-aware-placement), shown in the table and not
|
||||
// a fault of the chain; one that is Barren in some facilities and stalled in others still is.
|
||||
[Fact]
|
||||
public void ARecipeOnlyBarrenIsNotAFault()
|
||||
{
|
||||
var barren = Recipe("Gold Ore", Stall.Barren);
|
||||
var sample = Sample(0, barren, Recipe("Silver Ore", Stall.Inputs, 60, "Slag"));
|
||||
Assert.Empty(EconomyRegion.Report(new[] { sample }).Where(fault => fault.Record == "seed 7 Gold Ore"));
|
||||
Assert.Single(EconomyRegion.Report(new[] { sample }), fault => fault.Record == "seed 7 Silver Ore");
|
||||
barren.Final[Stall.Inputs] = 1;
|
||||
Assert.Contains("the ground it sits on holds none of its good", Message(sample, "Gold Ore"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ARecipeWhoseHoldIsFullIsNotBlamedOnItsInputs()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ public sealed class RegionFacility
|
|||
public SortedDictionary<Stall, int> Stalls = new SortedDictionary<Stall, int>();
|
||||
// The recipe outputs of this facility's run list (good names).
|
||||
public List<string> Outputs = new List<string>();
|
||||
// Whether every recipe of its run list is raw: a rig or a skimmer, which takes from the ground.
|
||||
public bool Extractor;
|
||||
}
|
||||
|
||||
public sealed class RegionStation
|
||||
|
|
@ -56,6 +58,7 @@ public sealed class RegionRecipe
|
|||
// The goods a cycle draws, and whether any station holding a facility of the recipe holds some of each when the horizon ends.
|
||||
public SortedDictionary<string, bool> Draws = new SortedDictionary<string, bool>(StringComparer.Ordinal);
|
||||
internal readonly Dictionary<string, CultRecordKey> DrawKeys = new Dictionary<string, CultRecordKey>(StringComparer.Ordinal);
|
||||
internal CultRecordKey OutputKey;
|
||||
public SortedDictionary<Stall, int> Final = new SortedDictionary<Stall, int>();
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +71,8 @@ public sealed class RegionSample
|
|||
public List<RegionKind> Kinds = new List<RegionKind>();
|
||||
public List<RegionStation> Stations = new List<RegionStation>();
|
||||
public List<RegionRecipe> Recipes = new List<RegionRecipe>();
|
||||
// Facilities whose run list is empty (extraction rigs and skimmers: extraction recipes do not run yet, follow-up facility-extraction)
|
||||
// and how many of those did anything: nothing enters the region from the ground unless some did.
|
||||
// Facilities whose run list is all raw recipes (extraction rigs and skimmers) and how many of those started a cycle (FacilityRun.Cycles):
|
||||
// nothing enters the region from the ground unless some did.
|
||||
public int Extractors, ExtractorsRunning;
|
||||
public bool NoExtraction => Extractors > 0 && ExtractorsRunning == 0;
|
||||
// Per faction holding a non-entrance station: the kinds it fields (StationKinds.FieldableKindsOf) that no such station of it is.
|
||||
|
|
@ -111,11 +114,15 @@ public static class EconomyRegion
|
|||
foreach (var (unit, _) in facilities)
|
||||
{
|
||||
var run = Production.RunList(catalog, unit.EquippableItem.Data.Key);
|
||||
station.Facilities.Add(new RegionFacility { Name = demo.Items.GetData(unit.EquippableItem).Name, Outputs = run.Select(recipe => Good(recipe.Output.Key)).ToList() });
|
||||
station.Facilities.Add(new RegionFacility
|
||||
{
|
||||
Name = demo.Items.GetData(unit.EquippableItem).Name, Outputs = run.Select(recipe => Good(recipe.Output.Key)).ToList(),
|
||||
Extractor = run.Count > 0 && run.All(recipe => Recipes.IsRaw(catalog, recipe))
|
||||
});
|
||||
foreach (var recipe in run)
|
||||
{
|
||||
var entry = sample.Recipes.FirstOrDefault(r => r.Output == Good(recipe.Output.Key));
|
||||
if (entry == null) sample.Recipes.Add(entry = new RegionRecipe { Output = Good(recipe.Output.Key) });
|
||||
if (entry == null) sample.Recipes.Add(entry = new RegionRecipe { Output = Good(recipe.Output.Key), OutputKey = recipe.Output.Key });
|
||||
entry.Stations++;
|
||||
entry.Cycle = recipe.Cycle;
|
||||
foreach (var draw in Production.Draws(catalog, recipe)) { entry.Draws[Good(draw)] = false; entry.DrawKeys[Good(draw)] = draw; }
|
||||
|
|
@ -169,14 +176,19 @@ public static class EconomyRegion
|
|||
{
|
||||
var (unit, facility) = tracked[s].facilities[f];
|
||||
var outputs = tracked[s].station.Facilities[f].Outputs;
|
||||
if (outputs.Count == 0)
|
||||
if (tracked[s].station.Facilities[f].Extractor)
|
||||
{
|
||||
sample.Extractors++;
|
||||
if (facility.Stall != Stall.Unrunnable || (unit.EquippableItem.Run?.Progress ?? 0) > 0) sample.ExtractorsRunning++;
|
||||
continue;
|
||||
if ((unit.EquippableItem.Run?.Cycles ?? 0) > 0) sample.ExtractorsRunning++;
|
||||
}
|
||||
// A rig or skimmer stalls as a whole, but a raw recipe the ground under it holds none of is Barren whatever else the facility
|
||||
// read (EntityHold.Deposit, the rule Advance picks by).
|
||||
var ground = new EntityHold(tracked[s].entity);
|
||||
foreach (var recipe in sample.Recipes.Where(r => outputs.Contains(r.Output)))
|
||||
recipe.Final[facility.Stall] = recipe.Final.TryGetValue(facility.Stall, out var n) ? n + 1 : 1;
|
||||
{
|
||||
var stall = tracked[s].station.Facilities[f].Extractor && !(ground.Deposit(recipe.OutputKey) > 0f) ? Stall.Barren : facility.Stall;
|
||||
recipe.Final[stall] = recipe.Final.TryGetValue(stall, out var n) ? n + 1 : 1;
|
||||
}
|
||||
}
|
||||
for (var s = 0; s < tracked.Count; s++)
|
||||
for (var o = 0; o < tracked[s].outputs.Length; o++)
|
||||
|
|
@ -222,7 +234,9 @@ public static class EconomyRegion
|
|||
var faults = new List<EconomyFault>();
|
||||
foreach (var sample in samples)
|
||||
{
|
||||
foreach (var recipe in sample.Recipes.Where(r => !r.Ran))
|
||||
// A recipe whose every facility ended Barren sits on ground that holds none of its good: extraction-aware-placement's to
|
||||
// fix, shown in the table and not a fault of the chain.
|
||||
foreach (var recipe in sample.Recipes.Where(r => !r.Ran && !(r.Final.Count > 0 && r.Final.Keys.All(stall => stall == Stall.Barren))))
|
||||
faults.Add(new EconomyFault(HIdle, $"seed {sample.Seed} {recipe.Output}", $"{recipe.Output} is a recipe of {recipe.Stations} facilities the region holds and no cycle of it ran in {sample.Hours:0.##} sim h: {Cause(sample, recipe)}"));
|
||||
foreach (var (faction, kind) in sample.MissingLinks)
|
||||
faults.Add(new EconomyFault(HMissingLink, $"seed {sample.Seed} {faction}", $"{faction} fields {kind}, and no station of it outside the entrance zone is one: the chain has no such link."));
|
||||
|
|
@ -236,6 +250,7 @@ public static class EconomyRegion
|
|||
{
|
||||
var ends = recipe.Final.Count == 0 ? "no facility Stall was read" : "its facilities ended " + string.Join(", ", recipe.Final.Select(kv => $"{kv.Key} x{kv.Value}"));
|
||||
if (recipe.Final.ContainsKey(Stall.Room) && !recipe.Final.ContainsKey(Stall.Inputs)) return ends + ": the hold has no room for its output.";
|
||||
if (recipe.Final.ContainsKey(Stall.Barren)) return ends + ": the ground it sits on holds none of its good.";
|
||||
var missing = recipe.Draws.Where(draw => !draw.Value).Select(draw => draw.Key).ToList();
|
||||
if (missing.Count == 0) return ends + ": it holds some of every input, but not a cycle's quantity of one.";
|
||||
return ends + ": missing " + string.Join("; ", missing.Select(good => Upstream(sample, good))) + ".";
|
||||
|
|
@ -247,7 +262,7 @@ public static class EconomyRegion
|
|||
var maker = sample.Recipes.FirstOrDefault(recipe => recipe.Output == good);
|
||||
if (maker == null)
|
||||
return sample.NoExtraction
|
||||
? $"{good}, which no recipe in the region makes and no extraction runs to supply (extraction recipes do not run yet, follow-up facility-extraction)"
|
||||
? $"{good}, which no recipe in the region makes and no extraction runs to supply"
|
||||
: $"{good}, which no recipe in the region makes and no haul leg brings from outside (region-haul-legs)";
|
||||
return maker.Ran
|
||||
? $"{good}, whose recipe ran but whose units are not held where this one is made: no haul leg moves them (region-haul-legs)"
|
||||
|
|
@ -260,7 +275,7 @@ public static class EconomyRegion
|
|||
output.WriteLine(string.Format(inv, "\nRegion, seed {0} ({1} zones advanced to {2:0.##} sim h in {3} spans of {4:0} s by Zone.AdvanceTo; no zone steps, no player flies; hauler parked: {5})", sample.Seed, sample.Zones, sample.Hours, sample.Spans, RegionClock.Span, sample.Parked));
|
||||
output.WriteLine(" no cargo moves between stations in this view (region-haul-legs)");
|
||||
output.WriteLine(sample.NoExtraction
|
||||
? $" no extraction runs in the region: every downstream recipe starves ({sample.Extractors} extraction facilities, none running; extraction recipes do not run yet, follow-up facility-extraction)"
|
||||
? $" no extraction runs in the region: every downstream recipe starves ({sample.Extractors} extraction facilities, none running)"
|
||||
: $" extraction runs in {sample.ExtractorsRunning} of {sample.Extractors} extraction facilities");
|
||||
output.WriteLine(" stations outside the entrance zone by faction and kind (count | depth toward the gate, min to max)");
|
||||
foreach (var kind in sample.Kinds)
|
||||
|
|
|
|||
Loading…
Reference in a new issue