Event Example
This example is about showing the usage of the Event component. This component can be used as a
condition that needs to be triggered in order to continue the simulation.
pydes.Event(sim)
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.
Imports
First of all, we import the necessary modules and classes from the pydes library. These imports are essential for setting up and running our simulation.
Define Model
We define Process1, which is one of the example processes in our simulation. Process1 waits for an event to be triggered.
We define Process2, which is the second example process in our simulation. Process2 triggers the event after a specified duration.
Run Simulation
Finally, we set up the simulation environment, schedule the processes, and run the simulation.
sim = Simulator()
event = Event(sim)
p1 = Process1(sim, event)
p2 = Process2(sim, event)
sim.schedule(p1.main)
sim.schedule(p2.main)
sim.run()
The simulation output would resemble the following:
| ------------------------------ | --------------- | ---------------------------------------- | ------------------------------ |
| time | component | value | description |
| ------------------------------ | --------------- | ---------------------------------------- | ------------------------------ |
| | | | |
| 0 | Process1.0 | wait for event | None |
| 0 | Process2.0 | sleeps before triggering event | None |
| 10 | Process2.0 | sets event | None |
| 10 | Process2.0 | event was set | None |
| 10 | Process1.0 | event was triggered | None |