python - How to schedule a request at a particular time? -
I am using simpy 3.xx with dragon 2.7. I am trying to create a train simulation why it is necessary that the train process requested a request to enter simulation at a specific time. It should be very easy to do this, but I think I can not find any solution.
We say simulation-time 20 I want the process of preparing a request event, how do I do it? Common would generate I have a request: req = res.request (), and then req produce I would like to schedule a request event at a specific time.
You should start with a timeout event. It generates a timeout event, based on stated, this generates a request event on 20
#at time 20 imports a request event simpy square Trainstation on :. 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 the request for "time is: {0} ". format (env.now)) self.request_event produce print (" received the request: {0} ". format (env.now)) env = simpy.Environment () Trainstation = Trainstation (Env) env.run ()
Comments
Post a Comment