Jack
Jack

Reputation: 1437

Netlogo - Behavior Space

I want to run experiments using behavior space. However, the number of experiments needed is depending on the length of a list which is dynamic subject to the external data loaded. Hence , I want to do something like below which is not supported:

enter image description here

what is the correct way to do so? thanks

Upvotes: 1

Views: 965

Answers (1)

Luke C
Luke C

Reputation: 10291

You note that you do this with a .bat or .sha file. If that's the case, here's a .bat solution. However, I'm not sure what your data looks like- in this example I just used the number of entries in a csv file to determine the number of runs needed.

So, I have a data file called 'example_data.csv' that looks like this:

1
100
1000
10000

I have an .nlogo file with an Input widget that defines a global variable called n_runs. I pulled out the xml for an BehaviorSpace experiment and saved it in a file called "experiment_base.xml"- it looks like:

<experiments>
  <experiment name="experiment" repetitions="1" sequentialRunOrder="false" runMetricsEveryStep="false">
    <setup>setup</setup>
    <go>tick</go>
    <timeLimit steps="5"/>
    <metric>count turtles</metric>
    <steppedValueSet variable="n_runs" first="1" step="1" last="1"/>
  </experiment>
</experiments>

I have a .bat file that:

  • counts the number of entries in my 'example_data.csv"
  • reads in the 'experiment_base.xml' file and replaces the last="1" with the number read above, then writes this as a new experiment called 'mod_experiments.xml'
  • runs the experiment using the newly generated experiments file

This entire bat file looks like:

@echo off
cls
setlocal EnableDelayedExpansion
set "cmd=findstr /R /N "^^" example_data.csv | find /C ":""

for /f %%a in ('!cmd!') do set number=%%a

powershell -Command "(gc experiment_base.xml) -replace '<steppedValueSet variable=\"n_runs\" first=\"1\" step=\"1\" last=\"1\"/>', '<steppedValueSet variable=\"n_runs\" first=\"1\" step=\"1\" last=\"%number%\"/>' | Set-Content mod_experiments.xml

echo "Running experiment..."

netlogo-headless.bat ^
--model dynamic_behaviorspace.nlogo ^
--setup-file mod_experiments.xml ^
--table table-output.csv 

This outputs results for 4 experiments, since I had 4 values in my data file. If I modify the number of entries in the csv and rerun the .bat file, I get results for a corresponding number of runs.

Upvotes: 3

Related Questions