resources.populate_store

resources.populate_store(
    num_resources,
    simpy_store,
    sim_env,
    label=None,
    extra_attributes=None,
)

Populate a SimPy Store (or VidigiPriorityStore) with VidigiResource objects.

.. deprecated:: 2.0.0 populate_store() will be removed in vidigi 3.0. It predates being able to build the pool through the store itself. Use VidigiStore(env, num_resources=N, label=...) / VidigiPriorityStore(env, num_resources=N, label=...), or store.populate(N, label=...) to top one up. A plain simpy.Store filled this way should become a VidigiStore - a drop-in replacement for simpy.Resource that also enables the count / num_resources properties. populate_store() does not feed those properties.

This function creates a specified number of VidigiResource objects and adds them to a SimPy Store, a VidigiStore, or VidigiPriorityStore.

Each VidigiResource is initialized with a capacity of 1 and a unique ID attribute, which is crucial for animation functions where you wish to show an individual entity consistently using the same resource.

If using VidigiPriorityStore, you will need to pass the relevant priority in to the .get() argument when pulling a resource out of the store.

Parameters

Name Type Description Default
num_resources int The number of VidigiResource objects to create and add to the store. required
simpy_store (simpy.Store, vidigi.resources.VidigiStore or vidigi.resources.VidigiPriorityStore) The SimPy Store object to populate with resources. required
sim_env simpy.Environment The SimPy environment in which the resources and store exist. required
label str A name for this pool of resources, e.g. "triage". When given, each resource also gets .unique_id_attribute (f"{label}_{id_attribute}") - unique across pools when every pool is given a distinct label, unlike id_attribute alone, which restarts at 1 in every pool. Omitting it (the default) changes nothing about the resources produced, but warns that label will become mandatory at vidigi 3.0 - see vidigi.analysis.resource_utilisation’s by="resource" docs for why. None
extra_attributes dict Further attributes to set on every resource in this pool, e.g. {"staff_type": "nurse"} - each becomes resource.staff_type etc., readable by your model code (for break scheduling, skill mix, …) and otherwise inert. VidigiResource has always accepted arbitrary keyword attributes directly; this just threads them through the bulk populate path so you do not have to build the pool by hand. Cannot be used to set id_attribute/id/label/unique_id_attribute/unique_id (managed by the pool) - that raises ValueError. None

Returns

Name Type Description
None

Notes

  • Each VidigiResource is created with a capacity of 1.
  • The ID attribute of each VidigiResource is set to its index in the creation loop plus one, ensuring unique IDs starting from 1.
  • This function is typically used to initialize a pool of resources at the start of a simulation.

Examples

>>> import simpy
>>> env = simpy.Environment()
>>> resource_store = simpy.Store(env)
>>> populate_store(5, resource_store, env, label="triage")
>>> len(resource_store.items)  # The store now contains 5 VidigiResource objects
5
Back to top