# dispatch

Optional storage dispatch plan: a rolling-horizon LP over the bus tags that drives every storage level marked optimal at the cheapest grid cost. Absent by default.

OPTIONAL storage dispatch plan: a rolling-horizon LP over the bus that sets every `levels[].storage` with optimal true at the cheapest cost of the `flows[].grid` flows, replanned from the measured state. Absent, nothing of it runs.

In the model file this key holds an object.

## Typical uses

These sections turn a model into a business case. `fixed_costs` are costs of the scenario rather than of the run, such as equipment capex. `investment` defines the case that `naga invest` reports: payback, NPV and return on investment against a baseline scenario. `dispatch` plans storage over a rolling horizon at the lowest grid cost.

## Behaviour and rules

Running costs are not set here. They come from the cost fields of resources, fleets, entity types, flows and RECORD blocks. A fixed cost flagged `capex` is the investment that the saving has to repay. The `investment` section needs a scenario to compare with, and a check warns when only one scenario exists.

The case scales the observed window to `operating_hours_per_year`. The saving over the baseline is counted for `horizon_years` and discounted at `discount_rate`. A `margin_per_part` adds the value of extra good parts to the saving. A value of 0 makes it a pure cost case.

The `dispatch` plan drives only the levels marked as storage. It prices grid flows with their own `price`. Without a `dispatch` section, those storage and grid settings do nothing. Both sections are absent by default.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string |  | `"site"` |  | The dispatch_summary row and KPI key part. |
| `supply_tags` | list of string | yes |  |  | Bus tags forecast as supply, e.g. ["generation", "dispatchable"]. |
| `demand_tags` | list of string | yes |  |  | Bus tags forecast as demand, e.g. ["demand"]. |
| `horizon` | number |  | `24.0` | time (`time_unit`) | How far each plan looks ahead; clipped at the run's end. |
| `step` | number |  | `0.25` | time (`time_unit`) | The plan's grid: setpoints are constant per step. |
| `replan_every` | number |  | `1.0` | time (`time_unit`) | How often the plan is solved again from the measured state; a multiple of step. |
| `time_unit` | choice |  | `"hours"` |  | Unit of horizon, step and replan_every. One of `base`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `weeks`, `months`, `years`. |
| `terminal` | choice |  | `"hold"` |  | hold: each plan ends with every storage at least at its starting level; free: it may end empty. One of `hold`, `free`. |
| `forecast` | choice |  | `"model"` |  | model: the rates and prices evaluated ahead (perfect foresight of the profiles); persistence: their values at the replan instant, held over the horizon. One of `model`, `persistence`. |
| `voll` | number |  |  | money | Cost per unit of unserved demand in the plan; default 100 x the dearest import price. |
| `status_variable` | string |  | `"dispatch_ok"` |  | A declared variable the plan sets to 1 while it holds and to 0 when a solve fails. |

A field of a nested object is described in the JSON Schema (`naga schema`).

## Example

The fragment refers to entries that are defined elsewhere in the same file:

```json
{"variables": [{"name": "dispatch_ok", "initial": 1}, {"name": "battery_kw", "initial": 0}], "levels": [{"name": "Battery", "capacity": 10, "initial": 0, "storage": {"optimal": true, "setpoint": "battery_kw", "charge_max": 5, "discharge_max": 5}}]}
```

The fragment:

```json
{"dispatch": {"supply_tags": ["generation"], "demand_tags": ["demand"], "horizon": 24}}
```

In the Python builder the section is a keyword of `Model`:

```python
from nagasim import build as nb
m = nb.Model(dispatch={'supply_tags': ['generation'], 'demand_tags': ['demand'], 'horizon': 24})
```

## Used in

Guides: [Continuous quantities: levels, flows and time-series inputs](../../modelling-guide/continuous-quantities.md), [Layout, paths and vehicles](../../modelling-guide/layout-paths-vehicles.md).

## See also

- [All sections](index.md), [Model file keys](../schema.md), [Model file format](../../model-file-format.md)
