NetLogo Behavior Space doesn't count one of my breeds - netlogo

I'm working on a model to simulate tick bites in the Netherlands. My code is finished and now I want to use Behavior Space to generate output files. I've got two breeds in my model, 'residents' and 'tourists-2d'. From both breeds, I want to count how many turtles got a tick bite. The residents-breed is working but the tourists-breed isn't. Can anybody help me how to fix this? I think it is because my tourists-breed comes from a list but I don't know how to fix it. Even if I simply use 'count tourists-2d', the output of Behavior Space is 0.
globals [ month month-day week week-day tourist-2d-list ]
breed [ residents resident ]
breed [ tourists-2d tourist-2d ]
to setup
ca
file-close-all
reset-ticks
; ---------- Creating tourist-lists -----------
set tourist-2d-list (list 1 1 2 4 8 17 38 85 188 420 935 2086 4651 10371 18750 18750 10371 4651 2086 935 420 188 85 38 17 8 4 2 1 1)
end
to go
set month ceiling(ticks / 30)
set month-day (ticks mod 30)
set week ceiling(ticks / 7)
set week-day (ticks mod 7)
; ---------- Set tick dynamics per month ----------
if month = 13 and month-day = 1 [reset-ticks]
; ---------- Set 2-day tourist dynamics per week ----------
initialize-tourists-2d
tick
remove-tourists
end
to initialize-tourists-2d
if week-day = 6 [
if week > 14 and week < 45 [
create-tourists-2d item (week - 15) tourist-2d-list [set color pink set shape "person" setxy -14 -7 set stay-period 2 set day-counter 0 ]
]
]
end
to remove-tourists
ask tourists-2d [set day-counter (day-counter + 1)
if day-counter = stay-period [die]
]
end
Additional info to my code, tourist-2d-list is a global and tourists-2d a breed. It would be great if somebody could help me!

Please post a minimal working example for such a question. This would look like the following:
globals [tourist-2d-list week-day week]
breed [tourists-2d tourist-2d]
to setup
set tourist-2d-list (list 1 1 2 4 8 17 38 85 188 420 935 2086 4651 10371 18750 18750
10371 4651 2086 935 420 188 85 38 17 8 4 2 1 1)
reset-ticks
end
to go
if (ticks > (45 * 7)) [stop]
set week-day ticks mod 7
set week (int ticks / 7)
add-tourists
tick
end
to add-tourists
if week-day = 6 and week > 14 and week < 45 [
create-tourists-2d item (week - 15) tourist-2d-list [init-tourist]
print (count tourists-2d) ;print to debug
]
end
to init-tourist
; put initializations here
end
As you can see, the count is not zero.

Related

NetLogo Random values based on probabilities in list

I try to figure out, how to create an output that has an equal distribution on the random sample. Based on the code snippet below, the function creates three random numbers for three items in a list. This values gets than compared to each other, and the maximal value of them, gets count. However I am trying to figuring out how to control the randomness by a probability for example 50% (50) 25% (25) 25% (25) N=100.
to numberGenerator
let i 0
set counter_red 0
set counter_blue 0
set counter_green 0
while [i < 100] [
let numberS_red1 random-float 1
let numberS_blue1 random-float 1
let numberS_green1 random-float 1
let usedcolors [red blue green]
let OPstrength1 ( list numberS_red1 numberS_blue1 numberS_green1)
let strategies (map list usedcolors OPstrength1)
print strategies
if (numberS_red1 > numberS_blue1) and (numberS_red1 > numberS_green1)
[set counter_red counter_red + 1]
if (numberS_blue1 > numberS_red1) and (numberS_blue1 > numberS_green1)
[set counter_blue counter_blue + 1]
if (numberS_green1 > numberS_red1) and (numberS_green1 > numberS_blue1)
[set counter_green counter_green + 1]
set i i + 1
]
print counter_red
print counter_blue
print counter_green
end
counter_red = 26
counter_blue = 36
counter_green = 38
you can implement a new function using the netlogo random-normal command which assigns a color. Documentation for the function is at link

When extra turtle is created turtle-own variable value increases when it shouldn't

I have a number of global variables where values are set and a number of turtle-own variables where an initial value is set but change by the associated global variable once the model beings to run.
For example:
globals [dis-id]
turtles-own [identity]
to determine-parameters
set dis-id -1
ask turtles [
set identity 0
end
So when a turtle acts its identity goes up or down 1 depending on how successful an action has been.
So say an action was successful, identity should move from 0 to -1. If it is successful again it will move -1 to -2 etc. and vice-versa for failure 0 to 1, 1 to 2 etc.
My problem is that for every turtle that is added to the model (either created from the observer when running or setup procedure) this amount of change increases.
1 turtle 0 to 1, 1 to 2, 2 to 3 (correct + 1)
2 turtles 0 to 2, 2 to 4, 4 to 6 (incorrect + 2)
3 turtles 0 to 3, 3 to 6, 6 to 9 (incorrect + 3)
etc.
If the global variable is -6 instead of 1 i.e.
globals [dis-id]
turtle-own [identity]
to determine-parameters
set dis-id -6
ask turtles [
set identity 0
end
The same pattern occurs
1 turtle 0 to 6, 6 to 12, 12 to 18 (correct + 6)
2 turtles 0 to 12, 12 to 24, 24 to 36 (incorrect + 12)
3 turtles 0 to 18, 18 to 36, 36 to 54 (incorrect + 18)
etc.
The procedure/calculation to determine identity is
to succeed
ask turtles [
if outcome > expectation [
set identity (identity - dis-id)]
]
end
to fail
if outcome < expectation [
ask turtles [
set identity (identity - dis-id)]
]
end
This problem is consistent for every turtle-own variable calculated the same way.
I have attempted many fixes to no avail.
Any help with this would be much appreciated!
If any further explanation or code is needed to help problem solve this please let me know as I'm not sure how much or how little code I should put here. FYI the actual code is quite long.
UPDATE
the bit of code that was the problem was
to dothething
ask turtles [
if X >= Y [
succeed
fail]
]
Thank you to JenB for pointing this out!

Netlogo: How to get the weight of the link

I got a set of turtles with links connected to each other. I wanted to retrieve the weight of the link between two nodes, i've tried searching but couldn't find any info on how to do it. I'm not using nw cause i don't want the shortest path. Any ideas? This is a section of my code:
to calculate-oldpath
let oldList [ 25 0 1 2 3 4 9 8 7 6 5 10 11 12 13 14 19 18 17 16 15 20 21 22 23 24]
let weighted-dist 0
( foreach ( but-last oldList ) ( but-first oldList ) [
[ a b ] ->
ask turtle a [
let node-link link-with turtle b
;Then retrieve weight link to do adding
]
] )
print weighted-dist
end
enter image description here
The S is my starting point (25 in the list) and E is end (24 in the list) I wanted to calculate the weight of this "orange path"
Jen's answer about how to get the weight of a link is correct, but I would suggest an alternative way of computing the sum of these weights: using the sum primitive!
This requires turning your foreach into a map, but aside from that, it's pretty straightforward:
let weighted-dist sum (map [ [a b] ->
[ [ weight ] of link-with turtle b ] of turtle a
] (but-last oldList) (but-first oldList))
Another small comment: using a list of who numbers might not be the best way to approach things, but I don't know enough about your problem to suggest an alternative...
Assuming you called the weight weight (in your links-own statement that you haven't shown) then something like this should work:
to calculate-oldpath
let oldList [ 25 0 1 2 3 4 9 8 7 6 5 10 11 12 13 14 19 18 17 16 15 20 21 22 23 24]
let weighted-dist 0
( foreach ( but-last oldList ) ( but-first oldList ) [
[ a b ] ->
ask turtle a [
let node-link link-with turtle b
set weighted-dist weighted-dist + [weight] of node-link
]
] )
print weighted-dist
end
Getting the attribute value for a link is exactly the same as getting the attribute value for a turtle or patch, you use of

NetLogo histogram data

I tried posting this to the NetLogo user group on Yahoo but wasn't successful in getting the post accepted. So I'm trying here.
NetLogo can plot histograms. Is there any way to get access to the histogram data, i.e., the data generated for the histogram plot? Thanks.
Happy Holidays, Russ!
I don't think it's possible to get the values. Though if you wanted to implement your own histogram for data, you could use something like:
to-report calc-histogram [ aList numBars aMaxValue ]
let minValue min aList
let interval (aMaxValue - minValue) / numBars
let hist []
foreach n-values numBars [?] [
let lowerBound minValue + (? * interval)
let upperBound lowerBound + interval
let x (lowerBound + upperBound) / 2
let y length filter [? >= lowerBound and ? < upperBound] aList
set hist lput (list x y ) hist
]
report hist
end
example usage:
observer> calc-histogram [0 1 18 2 3 4 5 6 7 7 7 9 10 7 15 7 17 18 19 ] 5 20
observer: [[2 4] [6 8] [10 2] [14 1] [18 4]]

How to ask turtles to do different actions according to ticks

I want to ask you if the time step of my model is per month , and I want to divide the actions , the first 6 months the turtle will do some thing and the second six months other action,
what I know if I want to ask the turtle to do every 6 months the same action
if ticks mod 6 = 0
Thanks in advance
If I'm understanding your question right, you can just do:
if ticks < 6 [
do-one-action
]
if ticks >= 6 [
do-other-action
]
Edit: Just saw your comments. If you want to alternate actions every 6 ticks, you could do:
if ticks mod 12 < 6 [
do-one-action
]
if ticks mod 12 >= 6 [
do-other-action
]
If ticks tells us the number of months that have passed in the simulation, then ticks mod 12 tell us which month in the current year it is (e.g. 0, 1, 2, ... 11). So if ticks mod 12 < 6 says "if we're in the first 6 months of the current year".