components
Component
Base class for components in the simulation.
Components are just an utility base class that tracks how many
instances of itself are created. Its id property will be unique
during the simulation.
This property is usefull to identify different components in the simulation
without having to set an explicit name for them, however is not a requirement
for the Simulation to run.
from pydes.process import Component, Simulator
# define the component with a main method
class Process(Component):
def __init__(self, sim: Simulator):
self.sim = sim
def main(self):
for _ in range(10):
print(self.sim.now(),"waiting")
self.sim.sleep(2)
print(self.sim.now(),"waiting")
# create the simulator object
sim = Simulator()
# create an instance of the Component
process = Process(sim)
# schedule the process in the simulator
sim.schedule(process.main)
# now you can run the simulation
sim.run()
Event(sim)
Bases: Component
An event can be waited and set by components. They are very useful to model trigger conditions and model interaction between different actors across the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
Methods:
| Name | Description |
|---|---|
wait |
a component can call the |
set |
a component can call the |
set()
Set the event.
wait()
Wait for the event to be set.
State(sim, value)
Bases: Component
Represents a state in the simulation. It is highly recommended to use Enums to control the possible values that a State object can take.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
value
|
Any
|
The initial value of the state. |
required |
Methods:
| Name | Description |
|---|---|
set |
changes the state to a new provided value |
wait |
waits until a certain value is set in the State. |
set(value)
Set the state to a new value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The new value of the state. |
required |
wait(value)
Wait for the state to become a specific value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to wait for. |
required |
Queue(sim, capacity=inf)
Bases: Component
Queues are used to acumulate objects in a buffer and retrieved them from it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
capacity
|
float | int
|
The maximun lenght of the queue. |
inf
|
Methods:
| Name | Description |
|---|---|
put |
tries to insert a new member into the queue and waits if the queue is full. |
get |
tries to get one member from the queue and waits if the queue is empty. |
Constructor for Queue class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
get()
Get an item from the queue.
Waits until there is an item available in the queue.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The item retrieved from the queue. |
put(member)
Put an item into the queue or waits if the queue is full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
member
|
Any
|
The item to be put into the queue. |
required |
size()
Get the size of the queue. Its equivalent to the number of member inside.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of items in the queue. |
Resource(sim, capacity=1)
Bases: Component
Resources can be requested and released by components and therefore are really useful in modeling real world scenarios quere components must be shared among different processess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
capacity
|
int
|
The capacity of the resource, default is 1. |
1
|
Methods:
| Name | Description |
|---|---|
request |
tries to get the ownership of this |
release |
gives back the ownership of the |
request(by)
Request the resource.
If the resource is idle, the component can acquire it. Otherwise, it waits until the resource becomes idle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
Component
|
The component requesting the resource. |
required |
release(by)
Release the resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by
|
Component
|
The component releasing the resource. |
required |
Raises:
| Type | Description |
|---|---|
PydesError
|
If the component has not previously requested the resource. |
usage()
Get the current usage of the resource.
capacity()
Get the capacity of the resource.
is_idle()
Check if the resource is idle.
Container(sim, capacity=inf)
Bases: Component
Containers have the capability to acumulate and provide continuous amounts of what contains. It is particularly useful to model non discrete accumulators like Tanks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
capacity
|
int | float
|
The capacity of the container, default is 1. |
inf
|
Methods:
| Name | Description |
|---|---|
get |
decrease the level of the container by some amount. |
put |
increase the level of the container by some amount. |
get(amount=1)
Get some amount from the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
int | float
|
The amount to get from the container, default is 1. |
1
|
put(amount=1)
Put some amount into the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
int | float
|
The amount to put into the container, default is 1. |
1
|
level()
Get the current level of the container.
capacity()
Get the capacity of the container.
Store(sim, capacity=1)
Bases: Component
Stores are useful to save and retrieve objects. Stores can be use to insert any type of object but it requires all the objects to be of the same type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
Simulator
|
The simulator instance. |
required |
capacity
|
int
|
The capacity of the store, default is infinity. |
1
|
get()
Get an item from the store.
put(item)
Put an item into the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Any
|
The item to put into the store. |
required |
level()
Get the current level of the store.
capacity()
Get the capacity of the store.