# Plan, inspect and share

Plan with a solver, find the loops that drive a system dynamics model, and share a model in a browser.

## naga plan

```text
usage: naga plan [-h] [--orders ORDERS]
                 [--propose {makespan,weighted_tardiness}]
                 [--time-limit TIME_LIMIT] [--risk N] [--workers WORKERS]
                 [--seed SEED] [--export EXPORT] [--report REPORT]
                 model

What is the plan, is there a better one, and how risky is it -- the
deterministic schedule, an optional CP-SAT proposal, and optional risk.

positional arguments:
  model                 path to the model JSON, or a bundled model's name
                        (naga examples)

options:
  -h, --help            show this help message and exit
  --orders ORDERS       CSV replacing the model's "orders" section
  --propose {makespan,weighted_tardiness}
                        propose a plan with CP-SAT instead of the as-is layout
                        (needs the optional 'ortools' package: pip install
                        "nagasim[plan]")
  --time-limit TIME_LIMIT
                        CP-SAT time limit in seconds (default: 10)
  --risk N              score the plan with N stochastic replications
  --workers WORKERS     risk replications run in parallel
  --seed SEED
  --export EXPORT       write the plan here: .csv or .json by extension
  --report REPORT       write an HTML report (Gantt + risk table) here
```

## naga loops

```text
usage: naga loops [-h] [--seed SEED] [--run-length RUN_LENGTH] [--limit LIMIT]
                  [--csv FILE]
                  model

Loop dominance (Loops That Matter) of an SD model: which feedback loop drives
the behaviour and when. Needs simulation.sd.

positional arguments:
  model                 path to the model JSON, or a bundled model's name
                        (naga examples)

options:
  -h, --help            show this help message and exit
  --seed SEED
  --run-length RUN_LENGTH
                        run length in base time units (default: the model's
                        own)
  --limit LIMIT         elementary circuits enumerated before the strongest-
                        path search takes over (default: 1000)
  --csv FILE            write the loop table to FILE and the per-step scores
                        to FILE's stem + '_dominance.csv'
```

## naga viewer

```text
usage: naga viewer [-h] [-o OUTPUT] [--title TITLE] [--runtime DIR]
                   [--pyodide {embedded,cdn}] [--fetch] [--freeze]
                   [--asked FILE] [--lang {en,it}] [--allow-network]
                   [--allow-private-network] [--allow-host HOST]
                   [--connections FILE]
                   [model]

Write one HTML file in which the engine runs in a browser and re-runs the
model with the inputs its dashboard definition exposes. The file holds the
whole model and the engine's source: whoever receives it can read both. For a
confidential model share a recording instead (`naga run MODEL --player
FILE.html`).

positional arguments:
  model                 the model file, or a bundled model's name (naga
                        examples)

options:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        the HTML file to write
  --title TITLE         the page's title (default: the model file's name)
  --runtime DIR         the folder of the browser runtime (default:
                        $NAGASIM_VIEWER_RUNTIME, else the user's own copy)
  --pyodide {embedded,cdn}
                        embedded (default): the file carries the browser
                        runtime and works offline (about 35 MB); cdn: a small
                        file that carries the engine and fetches Pyodide's
                        pinned files from cdn.jsdelivr.net when opened, each
                        checked against its SHA-256, refusing to start on a
                        mismatch or with no network
  --fetch               download the browser runtime (Pyodide 314.0.7, 29 MB,
                        from github.com and cdn.jsdelivr.net) into that
                        folder; nothing is downloaded without this flag
  --freeze              read the model's data sources once, now, and write the
                        values read into the copy as plain model data: the
                        file then names no source, path or address (without it
                        a model with data sources is refused)
  --asked FILE          recorded answers for the trust card: a study version's
                        asked.json, or a file of the editor's answers store;
                        its input-data and parameter rows quote them instead
                        of 'not measured'
  --lang {en,it}        the language of the page (default en)
  --allow-network       permit sql / json_url data sources (refused by
                        default: opening a model must not make outbound
                        connections on its own)
  --allow-private-network
                        also permit private/intranet addresses (refused even
                        with --allow-network)
  --allow-host HOST     restrict network sources to this hostname; may repeat
  --connections FILE    the connections a live source (rest, mqtt, opcua) may
                        name: a JSON file of yours, never the model's; without
                        it every live source is refused
```
