utils.populate_store

utils.populate_store(num_resources, simpy_store, sim_env)

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

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

Each CustomResource 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 CustomResource objects to create and add to the store. required
simpy_store simpy.Store or vidigi.utils.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

Returns

Name Type Description
None

Notes

  • Each CustomResource is created with a capacity of 1.
  • The ID attribute of each CustomResource 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)
>>> len(resource_store.items)  # The store now contains 5 CustomResource objects
5