I have a problem about divisible number because I want to use the number of ticks to code in my project. For example, I want the turtle to start doing something in specific time (like in every 30,60,90..., number that able to be divided by 30).
I have no idea about it so if you guys have any suggestion about it?
You'll want to use the modulos operator. In your forever go function, you could use the following code that checks whether enough ticks have passed.
if ticks mod number = 0 [ask turtles [do-something]]
Don't forget to tick your simulation at the end of your go.
Related
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.
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).
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.
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)
I have a NetLogo model, simplified to this:
to setup
clear-all
create-turtles 1000 [
fd 100
]
end
When I add a monitor widget to the UI, with a reporter like mean [xcor] of turtles and then run setup, the values in the monitor change a slight bit constantly. It might show 0.2305090322262271 one moment then 0.2305090322262268 the next, and then another similar number on and on.
What is making my monitor widget flicker or flash like this? How can I prevent it?
This is caused by a combination of a few things:
NetLogo's use of floating point numbers, which can produce small accuracy issues. See Floating point accuracy in the NetLogo programming guide: https://ccl.northwestern.edu/netlogo/docs/programming.html#math
Agentsets such as turtles are always returned in a random order.
Monitors re-run their reporter calculation constantly, even when you are not running any model code with a forever button or through the command center.
So the monitor constantly re-runs its mean [xcor] of turtles reporter, but the turtles agentset gives the turtles in a random order, and so the floating-point inaccuracies for mean will accumulate in a slightly different way each time due to the order differences. The end result is you see very slightly different numbers flashing through the monitor widget while nothing is happening.
You would see the same problem doing sum [xcor] of turtles or variance [xcor] of turtles - anytime you're reducing a bunch of floating point numbers from an agentset into a single value. You can also see the problem running your reporter code directly in the command center repeatedly, without a monitor widget at all.
The fixes are fortunately pretty easy:
Sort your numbers before you calculate: mean sort [xcor] of turtles, sum sort [xcor] of turtles, variance sort [xcor] of turtles. If the numbers are in the same order you'll still have small floating-point inaccuracies, but they'll be the the same every time so you won't see the values change. This is probably the best solution, but it can be slow if you have a really large agentset.
Change the Decimal places setting of your monitors to a number where you don't notice the changing values. Since the differences in results should be small, this is usually possible.