simpype.resource
¶
SimPype’s resources process Message
objects.
The behavior of each resource can be customized by overloading the custom
service
function through the decorator @simpype.resource.service
.
See Resource service()
for more details on how to customize a Resource
behavior.
import simpype
import random
sim = simpype.Simulation(id = 'simple')
gen0 = sim.add_generator(id = 'gen0')
gen0.message.property['wait'] = {
0: lambda: random.uniform(0,1)
}
res0 = sim.add_resource(id = 'res0')
res0.random['service'] = {
0: lambda: 2.0
}
@simpype.resource.service(res0)
def service(self, message):
# Wait for a random time
yield self.env.timeout(self.random['service'])
# Wait for a time as reported in the message property
yield self.env.timeout(message.property['wait'].value)
sim.run(until = 10)
-
class
simpype.resource.
Resource
(sim, id, capacity=1, pipe=None)¶ This class implements the
Resource
object.Parameters: - sim (
Simulation
) – The SimPype simulation object. - id (str) – The resource id.
- capacity (int) – The simpy.Resource capacity.
- pipe (
Pipe
) – The SimPype pipe model associated to this resource.
-
sim
¶ The SimPype simulation object.
Type: Simulation
-
env
¶ The SimPy environment object.
Type: simpy.Environment
-
id
¶ The simpype.Resource id.
Type: str
-
use
¶ The SimPy resource object.
Type: simpy.Resource
-
pipe
¶ The SimPype pipe object.
Type: Pipe
-
random
¶ The SimPype RandomDict object.
Type: RandomDict
-
task
¶ The dictionary storing the task currenty being executed by the resource.
Type: dict
- sim (
-
class
simpype.resource.
Task
(sim, message, process)¶ This class implements the
Task
managed by theResource
.Parameters: - sim (
Simulation
) – The SimPype simulation object. - message (
Message
) – The message being processed in this class - process (simpy.events.Process) – The SimPy process to execute
-
sim
¶ The SimPype simulation object.
Type: Simulation
-
env
¶ The SimPy environment object.
Type: simpy.Environment
-
started
¶ The simulation time this task was started
Type: float
-
interrupted
¶ The simulation time this task was interrupted.
None
if active.Type: float
-
process
¶ The SimPy process being executed
Type: simpy.events.Process
- sim (
-
simpype.resource.
service
(arg)¶ Decorator for overloading the default
Resource
service behavior.Parameters: arg ( Resource
)(self
) – TheResource
instance.If the overloading is done in scripts, the
Resource
instance must be provided as decorator argument.myresource = sim.add_resource(id = 'myresource1') @simpype.resource.service(myresource) def service(self, message): yield self.env.timeout(1.0)
If the overloading is done inside a Resource subclass, the decorator must be called without any arguments.
Resource
instance is automatically provided throughself
.class MyResource(simpype.Resource): def __init__(self, sim, id, capacity = 1, pipe = None): super().__init__(sim, id, capacity, pipe) @simpype.resource.service def service(self, message): yield self.env.timeout(1.0)