-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Description
Problem Description:
I am using DEVSimulator
in a Mesa-based simulation, and I noticed that when there are no events in the queue, the simulation stops running. This behavior is problematic when I want to keep the simulation running indefinitely and allow new events to be scheduled dynamically.
Expected Behavior:
- When there are no events, the simulation should not stop completely but rather wait for new events to be scheduled (or continue advancing time at a fixed interval).
- Is there a built-in way to handle this behavior in
DEVSimulator
?
Current Workaround:
To prevent the simulation from stopping, I am considering:
- scheduling a periodic "idle" event that does nothing but keeps the queue active.
such as:
def idle_event(model):
# idle event can do nothing or just update the time
pass
# Schedule a periodic idle event after the simulator is initialized (e.g. before run_for())
def schedule_idle_events(simulator, interval=1):
# schedule an idle event every interval seconds
simulator.schedule_event_relative(idle_event, interval, function_kwargs={'model': simulator.model})
# call itself to ensure loop
simulator.schedule_event_relative(schedule_idle_events, interval, function_kwargs={'simulator': simulator, 'interval': interval})
# schedule the idle event immediately once initializing the simulator
schedule_idle_events(simulator, interval=1)
- Modifying the event processing loop(function
run_until
) to wait instead of stopping when the queue is empty.
such as:
def run_until(self, end_time):
while self.time < end_time:
try:
event = self.event_list.pop_event()
except IndexError:
# the queue is empty, wait for a while, and then continue the cycle
time.sleep(0.1)
continue
self.time = event.time
event.execute()
Is there a recommended way to handle this within DEVSimulator
, or is this expected behavior?
Steps to Reproduce:
- Create a
DEVSimulator
-based simulation. - Run it until all scheduled events are completed.
- Observe that the simulation stops running.
System Info:
- Mesa version: 3.1.4
- Python version: 3.11.6
- OS: macOS Sequoia 15.2
Any guidance on the best approach would be greatly appreciated!
Metadata
Metadata
Assignees
Labels
No labels