def do_simulation(self): """ Do one simulation run. Initialize simulation and create first and last event. After that, one after another event is processed. :return: SimResult object """ # insert first and last event self.event_chain.insert(CustomerArrival(self, 0)) self.event_chain.insert( SimulationTermination(self, self.sim_param.SIM_TIME)) # start simulation (run) while not self.sim_state.stop: # TODO Task 1.4.1: Your code goes here """ Hint: You can use and adapt the following lines in your realization e = self.event_chain.remove_oldest_event() e.process() """ pass # TODO Task 2.4.3: Your code goes here somewhere # gather results for sim_result object self.sim_result.gather_results() return self.sim_result
def test_event_chain(self): """ Test module EventChain. Add and remove SimEvents and check the correct order. """ # priorities: SC = 0, CA = 1, ST = 2 e = EventChain() e.insert(CustomerArrival(None, 10)) e.insert(SimulationTermination(None, 10)) e.insert(ServiceCompletion(None, 10)) e.insert(CustomerArrival(None, 5)) e.insert(ServiceCompletion(None, 2)) results = [[2, 0], [5, 1], [10, 0], [10, 1], [10, 2]] for r in results: ev = e.remove_oldest_event() self.assertEqual( [ev.timestamp, ev.priority], r, msg= "Error in EventChain or SimEvent. Events are sorted or returned in the wrong order." ) self.assertEqual( len(e.event_list), 0, msg="Error in EventChain or SimEvent. EventChain should be empty.")
def test_simulation_termination(self): """ Check correct behavior of SimulationTermination. SimState stop flag should be set true. """ DESTest.sim.reset() SimulationTermination(DESTest.sim, 0).process() self.assertEqual(DESTest.sim.sim_state.stop, True, msg="Error in SimulationTermination. Stopping simulation doesn't work as expected.")
def do_simulation(self): """ Do one simulation run. Initialize simulation and create first and last event. After that, one after another event is processed. :return: SimResult object """ # insert first and last event self.event_chain.insert(CustomerArrival(self, 0)) self.event_chain.insert( SimulationTermination(self, self.sim_param.SIM_TIME)) # start simulation (run) while not self.sim_state.stop: # TODO Task 1.4.1: Your code goes here """ Hint: You can use and adapt the following lines in your realization e = self.event_chain.remove_oldest_event() e.process() """ e = self.event_chain.remove_oldest_event() if e: # if event exists and timestamps are ok, process the event if self.sim_state.now <= e.timestamp: self.sim_state.now = e.timestamp self.counter_collection.count_queue() e.process() else: print "NOW: " + str( self.sim_state.now) + ", EVENT TIMESTAMP: " + str( e.timestamp) raise RuntimeError( "ERROR: TIMESTAMP OF EVENT IS SMALLER THAN CURRENT TIME." ) else: print "Event chain is empty. Abort" self.sim_state.stop = True # TODO Task 2.4.3: Your code goes here somewhere #self.counter_collection.count_queue() # gather results for sim_result object self.sim_result.gather_results() return self.sim_result
def do_simulation(self): """ Do one simulation run. Initialize simulation and create first and last event. After that, one after another event is processed. :return: SimResult object """ # insert first and last event self.event_chain.insert(CustomerArrival(self, 0)) self.event_chain.insert( SimulationTermination(self, self.sim_param.SIM_TIME)) # start simulation (run) while not self.sim_state.stop: # get next simevent from events e = self.event_chain.remove_oldest_event() if e: # if event exists and timestamps are ok, process the event if self.sim_state.now <= e.timestamp: self.sim_state.now = e.timestamp self.counter_collection.count_queue() e.process() else: print('NOW: ' + str(self.sim_state.now) + ', EVENT TIMESTAMP: ' + str(e.timestamp)) raise RuntimeError( "ERROR: TIMESTAMP OF EVENT IS SMALLER THAN CURRENT TIME." ) else: print('Event chain is empty. Abort') self.sim_state.stop = True # gather results for sim_result object self.sim_result.gather_results() return self.sim_result