本文整理汇总了Python中simulator.Simulator.setTerminationTime方法的典型用法代码示例。如果您正苦于以下问题:Python Simulator.setTerminationTime方法的具体用法?Python Simulator.setTerminationTime怎么用?Python Simulator.setTerminationTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulator.Simulator
的用法示例。
在下文中一共展示了Simulator.setTerminationTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: time
# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import setTerminationTime [as 别名]
# 3. Perform all necessary configurations, the most commonly used are:
# A. Termination time (or termination condition)
# Using a termination condition will execute a provided function at
# every simulation step, making it possible to check for certain states
# being reached.
# It should return True to stop simulation, or Falso to continue.
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()
# ======================================================================
示例2: intTransition
# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import setTerminationTime [as 别名]
def intTransition(self):
self.state = None
return self.state
def extTransition(self, inputs):
self.state = inputs[self.inport]
return self.state
class CQueue(CoupledDEVS):
def __init__(self):
CoupledDEVS.__init__(self, "CQueue")
self.generator = self.addSubModel(Generator())
self.queue = self.addSubModel(Queue())
self.connectPorts(self.generator.outport, self.queue.inport)
class DQueue(CoupledDEVS):
def __init__(self):
CoupledDEVS.__init__(self, "DQueue")
self.generator = self.addSubModel(Generator())
self.queue1 = self.addSubModel(Queue())
self.queue2 = self.addSubModel(Queue())
self.connectPorts(self.generator.outport, self.queue1.inport)
self.connectPorts(self.generator.outport, self.queue2.inport)
model = CQueue()
sim = Simulator(model)
sim.setClassicDEVS()
sim.setTerminationTime(5.0)
sim.setVerbose()
sim.simulate()