NetLogo Behaviourspace Experiment output for every tick - netlogo

I'm trying to run experiments for a model of mine. I need it to output certain variable values for every tick but when I run the experiment I only get the values of either tick = 0 or the values at the end of the simulation. I need the values for every tick, anyone knows how this can be done in the NetLogo behaviour space experiments? Thanks in advance!

When you setup an experiment, there is a checkbox for saving the "reports" of a reporter at every step:
When I setup this experiment for the Wolf Sheep Predation Model from the Models Library, it outputs the count turtles for every tick.

Related

How to efficiently create data on one variable all agents have

I'm working with a NetLogo model on EV charging behaviour. All (500) agents monitor their my-charging-demand per tick and I want to find out what happens to this emergent behaviour when I change the policy intervention that is active (costs of electricity in this case). I am trying to show changes in charging characteristics such as charging-duration, charging power etc.
What is the best way to create data on the agents' my-charging-demand in time?
Right now I am plotting all their data in one graph using the following code:
ask adopters
[ create-temporary-plot-pen (word-who)
set-plot-pen-color color
plotxy ticks my-charging-demand
]
It works, but unfortunately it also made the model incredibly slow, as 500 pens are to be updated every tick. The model needs 105120 ticks before a whole year/run is completed, as each tick in the model represents 5 minutes. Therefore, speed does matter :-)
Is there a more efficient way to keep track / create data of one variable all agents have?
If I have understood this correctly, you want each agent to remember the value of its variable my-charging-demand across all time. If so, the easiest way (but I don't know if it's more efficient) is to have the list as a turtle variable. So, modify your turtles-own to add another variable:
adopters-own
[ ....
my-charging-demand
my-charging-demand-series
]
And wherever you have the code for calculating demand, add the result to the list
ask adopters
[ ...
set my-charging-demand ...
set my-charging-demand lput my-charging-demand my-charging-demand-series
...
]
I can't imagine a plot with 500 lines is readable. The plot should do something like the average of my-charging-demand or the proportion of turtles with my-charging-demand greater than some threshold.

NetLogo set random-seed according to the number of repetitions in the Behavior Space

I would like to know whether is it possible in NetLogo to set the random-seed according to the number of repetitions in the Behavior Space.
I know there is the command random-seed behaviorspace-run-number, but it sets a different seed for every run of the model. This is not what I want because I am trying to explore the impact of a variation in the values of a parameter on a specific random network structure. By using random-seed behaviorspace-run-number I get a different network structure for each value of the parameter within the same repetition of the experiment, which is not what I want.
Can anyone help me on this?
Thanks a lot,
Emanuele
There's not a variable that gives you exactly what you want, but BehaviorSpace runs through the parameter sets in a specific order. Say you have 5 repetitions of 20 parameter combinations, so there's 100 runs. It will do the first run of 20 combinations, then the second series etc. So you can do some mathematics or some if/then to go from the behaviorspace-run-number to the random-seed (eg floor behaviorspace-run-number / 20 if you want it to change every 20 runs).

NetLogo Experiment Setup

I'm working on a model in Netlogo and I'm having a problem understanding how to set up an "experiment". In my model, I have a matrix that has all of the values that I'm interested in (6 in total) and the matrix is updated whenever a condition is met (every time X turtles are killed off) basically capturing a snapshot of the model at that point. The previous values in the matrix are cleared, so the matrix is a 1x6, not a 10000x6 matrix with only one line being updated for each snapshot.
What I would like to do is to set up an experiment to run my model several hundred times, collecting this matrix each time for the first X number of snapshots or until Y ticks have occurred. But I can't see a way to do that in the experiment setup?
Is this possible to do, or would I have to create the 100x6 (100 snapshots) and then just export that matrix to a CSV somehow?
I've never set up an experiment in Netlogo, so this might be super easy to do or just be completely impossible.
If I understand your question correctly, then you want 6 values reported at specific ticks during the run. Those ticks are chosen by meeting a condition rather than a certain number of ticks. NetLogo has an experiment management tool called BehaviorSpace. It is straightforward to set up your several hundred runs (potentially with different values for any inputs on sliders etc). It's not so straightforward to only output on certain ticks.
The BehaviorSpace dialogue box has a checkmark for every tick or at the end only. If you have it set to every tick, then you can export your six numbers every tick automatically. In your case, it is likely to be easier to do that than to try and only output occasionally. You could add a seventh reporter that is true/false for whether the matrix is being reset this tick. Then all you have to do in post-processing is select the lines where that seventh reporter is true.
If you want to run the model for exactly N snapshots, then you would also need to set up a global variable that is incremented each snapshot point. Your BehaviorSpace settings would then use that counter for the stop condition.
I'm not sure I understand your question, but usually you will have a Setup function and a Run function, correct? So I'm guessing the code structure below should be kind of what you are looking for. I haven't used netlogo in a while so the exact matrix code you'll have to figure out yourself.
globals your-1by6-matrix your-100by6-matrix
to setup
;reset your experiment
end
to run
;run your experiment
end
to run100times
repeat 100[
setup
run
;save your 1by6matrix into your 100by6matrix
]
;use your 100by6matrix to plot or export
end

Take trip time of cars in netlogo

I need to count ticks each car takes from start of trip till end of trip. I am working on showing road bloackade simulation in netlogo. For this trip time of cars is needed to be calculated.
For this I have made following code:
to-report start-journey-time
report min-pxcor
end
to-report end-journey-time
report max-pxcor
end
The current value of the tick counter is access with the reporter ticks. Note that this is different from tick, which is used to increment the counter.
So, assuming each car has a variable called journey-time, you can do something like this. When the journey starts: set journey-time ticks, and when the journey finishes set journey-time ticks - journey-time. This is not great code since you are using the same variable for both the start time and the duration, but it saves a variable. If you want more readable code, use separate variables.

NETLOGO: Storing and using the value of a variable in the last 3 ticks

I am trying to model a stock market. I am trying to give agents a certain kind of behaviour to base their prediction of the prices on.
So basically, every agent predicts the price of the share. In the Setup procedure, a random predicted price is assigned to each agent. As the time passes, the predicted price is supposed to be calculated as follows:
total of predicted price of the last 3 periods / 3
I don't know how to approach this issue. I tried using the last command but it does not work. I was thinking about making a sort of vector but I couldn't do so. Any leads?
This is what I have tried so far:
ask turtles [
set pre-price (pre-price + last [pre-price] of turtles + last [last [pre-price] of turtles] of turtles) / 3 ]
end
The last command does not work as I want it to work because I have tried to manually calculate the results and they don't reconcile with this command. Any idea on how to go about it?
Thank you!
This is actually a very interesting bug.
The issue is that inside your turtle call, you assume all the turtles "pre-price" is static; however, with each agent, they are assigning the variable.
I'd suggest to introduce another variable which explicitly stores the pre-prices for each tick (using a matrix/nested list)