Is there a way to terminate the simpy simulation by using a command like env.exit()? I don’t understand how to place an event into env.run(until=event)
. I want to terminate the simulation when there are no objects left in my certain Simpy Stores
. How can I do that?
Advertisement
Answer
Everything is an event in simpy, even the environment itself. Thus, you can terminate the simulation marking as succeed the “root” event.
JavaScript
x
6
1
# Save the event somewhere
2
end_event = env.event()
3
4
# Later, when you want to terminate the simulation, run
5
end_event.succeed()
6
In order to check if a store is empty, just check if its items
len is equal to zero.
If you put all together, you can do something like that to solve your problem:
JavaScript
1
4
1
store = simpy.FilterStore(env, capacity=10)
2
if len(store.items) == 0:
3
end_event.succeed()
4