Reputation: 97
I want to be able to run multiple simulation instances one after the other. What I have done, is create a "Multi-Run" button that calls a function that will call go as many times as the user asks.
The problem is that running go in a loop doesn't seem to operate the same as running go "forever" (as the button allows you to). I have stop conditions within go that allow for the simulation to stop when certain conditions are met.
How do I achieve this? OR How can I run multiple simulations one after the other successfully? Can I do this by calling Netlogo in Python?
Upvotes: 2
Views: 170
Reputation: 2780
One way to do it is to use a global variable to track the stop?
state for each run, then your multi-run
procedure can check that to see if it's time to move on to the next run.
You didn't provide code, so here is a simple example.
globals [
stop?
run-number
initial-value
]
to multi-run
let run-settings [1 3 5 7 9 11]
set run-number 0
foreach run-settings [ setting ->
set stop? false
set initial-value setting
setup
while [not stop?] [
go
]
show-results
set run-number (run-number + 1)
]
end
to setup
create-turtles initial-value
reset-ticks
end
to go
ask n-of (random initial-value) turtles [ forward 10 ]
tick
if (ticks > 100) [ set stop? true ]
end
to show-results
show run-number
show mean [xcor] of turtles
show mean [ycor] of turtles
end
If you use this method I recommend adding a tick limit to set stop? true
even if that's not your primary criteria, just in case your model hits a scenario where it's never going to stop on its own.
To make sure you are aware: if you just want to generate results for multiple runs of a model to a CSV format but you don't really care about the UI updating throughout, you should check out the built-in BehaviorSpace feature which is designed to do just that.
Upvotes: 3