My model needs to import a certain amount of patch-related information (via import-world
) when setting up and it takes around 10 seconds to do that.
When using Behavior Space, these seconds add up very quickly and increase greatly the time needed to run experiments.
I need to shorten this time so I wanted to set things in a way that, when launching Behavior Space, the import-world
command is run only on the first run, while all the other times it can be avoided.
If something like that was possible, I could arrange my code in such a way that those 10 seconds would be needed only once each time Behavior Space is launched.
However, as far as I am aware, Behavior Space only asks you for a setup
command to be run at the beginning of each run.
I might be able to work out some ways to achieve what I want, but I only have in mind things that would look a bit error-prone or bad coding style (e.g. not using clear-all
upon setup but clearing "manually", at the end of my code, one by one the things that I want to clear, which would allow me to not clear the imported patch data, and then use if
upon setup to check if that data already exists, and if it exists then do not import it).
However, I would like to hear if there is a better way to achieve my goal here.
Your "bad coding style" idea is the correct one in this case, there is no other way to leave patch data intact while clearing the rest of the model data. The
clear-all
primitive is pretty clear about what it does in the docs, so you just need to replace it with all of its component commands besidesclear-patches
:Then you need to clear any patch data that isn't the "special" data you want to save.
ask patches [ set pcolor 0 ]
, as an example ifpcolor
is changed in the model run.You do need to check some conditional on
setup
to see if loading patch data is necessary. Not just for the first run, but because each thread you run in BehaviorSpace gets it own "world", so each will need to run your data import commands. From the sixth item in the BehaviorSpace gotchas:I hope that helps.