I am just starting to work on an event simulation, and I am having some issues with monitoring the queue.
It appears that every time I check the queue, it is actually showing the Env.now. Any advice?
** BTW I am new to the group and SimPy. If this isn't proper to post this in the group please let me know and I will remove it. ***
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)
Results:
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
yield env.process(process_client(env, 'Car %s' % i))