Conditional end simulation

Eliot McIntire edited this page Feb 2, 2018 · 3 revisions

Is there's a way of stopping the SpaDES simulation based on a condition, such as when some variable reaches a certain value?

Simply change the end time of the simulation mid-run: when your condition is met, change the end time to the current time.

Within your module:

if (condition) end(sim) <- time(sim)

With care, you can also manipulate the event queue. For example, if you remove all the events in the queue, then it will the time will proceed until the end time (i.e., end(sim) )

# remove all events in the event queue
if (condition) events(sim) <- events(sim)[0]
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.