F1: economia headless, dati validati, generatore di mappa e salvataggi

- Base deterministica: Money, id tipizzati, DMath, XxHash64, calendario
- 12 file dati con schemi, validatore di schema interno, validazione semantica
  e hash dei dati; viaferrea-tools validate-data
- Generatore di mappa (rilievo, mare, priority-flood, fiumi, laghi, copertura,
  giacimenti, città, hub, industrie) e viaferrea-tools genmap
- Economia: città, industrie, hub, mercato con componente mondiale, prezzi
  locali, tariffe, lavoro in sede e a piedi, trasporto locale, registro a
  partita doppia, prestiti, rating, difficoltà
- Salvataggi Brotli con rimappatura per id e hash di stato giornaliero
- viaferrea-tools simulate con KPI CSV; 45 test verdi; ADR 0002-0006

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0191R7vXgtbAvSV4V8tj8uzL
This commit is contained in:
Claude committed 2026-10-01 22:38:17 +00:00
1 parent 290a1d886c
commit 7cb98fa206
113 files changed
+12553 -23

No files matched your search

@@ -0,0 +1,62 @@
using ViaFerrea.Core.Common;
using ViaFerrea.Core.Economy;
namespace ViaFerrea.Core.Simulation.Systems;
/// <summary>
/// Domanda giornaliera: consumo desiderato delle città (con elasticità al prezzo) e input
/// richiesti dalle industrie al loro potenziale di lavoro. Alimenta D del mercato.
/// </summary>
public sealed class DemandSystem : ISimSystem
{
public string Name => "Demand";
public void Step(WorldContext ctx)
{
if (!ctx.IsNewDay) return;
var w = ctx.World;
var data = w.Data;
var market = w.Market;
int year = ctx.Year;
foreach (var town in w.Towns)
{
for (int g = 0; g < data.GoodCount; g++)
{
double d = TownDemand(w, town, g, year);
town.DemandToday[g] = d;
market.DemandToday[g] += d;
}
}
int dpm = w.Calendar.DaysPerMonth;
foreach (var ind in w.Industries)
{
if (ind.Closed || ind.Level <= 0)
{
Array.Clear(ind.InputDemandToday);
continue;
}
double eLabor = Math.Min(ind.CovWorkers, ind.CovStaff) * IndustryMath.ProfitFactor(ind, data.Balance.Industry)
* IndustryMath.ConditionMultiplier(ind.Condition, data.Balance.IndustryMaintenance);
double cycles = ind.CyclesPerDayAtFullCapacity(dpm) * eLabor;
var inputs = ind.Def.Recipe.Inputs;
for (int i = 0; i < inputs.Count; i++)
{
double need = cycles * inputs[i].PerCycle;
ind.InputDemandToday[i] = need;
market.DemandToday[inputs[i].GoodIndex] += need;
}
}
}
/// <summary>Domanda giornaliera di una città per un bene, in unità.</summary>
public static double TownDemand(World w, Town town, int good, int year)
{
var def = w.Data.Goods[good];
if (def.Town is not { } td || def.Era > year || (td.UntilYear is { } until && year >= until)) return 0;
double ratio = w.Market.GlobalPrice[good] / def.BasePrice;
double priceFactor = DMath.Clamp(DMath.Pow(ratio, -def.Elasticity), 0.5, 1.5);
return town.Population / 1000.0 * td.DemandPerThousand * priceFactor;
}
}