def terminate_whenStateIsReached(clock, model): return model.trafficLight.state.get() == "manual" sim.setTerminationCondition(terminate_whenStateIsReached) # A termination time is prefered over a termination condition, # as it is much simpler to use. # e.g. to simulate until simulation time 100.0 is reached sim.setTerminationTime(300.0) # B. Set the use of a tracer to show what happened during the simulation run # Both writing to stdout or file is possible: # pass None for stdout, or a filename for writing to that file sim.setVerbose(None) # C. Use Classic DEVS instead of Parallel DEVS # If your model uses Classic DEVS, this configuration MUST be set as # otherwise errors are guaranteed to happen. # Without this option, events will be remapped and the select function # will never be called. sim.setClassicDEVS() # ====================================================================== # 4. Simulate the model sim.simulate() # ====================================================================== # 5. (optional) Extract data from the simulated model print("Simulation terminated with traffic light in state %s" % (trafficSystem.trafficLight.state.get()))