Helo,我正在 SimPy 中构建一个相对复杂的离散事件模拟模型。
当我尝试将 yield 语句放在函数中时,我的程序似乎不起作用。下面显示一个例子。
import SimPy.SimulationTrace as Sim
import random
## Model components ##
class Customer(Sim.Process):
def visit(self):
yield Sim.hold, self, 2.0
if random.random()<0.5:
self.holdLong()
else:
self.holdShort()
def holdLong(self):
yield Sim.hold, self, 1.0
# more yeild statements to follow
def holdShort(self):
yield Sim.hold, self, 0.5
# more yeild statements to follow
## Experiment data ##
maxTime = 10.0 #minutes
## Model/Experiment ##
#random.seed(12345)
Sim.initialize()
c = Customer(name = "Klaus") #customer object
Sim.activate(c, c.visit(), at = 1.0)
Sim.simulate(until=maxTime)
我从运行中得到的输出是:
0 activate <Klaus > at time: 1.0 prior: False
1.0 hold < Klaus > delay: 2.0
3.0 <Klaus > terminated
holdLong() 和holdShort 方法似乎根本不起作用。我怎样才能解决这个问题?提前致谢。