feat(forlop): time course and stability check from own numbers

New script paper/forlop.py reads the same input file as diagnose.py.
It checks whether the steering tolerates its own delay, places the
binding link in the model as the link with a queue, calibrates the size
and start of the increase so that the coordinated rule's first budget
decision sees the numbers in the file, and runs simulate_endo month by
month with and without measures. It also reports what the measure does
to the rest of the chain: police effort, the share diverted, and whether
the bottleneck moves to the links after it.

The example file reproduces section 9.5 and table 10: +19 % now, +12 %
after 12 months, capacity 1,31; 8,3 / 0,74 / 1,10 / 3,5 with measures and
68,7 / 0,65 / 1,26 without. The stability block reproduces section 9.3
with delay 11 and reactivity 3. The script declines to print a time
course when the steering is unstable, when the forecast has not settled
within the horizon, or when the model cannot build the backlog in the
file before the first decision.

sim.py is imported unchanged; paper/data is untouched. diagnose.py gives
identical output for both input files; the bottleneck selection is now a
function so forlop.py can reuse it, and true/false are rejected where a
number is expected. Reviewed by an independent agent; its 14 findings
are addressed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-10 16:20:31 +01:00
commit 01d335e941
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
6 changed files with 468 additions and 15 deletions

View file

@ -11,13 +11,14 @@ Concept note (Norwegian, LaTeX) and its simulation code. The principle: enforcem
## Conventions
- The core sentence must be quoted verbatim everywhere: «Innsatsen for å håndheve lover og regler bør løpende stå i forhold til hvor mye, og hvor alvorlig, de faktisk brytes.» Short form of the clarification: «Straffebud og strafferammer ligger fast.»
- Any change to `sim.py` must keep `paper/data/` byte-identical unless the change is meant to alter results; then text, figures and PDFs change in the same commit.
- Licensing is split: text (`pdf/`, `paper/*.tex`, `README.md`, `CHANGELOG.md`, `CLAUDE.md`) is CC BY 4.0 (`LICENSE-CC-BY-4.0.txt`); code and data (`paper/sim.py`, `paper/diagnose.py`, `paper/eksempel_domstol.json`, `paper/norge_2025.json`, `requirements.txt`, `paper/data/`) are MIT (`LICENSE`). New files follow the same split.
- Never commit anything under `private/` (working documents: peer review, change list, social-media drafts, original source zip).
- Licensing is split: text (`pdf/`, `paper/*.tex`, `README.md`, `CHANGELOG.md`, `CLAUDE.md`) is CC BY 4.0 (`LICENSE-CC-BY-4.0.txt`); code and data (`paper/sim.py`, `paper/diagnose.py`, `paper/forlop.py`, `paper/eksempel_domstol.json`, `paper/norge_2025.json`, `requirements.txt`, `paper/data/`) are MIT (`LICENSE`). New files follow the same split.
- Never commit working documents; `private/` is ignored for that purpose.
## Commands
- Setup: `python3 -m venv .venv && .venv/bin/pip install -r requirements.txt`
- Run simulation (about 2 min, from `paper/`): `../.venv/bin/python sim.py`
- Bottleneck diagnosis from own numbers (stdlib only, from `paper/`): `python3 diagnose.py eksempel_domstol.json`; must reproduce section 9.5 (utilization 1,28, +19 % capacity). `python3 diagnose.py norge_2025.json` must match the table in README (1,09 / 1,04 / 0,88 / 1,09).
- Time course and stability check from own numbers (needs the venv, from `paper/`): `../.venv/bin/python forlop.py eksempel_domstol.json`; must reproduce section 9.5 and table 10 (critical delay 7,2; +19 % now, +12 % after 12 months, capacity 137,9 = 1,31; with measures 8,3 / 0,74 / 1,10 / +31 % / 3,5; without 68,7 / 0,65 / 1,26). `forlop.py` imports `sim.py` and must never require a change there.
- Reproduction check after a run: `git status paper/data` shows no changes (verified 2026-11-10: 22/22 files identical with Python 3.14.0, numpy 2.5.4, scipy 1.18.1)
- LaTeX build (from `paper/`, TeX Live 2026 in `/Library/TeX/texbin`): `pdflatex main.tex` and `pdflatex notat.tex` three times each, `xelatex karusell.tex` twice; copy to `pdf/` (verified 2026-11-10: main 58 pages, notat 2, karusell 16, no undefined references). Build in a scratch copy of `paper/` to keep aux files out of the repo, and give each run a time limit: one pdflatex run has been seen to hang.