私は Simpy マニュアルのバスの内訳の例を実験してきましたが、バスの複数のインスタンスを作成すると、最初の修復後に最後のインスタンスが "of sequence" になるように見える理由を理解するのに本当に苦労しています。Bus の 2 つのインスタンス (Bus1 と Bus2) を作成するために、マニュアルのサンプル コードの initialize() ステートメントのすぐ下をわずかに変更しました。これが私のコードです:
from SimPy.Simulation import *
class Bus(Process):
def operate(self,repairduration,triplength): # PEM
tripleft = triplength
# "tripleft" is the driving time to finish trip
# if there are no further breakdowns
while tripleft > 0:
yield hold,self,tripleft # try to finish the trip
# if a breakdown intervenes
if self.interrupted():
print self.interruptCause.name, 'at %s' %now()
tripleft=self.interruptLeft
# update driving time to finish
# the trip if no more breakdowns
self.interruptReset() # end self-interrupted state
# update next breakdown time
reactivate(br,delay=repairduration)
# impose delay for repairs on self
yield hold,self,repairduration
print '%s repaired at %s' %(self.name, now())
else: # no breakdowns intervened, so bus finished trip
break
print 'Bus has arrived at %s' %now()
class Breakdown(Process):
def __init__(self,myBus):
Process.__init__(self,name='Breakdown '+myBus.name)
self.bus=myBus
def breakBus(self,interval): # Process Execution Method
while True:
yield hold,self,interval # driving time between breakdowns
if self.bus.terminated(): break
# signal "self.bus" to break itself down
self.interrupt(self.bus)
initialize()
for i in range(1,5):
b=Bus('Bus%s' %i) # create a Bus object "b" called "Bus"
activate(b,b.operate(repairduration=20,triplength=1000))
# create a Breakdown object "br" for bus "b", and
br=Breakdown(b)
# activate it with driving time between
# breakdowns equal to 300
activate(br,br.breakBus(300))
simulate(until=4000)
print 'SimPy: No more events at time %s' %now()
上記により、次の出力が得られます。
Breakdown Bus1 at 300
Breakdown Bus2 at 300
Bus1 repaired at 320
Bus2 repaired at 320
Breakdown Bus1 at 600
Bus1 repaired at 620
Breakdown Bus2 at 620
Bus2 repaired at 640
Breakdown Bus1 at 900
Bus1 repaired at 920
Breakdown Bus2 at 920
Bus2 repaired at 940
Bus has arrived at 1060
Bus has arrived at 1060
SimPy: No more events at time 1240
さて、質問: t=600 の時点で、バス 2 が故障する前にバス 1 が修理されるのはなぜですか? 両方のバスが故障し、「ロックステップ」で修理されると予想していました。さらに、4 つのバスを作成すると、最初の 3 つが失敗し、以下に示すように「ロック ステップ」で修復されます。ただし、バス 4 は、最初の修理の後、20 までにシーケンスから外れます。なぜこれが起こるのかわかりません。誰かが提供できる洞察をいただければ幸いです。これは常に最後のインスタンスで発生します。
Breakdown Bus1 at 300
Breakdown Bus2 at 300
Breakdown Bus3 at 300
Breakdown Bus4 at 300
Bus1 repaired at 320
Bus2 repaired at 320
Bus3 repaired at 320
Bus4 repaired at 320
Breakdown Bus1 at 600
Breakdown Bus2 at 600
Breakdown Bus3 at 600
Bus1 repaired at 620
Bus2 repaired at 620
Bus3 repaired at 620
Breakdown Bus4 at 620
Bus4 repaired at 640
Breakdown Bus1 at 900
Breakdown Bus2 at 900
Breakdown Bus3 at 900
Bus1 repaired at 920
Bus2 repaired at 920
Bus3 repaired at 920
Breakdown Bus4 at 920
Bus4 repaired at 940
Bus has arrived at 1060
Bus has arrived at 1060
Bus has arrived at 1060
Bus has arrived at 1060
SimPy: No more events at time 1240
ありがとう、シーモア