error message "Min expected input to be a list but got the number 324 instead" when try to plot graph in Netlogo - netlogo

really need advice on this, i want to plot graph where the x-axis is evacuation time (should start from 0 until max time required for people evacuate) and y-axis is N# turtles. below is code, when all peoples leave the room, graph will plot later, however when the simulation is done, it pop-up this error message "Min expected input to be a list but got the number 324 instead. 324 is max time-to-evacuate. anywhere in the code i did wrong?please advice. thanks
globals [
time-to-exits
time-to-evacuate]
to setup
set time-to-exits []
set time-to-exits lput time-to-evacuate time-to-exits
end
to go
if (flag-active-alarm )[active-alarm]
if all? turtles [ pcolor = red ] ;stops simuation
[plot-time-to-exits
stop ]
end
to plot-time-to-exits
set-current-plot "Escape-Time"
set-plot-x-range min time-to-evacuate max time-to-evacuate
set-current-plot-pen "evacuated"
plot-pen-down
plot count turtles
end

When you wrote:
min time-to-evacuate max time-to-evacuate
I think you must have meant:
min time-to-exits max time-to-exits
time-to-exits is a list of values, so it makes sense to use min or max with it. In contrast, time-to-evacuate is just a single number.

I had a similar problem with the command min, I got it to read the list by including the list primitive.
min (list time-to-evacuate)

Related

Is Netlogo implementation of rngs:rnd-negbinomial getting the wrong results?

I'd like to use the negative binomial distribution to assign values to turtles, but the outcome seems not to be correct.
In my model I'd like to assign values with the negative binomial distribution to the breeds-own variable time-treatment of the breed children.
I used the following code for this:
extensions [ rngs ]
breed [children child]
children-own [
time-treatment
]
to setup
clear-all
rngs:init
rngs:set-seed 1 500
reset-ticks
end
to go
create-children 100 [
setxy random-xcor random-ycor
set time-treatment rngs:rnd-negbinomial 1 20 0.78
]
tick
end
When showing results and calculating the mean of time-treatment the value will be around 70.
However, according the mathematical formula for the mean, it should be r(1-p)/p = 20(1-0.78)/0.78 = 5.641... How is this possible?
The reverse formula rp/(1-p) gives 70.91 which is very close to the result you got here. I assume that is where the problem lies.
According to wikipedia there are a few alternative formulations of the negative binomial distribution.
The link you provided counts the number of failures before 20 successes happen, whereas it looks like the formula here counts the number of successes before 20 failures happen.

Netlogo: How do I make turtles of a specific breed make a decision based on previous ticks?

I'm trying to build a simulation where commuters can choose to take the car or bike to work. I'm want the turtles to make a decision based on their wait time in traffic from the last 20 ticks e.g. if average wait time is more than 10, they will take the bike to work. I have a plot that shows average wait time of cars and managed to have them make decision on that overall average. However, I have not managed to make each car make a decision based on their own experience. I'm not getting any errors, just not any results.
So far I have turtles owning average-wait-time-list and wait-time.
Create-cars ;;(cars are one of two breeds)
set average-wait-time-list []
to-report average-wait-time-sum
;; drop the first member of the list, but not until there are at least 60 items in the list
if (length average-wait-time-list > 20) [ set average-wait-time-list but-first average-wait-time-
list ]
;; add the number of raindrops created in last tick to the end of the list
set average-wait-time-list lput wait-time average-wait-time-list
report sum average-wait-time-list
end
to record-data ;; turtle procedure
ifelse speed = 0 [
set num-cars-stopped num-cars-stopped + 1
set wait-time wait-time + 1
]
[ set wait-time 0 ]
end

Netlogo: average cluster size

I have an urban growth model that outputs clusters of urban areas and want to measure them. Progress has been made to the point of plotting the frequency distribution of patch size following the code stated in this post.
Now all that is needed is to plot the average cluster size but I'm stuck in the coding. I have the idea of using the mean primitive but don't know how to make the model estimate this mean cluster size using the data that the model already outputs. Here is the current code:
to find-clusters
loop [
;; pick a random patch that isn't in a cluster yet
let seed one-of patches with [cluster = nobody
and pcolor = 8
]
;; if we can't find one, then we're done!
if seed = nobody
[
stop ]
;; otherwise, make the patch the "leader" of a new cluster
;; by assigning itself to its own cluster, then call
;; grow-cluster to find the rest of the cluster
ask seed
[ set cluster self
grow-cluster ]]
display
end
to grow-cluster ;; patch procedure
ask neighbors4 with [(cluster = nobody
and pcolor = 8
) and
(pcolor = [pcolor] of myself)]
[ set cluster [cluster] of myself
grow-cluster ]
end
and the code for estimating frequency:
to calc-frequency
let freq map [[i] -> count patches with [cluster = i]] remove-
duplicates [cluster] of patches
set-current-plot "Frequency distribution of urban patch size"
histogram freq
end
Any help will be appreciated. Thanks.
I think the object named 'freq' in your final block of code is a list of cluster sizes. If it is, then you can simply take mean freq to get the average cluster size. However, you then get into a tangle with accessing the result. If you have a global variable to store that average (called aveCluster in my code), then you can simply include a line set aveCluster mean freq.
However, a cleaner way to do it, would be to change your code block into a reporter. Something like (note that I have assumed the code for calculating sizes is correct):
to-report cluster-frequencies
report map [[i] -> count patches with [cluster = i]] remove-duplicates [cluster] of patches
end
Then you can do your histogram with histogram cluster-frequencies and the average with set aveCluster mean cluster-frequencies. Note that this will be less efficient because the list of sizes is calculated twice - once for the histogram and once for the average. If you have the two requirements close together then you can instead:
...
let freqs cluster-frequencies
histogram freq
set aveCluster mean freq
...
and it will only have to calculate once.

Accumulating per-step mortality model procedure in Netlogo

Kindly advise as to what I might be doing wrong in the following netlogo procedure for per-step mortality (I am implementing the "Pass-Away" procedure as a step in a "GO" procedure):
to Pass-Away
ask turtles [
let chances 1 - exp( -1 * mortality * ticks )
let dead-count 0
if chances >= 1 [die]
set dead-count dead-count + 1
]
end
Is the above code correct? Even if it is correct, is there a modified or better alternative means to achieve a constant (cummulative) per-time-step turtle mortality as they move through the world? Finally, how do I get the variable "dead-count" to report to a monitor on the netlogo interface?
This will mostly work, except that your dead-count will always be 1. But it will probably not work as you intend. You should embark on an exploration of what you have written. The first thing to do when you get confused is to break things into smaller pieces. The second thing is to add some helpful visuals. In this case, you will learn a lot by plotting your representation of chances. I'm going to have to guess that your mortality attribute is a random float, since you did not say so. The following is a partial fix of your code, which provides enough clues to continue. You will need to add a plot in the interface tab -- see https://subversion.american.edu/aisaac/notes/netlogo-basics.xhtml#core-concepts-plotting -- and you can add a monitor in the same way if you find monitoring with print too clunky.
globals [dead-count]
turtles-own [mortality]
to setup
ca
set dead-count 0
crt 100 [set mortality random-float 1]
reset-ticks
end
to go
ask turtles [pass-away]
print (word "dead count = " dead-count) ;easiest monitor
clear-plot ;you'll need to have added a plot
foreach sort [chances] of turtles [
[?] -> plot ?
] ;keep an eye on the largest value in this plot ... get it?
tick
end
to-report chances ;turtle proc
report 1 - exp( -1 * mortality * ticks )
end
to pass-Away ;turtle proc
if chances >= 1 [
set dead-count dead-count + 1 ;*inside* the conditional! must come first!
print (word "chances: " chances)
die
]
end

Storing / recalling the value of a variable in Netlogo

Is there a way to store / recall values of a variable in Netlogo from previous ticks?
I need a way to recall what a variable was from previous ticks. If my turtle variable R was equal to 0 the last 3 ticks, I need it to set another variable back to zero.
Here is what that I was thinking.
to regression
ask turtles [if (R = 0 from last 3 ticks [Set Oin 0 ]]
end
How about making a list of variables, then limiting the length of that list to how far back you'd like the agent to "remember"
set memory []
then add to the list each tick and get rid of old memories with
set memory lput value memory
if length memory >= 4 [set memory but-first memory]
and if zero is on the list, have that alter behavior in some way
if member? 0 memory [blah]