# resources

Named resources: capacity, queue discipline, optional ranking expression, capacity schedule, cost fields.

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

A scenario, an experiment or an optimizer can set a field by the path `resources.<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 resource's name; blocks seize it by this name. |
| `capacity` | integer |  | `1` | count | How many units can be held at the same time. |
| `discipline` | choice |  | `"FIFO"` |  | Queue order. LowestValueFirst/HighestValueFirst need a ranking_expr; Plan works each station's planned order (entity.plan, cpsat.propose). One of `FIFO`, `LIFO`, `LowestValueFirst`, `HighestValueFirst`, `Plan`. |
| `ranking_expr` | string |  |  |  | Expression ranking the queue, for a ranked discipline. |
| `rerank` | boolean |  | `false` |  | Re-evaluate ranking_expr for every waiting request just before each grant, instead of once when it joins the queue; only meaningful with LowestValueFirst/HighestValueFirst. |
| `capacity_schedule` | string |  |  |  | Name of a "capacity" schedule staffing this resource. |
| `cost_busy` | number |  | `0.0` | rate (`cost_time_unit`) | Cost per time unit (see `cost_time_unit`) while a unit is held. |
| `cost_idle` | number |  | `0.0` | rate (`cost_time_unit`) | Cost per time unit (see `cost_time_unit`) while a unit is free. |
| `cost_per_use` | number |  | `0.0` | money | Cost added each time a unit is seized. |
| `cost_time_unit` | choice |  | `"hours"` |  | Unit cost_busy/cost_idle are quoted per. One of `base`, `milliseconds`, `seconds`, `minutes`, `hours`, `days`, `weeks`, `months`, `years`. |
| `power` | object |  |  |  | kW per unit while busy/idle/blocked/down/off_shift; absent keys are 0, "blocked" defaults to "busy" (a blocked unit is seized). |

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

## Example

```json
{"resources": [{"name": "Server", "capacity": 2, "discipline": "FIFO"}]}
```

In the Python builder:

```python
from nagasim import build as nb
m = nb.Model()
m.add_resource(name='Server', capacity=2, discipline='FIFO')
```

## Used in

Bundled models: [Berth: shore power](../../gallery/energy.md), [Biogas digester, holder and CHP](../../gallery/energy.md), [Biogas plant (library assets)](../../gallery/energy.md), [Emergency department: staffing game](../../gallery/games.md), [Belt with stops, a divert and a merge](../../gallery/logistics.md), [Hub day: electrifying the ground support equipment](../../gallery/logistics.md) and 31 more.

Guides: [Model file format](../../model-file-format.md), [Coming from SimPy](../../coming-from/simpy.md), [Coming from AnyLogic](../../coming-from/anylogic.md), [Coming from Arena](../../coming-from/arena.md), [Coming from salabim](../../coming-from/salabim.md), [Digital twin](../../digital-twin.md) and 5 more.

## See also

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