resources.populate_store

resources.populate_store(num_resources, simpy_store, sim_env)

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

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

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)
>>> len(resource_store.items)  # The store now contains 5 VidigiResource objects
5