# schedules

Piecewise-constant arrival-rate or capacity schedules, optionally repeating.

In the model file this key holds a list of `schedule` entries, each named by its `name`.

A scenario, an experiment or an optimizer can set a field by the path `schedules.<name>.<field>`. A data binding can write a field.

## Typical uses

These sections define what entities wait for and when it is available. `resources` are the machines, staff and spaces that SEIZE and PROCESS blocks request. `resource_sets` group resources so that a request takes any one of them. `schedules` give a resource a shift pattern or give a CREATE block a changing arrival rate. `failures` break resources down and repair them.

## Behaviour and rules

A resource has a `capacity` of units, a queue discipline and optional costs. The discipline is `FIFO` by default. The ranked disciplines `LowestValueFirst` and `HighestValueFirst` need a `ranking_expr`. With `rerank` on, the rank is re-evaluated before every grant.

A resource set is seized by its own name. The `rule` picks one member for each request. `PreferredOrder` tries the members in the listed order, and `Cyclical` takes turns. The member that was chosen is the one that is released later.

A schedule is a list of `[duration, value]` points. The value holds for the duration. With `repeat`, the pattern starts over, and without it the last value holds for ever. For a `capacity` schedule the value is a number of units. For an `arrival` schedule it is a rate per time unit. A weekly grid needs `simulation.calendar`.

A schedule or a failure never interrupts a job in service. The unit goes out of service when the job frees it. A resource is built at its full `capacity`, which must cover the highest value its schedule asks for. Each failure draws its own uptime and downtime for each resource it lists.

## Fields

| Field | Type | Required | Default | Unit | Description |
|---|---|---|---|---|---|
| `name` | string | yes |  |  | The schedule's name; a block or a resource names it to follow the calendar. |
| `description` | string |  |  |  | What the schedule stands for; the run does not read it. |
| `kind` | choice |  | `"arrival"` |  | "arrival" for a rate of arrivals, "capacity" for a number of units available. One of `arrival`, `capacity`. |
| `repeat` | boolean |  | `false` |  | Start over after the last point; when false the last value holds for ever. |
| `time_unit` | choice |  | `"base"` |  | Unit the point durations are expressed in. One of `base`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `weeks`, `months`, `years`. |
| `points` | list of list of number |  |  | time (`time_unit`) | The calendar, one [duration, value] pair per period, in order. |
| `weekly` | object |  |  |  | Weekday grid in LOCAL wall-clock time, instead of "points" . Needs "simulation.calendar". Keyed by weekday (mon..sun); each value is a list of ["06:00", "14:00", value] bands. A day with no bands is off. |
| `off_value` | number |  | `0.0` |  | Value outside every band of a weekday schedule. |
| `exceptions` | list of object |  |  |  | Dated overrides of a weekday grid -- holidays, shutdowns. Whole LOCAL days, "end" inclusive; last match wins. |

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

## Example

```json
{"schedules": [{"name": "Shifts", "kind": "capacity", "time_unit": "hours", "repeat": true, "points": [[8, 2], [16, 0]]}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_schedule(name='Shifts', kind='capacity', time_unit='hours', repeat=True, points=[[8, 2], [16, 0]])
```

## Used in

Bundled models: [Biogas plant (library assets)](../../gallery/energy.md), [Hub day: electrifying the ground support equipment](../../gallery/logistics.md), [Hub day: turnaround workload (crews, ground equipment, on-time departures)](../../gallery/logistics.md), [Call centre on real dates](../../gallery/services.md), [Walk-in clinic (library assets)](../../gallery/services.md), [Walk-in clinic digital twin](../../gallery/services.md).

Guides: [Coming from AnyLogic](../../coming-from/anylogic.md), [Coming from Arena](../../coming-from/arena.md), [Model file format](../../model-file-format.md), [Batteries and charging](../../modelling-guide/batteries.md), [Schedules, failures and the WAIT rule](../../modelling-guide/schedules-failures.md), [Semantic diff](../../semantic-diff.md).

## See also

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