Resource Example
pydes.Resource(sim, capacity=1)
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.
Imports
Define Model
Run Simulation
sim = Simulator()
resource = Resource(sim)
p1 = Process1(sim, resource)
p2 = Process2(sim, resource)
sim.schedule(p1.main)
sim.schedule(p2.main)
sim.run()
| ------------------------------ | --------------- | ---------------------------------------- | ------------------------------ |
| time | component | value | description |
| ------------------------------ | --------------- | ---------------------------------------- | ------------------------------ |
| | | | |
| 0 | Process1.0 | requesting resource | None |
| 0 | Process1.0 | resource aquired | None |
| 0 | Process2.0 | sleeps before requesting | None |
| 5 | Process2.0 | requesting resource | None |
| 10 | Process1.0 | releasing resource | None |
| 10 | Process1.0 | resource released | None |
| 10 | Process2.0 | resource aquired | None |
| 20 | Process2.0 | releasing resource | None |
| 20 | Process2.0 | resource released | None |