datasim.Resource¶
- class datasim.Resource(world, id: str, resource_type: str, slots: int = 1, usage_time: float = 0.0, max_queue: int = 0, capacity: int | float | None = None, start_amount: int | float | None = None, gather: bool = True, data_id: str = '', sample_frequency: int = 1, plot_options: ~datasim.types.PlotOptions = <datasim.types.PlotOptions object>)¶
Representation of a resource in the simulation.
This can either be a storage location for an amount of things, an item/tool/machine that can be used by a limited number of users, or a combination of both (e.g. a machine with a supply of a resource that also takes time to use).
- Usage:
You can choose to make subclasses of
Resource
to automatically more safely limit the types and implement your own more complex usage logic, or just createResource
objects directly, using onlyresource_type
to identify the kind of resource, and set a single usage_time if more than 1 tick.
- __init__(world, id: str, resource_type: str, slots: int = 1, usage_time: float = 0.0, max_queue: int = 0, capacity: int | float | None = None, start_amount: int | float | None = None, gather: bool = True, data_id: str = '', sample_frequency: int = 1, plot_options: ~datasim.types.PlotOptions = <datasim.types.PlotOptions object>)¶
Create a resource.
- Parameters:
world – The world to add this Resource to.
id (str) – Descriptive name of the resource.
resource_type (str) – Identifier of the resource in the pool.
slots (int, optional) – Number of possible simultaneous users. If set to 0, the resource is a pure counter. Defaults to 1.
usage_time – The default amount of time one use of this resource takes. Set to 0.0 if the resource doesn’t take time to use; if set to 0.0 and capacity is None, the resource only limits its usage on a single concurrent tick. You should probably only use that if your tick duration is very long. Defaults to 0.0.
max_queue (int, optional) – Size of optional queue of users who can automatically (without a separate State) wait for the resource when occupied. Defaults to 0.
capacity (int, optional) – Optional maximum amount stored in the pool. No maximum if set to 0. Defaults to 0.
start_amount (int, optional) – Starting amount of resources in the pool. Defaults to 0.
gather (PlotType or False, optional) – Whether to automatically gather data for the output for this resource, and which type of plot if so. Defaults to PlotType.none to only save.
data_id (str, optional) – id for the data source if gather is True. Defaults to empty string which sets data_id to the value of this Resource’s id.
sample_frequency (int, optional) – Whether to add a data point every frequency ticks. If set to 0, adds a data point only when the quantity changes. Defaults to 1.
plot_options (Optional[PlotOptions], optional) – Options for a plot. Defaults to default PlotOptions.
Methods
__init__
(world, id, resource_type[, slots, ...])Create a resource.
add_output
([data_id, frequency, plot_options])Create an output source for this Resource.
remove_user
(user)Try to remove a resource user.
try_use
(user[, amount, usage_time, ...])Try to use the resource.
usage_tick
(user)Override this function for more complex usage time than a flat number of time units.
Attributes
amount
Current amount of the resource.
occupied
Check if the resource is fully occupied.
world
id
resource_type
users
user_index
slots
usage_time
simple_time_left
queue
capacity
changed_tick