Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Repository files navigation

SFC-ABM Core Engine

Core Engine Tests

Stock-Flow Consistent Agent-Based Model engine for studying phase transitions in AI-driven labor market automation. Powers all five papers in the complexity-econ series (40,000+ Monte Carlo simulations).

What it does

Simulates 10,000 heterogeneous firms across 6 sectors (GUS 2024 calibration) interacting on a configurable network topology over 120 months. Firms decide whether to adopt AI, go hybrid, or stay traditional based on profitability thresholds, network mimetic pressure, and sector-specific CES elasticity of substitution (σ). A BDP (basic disposable payment) shock at month 30 triggers the automation transition.

Every monetary flow is tracked bilaterally: government taxes and spends, banks lend and absorb losses, the central bank sets rates via Taylor rule, and the exchange rate floats via balance-of-payments (PLN) or stays fixed under SGP fiscal constraint (EUR).

Architecture

src/main/scala/sfc/
├── Main.scala Entry point + Monte Carlo orchestrator
├── config/
│ └── SimConfig.scala 40+ parameters, 2 regimes, 4 topologies, env var overrides
├── agents/
│ ├── Firm.scala TechState (Traditional→Hybrid→Automated→Bankrupt), decision logic
│ ├── Household.scala Aggregate household state
│ └── CentralBank.scala NBP/ECB rate wrapper
├── engine/
│ ├── Simulation.scala Monthly step: labor → demand → firms → bank → inflation → forex → fiscal
│ └── World.scala Immutable world state (macro + per-sector σ vector)
├── dynamics/
│ ├── SigmaDynamics.scala Endogenous σ evolution (Arthur-style learning-by-doing)
│ └── DynamicNetwork.scala Death-birth rewiring with preferential attachment
├── networks/
│ └── WattsStrogatz.scala WS, Erdos-Renyi, Barabasi-Albert, ring lattice generators
└── sfc/
└── BalanceSheet.scala GovState, BankState, ForexState (SFC accounting)

Key features

Monetary regimes

  • PLN: Floating exchange rate, endogenous NBP Taylor rule (α=1.5, β=0.8, inertia=0.70)
  • EUR: Fixed rate at 4.33 PLN/EUR, exogenous ECB Taylor rule, SGP fiscal constraint (3% deficit, 60% debt ceiling, austerity κ=2.0)

Network topologies

  • Watts-Strogatz small-world (k=6, p=0.10) — default
  • Erdos-Renyi random graph
  • Barabasi-Albert scale-free (preferential attachment)
  • Ring lattice (no rewiring)

Firm decision logic

  • 4-state technology transition: Traditional → Hybrid → Automated (+ Bankrupt)
  • Profitability threshold via CES elasticity: θ = min(1.0, 0.88 + 0.075·log₁₀(σ))
  • Network mimetic pressure: 40% weight on neighbors' adoption + 40% global panic
  • Uncertainty discount reduced by demonstration effect (neighbors already automated)
  • Sector-specific digital readiness, failure rates, and hybrid worker retention

Endogenous dynamics (Paper-05)

  • σ evolution: σ(t+1) = σ(t) + λ·σ(t)·adoption(t)·(1 - σ(t)/cap) with ratchet + hard cap
  • Network rewiring: bankrupt firms replaced with probability ρ, new entrants wire via preferential attachment
  • Both disabled by default (λ=0, ρ=0) — backward compatible with Papers 01–04

Macroeconomic channels

  • Phillips curve inflation (demand-pull + cost-push + import + tech-deflation)
  • Soft deflation floor at -1.5%/mo (Bewley 1999 wage rigidity)
  • Banking sector with NPL tracking, CAR constraint, endogenous lending rates
  • Balance-of-payments forex with IRP arbitrage (PLN) or fixed rate (EUR)
  • Government fiscal balance with SGP constraints (EUR only)

Sectors (GUS 2024)

SectorShareσ (CES)Digital readinessHybrid retain
BPO/SSC3%50.00.5050%
Manufacturing16%10.00.4560%
Retail/Services45%5.00.4065%
Healthcare6%2.00.2575%
Public22%1.00.0890%
Agriculture8%3.00.1285%

Usage

Prerequisites

Run simulation

# BDP = 2000 PLN, 30 seeds, PLN regime
sbt "run 2000 30 baseline pln"# EUR regime with SGP
sbt "run 2000 30 baseline eur"# Fat JAR (faster, no sbt startup overhead)
sbt assembly
java -jar target/scala-3.5.2/sfc-abm.jar 2000 30 baseline pln

Environment variable overrides

# Network topology
TOPOLOGY=er java -jar sfc-abm.jar 2000 30 test pln # Erdos-Renyi
TOPOLOGY=ba java -jar sfc-abm.jar 2000 30 test pln # Barabasi-Albert
TOPOLOGY=lattice java -jar sfc-abm.jar 2000 30 test pln # Ring lattice# Custom σ per sector
SIGMAS="8.97,4.88,4.95,1.0,0.8,1.44" java -jar sfc-abm.jar 2000 30 test pln
# σ multiplier (all sectors)
SIGMA_MULT=2.0 java -jar sfc-abm.jar 2000 30 test pln
# System size
FIRMS_COUNT=1000 java -jar sfc-abm.jar 2000 30 test pln
# Decision rule tuning
DEMO_THRESH=0.25 java -jar sfc-abm.jar 2000 30 test pln
# Endogenous σ (Paper-05)
SIGMA_LAMBDA=0.02 java -jar sfc-abm.jar 2000 30 test pln
# Dynamic network (Paper-05)
REWIRE_RHO=0.1 java -jar sfc-abm.jar 2000 30 test pln
# Full endogenous (both mechanisms)
SIGMA_LAMBDA=0.02 REWIRE_RHO=0.1 java -jar sfc-abm.jar 2000 30 test pln

Output

CSV files written to mc/ (European format: semicolon separator, comma decimals):

  • mc/<prefix>_terminal.csv — per-seed terminal values at month 120 (26 columns)
  • mc/<prefix>_timeseries.csv — aggregated time series (mean, std, p05, p95)

26 output columns: Seed, Inflation, Unemployment, TotalAdoption, ExRate, MarketWage, GovDebt, NPL, RefRate, PriceLevel, AutoRatio, HybridRatio, 6× sector adoption, EffectiveBDP, 6× sector σ, MeanDegree

Tests

93 tests across 8 suites, run on every push via GitHub Actions:

sbt test
SuiteTestsCovers
FirmSpec14Tech states, worker counts, capacity, σ threshold
SimConfigSpec12Sector calibration, parameter bounds, regime detection
NetworkSpec10WS/ER/BA/lattice degree, symmetry, connectivity
BalanceSheetSpec10NPL ratio, CAR, lending rate, credit constraint
SimulationSpec12Labor market, inflation channels, Taylor rules
SigmaDynamicsSpec6Learning-by-doing, ratchet, cap, backward compat
DynamicNetworkSpec6Death-birth, preferential attachment, backward compat
IntegrationSpec23End-to-end: 120×26 output, reproducibility, bounds

Tech stack

  • Scala 3.5.2 / sbt
  • Zero runtime dependencies (stdlib only)
  • ScalaTest 3.2.19 for unit tests
  • sbt-assembly for fat JAR packaging

Papers using this engine

#PaperSimsDOI
1The Acceleration Paradox6,30010.5281/zenodo.18727928
2PLN vs EUR with SGP1,26010.5281/zenodo.18740933
3Empirical σ Estimation12010.5281/zenodo.18743780
4Phase Diagram & Universality18,54010.5281/zenodo.18751083
5Endogenous Technology & Networks10,08010.5281/zenodo.18758365

Citation

See CITATION.cff

License

MIT