イベント シミュレーションの作業を始めたばかりですが、キューの監視に問題があります。
キューを確認するたびに、実際に Env.now が表示されているようです。何かアドバイス?
import simpy
num_of_machines = 2
env = simpy.Environment()
bcs = simpy.Resource(env, capacity=num_of_machines)
def monitor(resource):
"""This is our monitoring callback."""
print('Queue size: %s' % len(resource.queue))
def process_client(env, name):
with bcs.request() as req:
yield req
print('%s starting to charge at %s' % (name, env.now))
yield env.timeout(90)
print('%s ending charge at %s' % (name, env.now))
monitor(bcs)
def setup(env):
i = 0
while True:
i += 1
yield env.timeout(1)
env.process(process_client(env, ('Car %s' % i)))
env.process(setup(env))
env.run(until=300)
結果:
Car 1 starting to charge at 1
Car 2 starting to charge at 2
Car 1 ending charge at 91
Queue size: 88
Car 3 starting to charge at 91
Car 2 ending charge at 92
Queue size: 88
Car 4 starting to charge at 92
Car 3 ending charge at 181
Queue size: 176
Car 5 starting to charge at 181
Car 4 ending charge at 182
Queue size: 176
Car 6 starting to charge at 182
Car 5 ending charge at 271
Queue size: 264
Car 7 starting to charge at 271
Car 6 ending charge at 272
Queue size: 264
Car 8 starting to charge at 272