Reputation: 183
I'm using simpy 3.xx with python 2.7. I'm trying to build up a train simulation. What is needed is that the train process generated a request for entry at a specific time in the simulation. This must be very simple to do, but for sme reason I'm not able to find a solution.
Let's say at simulation-time 20 I want a process to generate a request event, how do I go about doing that? Normally I'd generate a request : req = res.request(), and then yield req. I wish to schedule a request event at a specific time.
Upvotes: 1
Views: 692
Reputation: 1828
You should start with a timeout
event. Here is a timeout event, based upon the tutorial. As you stated, this generates a request event at time 20.
#at time 20 generate a request event
import simpy
class TrainStation:
def __init__(self,env):
self.env= env
self.request_event = env.event()
self.request_receiver_process = env.process(self.receive_request())
self.request_producer_process = env.process(self.produce_request())
def produce_request(self):
yield self.env.timeout(20)
self.request_event.succeed()
self.request_event = self.env.event()
def receive_request(self):
print("Waiting for request at time: {0}".format(env.now))
yield self.request_event
print("Request received at time: {0}".format(env.now))
env = simpy.Environment()
trainStation = TrainStation(env)
env.run()
Upvotes: 3