waiting time not waiting properly(the right amount of ticks) - netlogo

This is a simulation I'm trying to run but I seem to have a problem with the waiting time (ticks).
I can't make my turtles(Shoppers) wait for the right amount of ticks, and I have found that the amount of turtles directly influences the amount of waiting time ticks.
waiting time is an attribute that tells the shoppers to stay put before they start walking towards their next destination.
extensions[gis]
breed [shopper shoppers]
breed [places place]
breed [cityts cityt]
shopper-own [person x y cid route shopper_type destination last-destination waiting_time step starting_point cityx cityy]
turtles-own [std wflag ]
places-own [shopper_type ycoor xcoor locality ]
cityts-own[shopper_type org xc yc]
patches-own[netlogo]
globals [ speed last_place]
to setup
setup_world
setup_color
ask cityts [set hidden? true]
reset-ticks
end
to go
ask shopper with [shopper_type != "rtqq"] [walk-towards]
; ask shopper with [shopper_type = "lvl2" and shopper_type ="lvl2" ] [omw]
if ticks >= 1440 [stop]
tick
end
to loc
ask cityts [
output-show ticks
output-show xcor
output-show ycor
output-show label
output-show who
]
end
to output-locations
output-show self
output-show xcor
output-show ycor
end
to walk-towards
ask shopper [
if shopper_type != "aaa" [
rep
ifelse waiting_time > 0 [
set waiting_time waiting_time - 1
set step step + 1]
[omw]] ]
end
to omw
if destination = false [fd 1]
ifelse distance destination > 0.1
[face destination
forward speed]
[move-to destination
next_place
set step 0]
end
to set_destination [NUM]
set destination min-one-of (turtles with [label = NUM] in-radius (360) )[distance myself]
end
to wt [NUM]
set waiting_time NUM + random 10 - random 10
set waiting_time waiting_time - 1
end
to setup_world
create-places 3
[
setxy random-xcor random-ycor
set label 345
]
create-places 3
[
setxy random-xcor random-ycor
set label 789
]
create-places 3
[
setxy random-xcor random-ycor
set label 3344
]
create-places 3
[
setxy random-xcor random-ycor
set label 3232
]
create-places 3
[
setxy random-xcor random-ycor
set label 1937
]
create-places 3
[
setxy random-xcor random-ycor
set label 951
]
create-places 3
[
setxy random-xcor random-ycor
set label 987
]
create-places 3
[
setxy random-xcor random-ycor
set label 234
]
create-places 3
[
setxy random-xcor random-ycor
set label 912
]
create-places 3
[
setxy random-xcor random-ycor
set label 567
]
create-places 3
[
setxy random-xcor random-ycor
set label 8529
]
create-places 3
[
setxy random-xcor random-ycor
set label 891
]
create-places 3
[
setxy random-xcor random-ycor
set label 1927
]
create-places 3
[
setxy random-xcor random-ycor
set label 1826
]
create-places 3
[
setxy random-xcor random-ycor
set label 1725
]
create-places 3
[
setxy random-xcor random-ycor
set label 456
]
create-places 3
[
setxy random-xcor random-ycor
set label 1013
]
create-places 3
[
setxy random-xcor random-ycor
set label 7891
]
create-places 3
[
setxy random-xcor random-ycor
set label 3322
]
create-places 3
[
setxy random-xcor random-ycor
set label 678
]
create-shopper 3 [
set size 1
set waiting_time 0
set shopper_type "lvl1"
set cid 1
set shape "person"
set starting_point one-of (turtles with [label = 1725])
; set xcor random-float 25
; set ycor random-float 25
; set ctiyx xcor of starting_point
; set cityy ycor of starting_point
set speed 0.1
set route random 6 ]
ask shopper [
set destination min-one-of (turtles with [label = 789 ] in-radius (360) )[distance myself]
set last-destination "boop" ]
; create-shopper 2 [
; set size 1
; set waiting_time 0
; set shopper_type "lvl2"
; set cid 7
; set shape "person"
; set xcor random-float 25
; set ycor random-float 25
; set speed 0.1
; set route random 5 ]
; ask shopper [
; set destination min-one-of (turtles with [label = 789 ] in-radius (360) )[distance myself]
; set last-destination "boop" ]
;
;
; create-ambolansces 1 [
; set size 1
; set waiting_time 0
; set shopper_type "lvl3"
; set shape "car"
; set xcor random-float 25
; set ycor random-float 25
; set speed 0.1
; set route random 3 ]
; ask shopper [
; set destination min-one-of (turtles with [label = 789 ] in-radius (360) )[distance myself]
; set last-destination "boop"]
end
to next_place
if shopper_type = "lvl1"[
if route = 0 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "345" ]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 3344] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "3344" ]
[ ifelse last-destination = "3344" [set destination min-one-of (turtles with [label = 3232] in-radius (360) )[distance myself] wt 10 walk-towards set last-destination "3232" ]
[ifelse last-destination = "3232" [set destination min-one-of (turtles with [label = 1937] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "1937" ]
[if last-destination = "1937" [set destination min-one-of (turtles with [label = 951] in-radius (360) )[distance myself] wt 80 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl1"[
if route = 1 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 100 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 10 walk-towards rep set last-destination "987" ]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 5 walk-towards rep set last-destination "234"]
[ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 951] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl1"[
if route = 2 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "912" ]
[ ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 567] in-radius (360) )[distance myself] wt 50 walk-towards set last-destination "567" ]
[ ifelse last-destination = "567" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl1"[
if route = 3 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "987" ]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 567] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "678" ]
[ ifelse last-destination = "678" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 10 walk-towards set last-destination "891" ]
[ifelse last-destination = "891" [set destination min-one-of (turtles with [label = 1927] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "1927" ]
[if last-destination = "1927" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 80 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl1"[
if route = 4 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 1937] in-radius (360) )[distance myself] wt 100 walk-towards rep set last-destination "1937" ]
[ ifelse last-destination = "1937" [set destination min-one-of (turtles with [label = 1826] in-radius (360) )[distance myself] wt 10 walk-towards rep set last-destination "1826" ]
[ ifelse last-destination = "1826" [set destination min-one-of (turtles with [label = 1725] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "1725"]
[ ifelse last-destination = "1725" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 5 walk-towards rep set last-destination "345"]
[ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 3322] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl1"[
if route = 5 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "912" ]
[ ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 0 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "345" ]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 3344] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "3344" ]
[ ifelse last-destination = "3344" [set destination min-one-of (turtles with [label = 3232] in-radius (360) )[distance myself] wt 10 walk-towards set last-destination "3232" ]
[ifelse last-destination = "3232" [set destination min-one-of (turtles with [label = 1937] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "1937" ]
[if last-destination = "1937" [set destination min-one-of (turtles with [label = 951] in-radius (360) )[distance myself] wt 80 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 1 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 100 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 10 walk-towards rep set last-destination "987" ]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 5 walk-towards rep set last-destination "234"]
[ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 951] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 2 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "912" ]
[ ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 567] in-radius (360) )[distance myself] wt 50 walk-towards set last-destination "567" ]
[ ifelse last-destination = "567" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 3 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "987" ]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 678] in-radius (360) )[distance myself] wt 10 walk-towards set last-destination "678" ]
[ ifelse last-destination = "678" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 10 walk-towards set last-destination "891" ]
[ifelse last-destination = "891" [set destination min-one-of (turtles with [label = 1927] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "1927" ]
[if last-destination = "1927" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 80 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 4 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 1937] in-radius (360) )[distance myself] wt 100 walk-towards rep set last-destination "1937" ]
[ ifelse last-destination = "1937" [set destination min-one-of (turtles with [label = 1826] in-radius (360) )[distance myself] wt 10 walk-towards rep set last-destination "1826" ]
[ ifelse last-destination = "1826" [set destination min-one-of (turtles with [label = 1725] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "1725"]
[ ifelse last-destination = "1725" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 5 walk-towards rep set last-destination "345"]
[ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 3322] in-radius (360) )[distance myself] wt 40 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl2"[
if route = 5 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 60 walk-towards rep set last-destination "912" ]
[ ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 345] in-radius (360) )[distance myself] wt 30 walk-towards rep set last-destination "345"]
[ ifelse last-destination = "345" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 70 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 8529] in-radius (360) )[distance myself] wt 50 walk-towards rep set last-destination "boop" set route random 6 ]]]]]]]]
if shopper_type = "lvl3"[
if route = 0 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "987"]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789"[set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "912"rep ]
[ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 1013] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "1013"rep ]
[if last-destination = "1013" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "boop" set route random 3 rep ]]]]]]]]
if shopper_type = "lvl3"[
if route = 1 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "234"]
[ ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "boop" set route random 3 ]]]]]]]]
if shopper_type = "lvl3"[
if route = 2 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "234"]
[ ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 20 walk-towards rep set last-destination "boop" set route random 3 ]]]]]]]]
if shopper_type = "lvl4"[
if route = 0 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "987"]
[ ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "789" ]
[ ifelse last-destination = "789"[set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 912] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "912" ]
[ifelse last-destination = "912" [set destination min-one-of (turtles with [label = 1013] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "1013" ]
[if last-destination = "1013" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "boop" set route random 3 ]]]]]]]]
if shopper_type = "lvl4"[
if route = 1 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "234"]
[ ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "boop" set route random 3 ]]]]]]]]
if shopper_type = "lvl4"[
if route = 2 [
ifelse last-destination ="boop" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "789" ]
[ ifelse last-destination = "789" [set destination min-one-of (turtles with [label = 456] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "456" ]
[ ifelse last-destination = "456" [set destination min-one-of (turtles with [label = 234] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "234"]
[ ifelse last-destination = "234" [set destination min-one-of (turtles with [label = 987] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "987"]
[ifelse last-destination = "987" [set destination min-one-of (turtles with [label = 789] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "7891" ]
[if last-destination = "7891" [set destination min-one-of (turtles with [label = 891] in-radius (360) )[distance myself] wt 20 walk-towards set last-destination "boop" set route random 3 ]]]]]]]]
END
to setup_color
ask shopper with [shopper_type = "lvl1"] [set color cyan]
ask shopper with [shopper_type = "lvl2"] [set color pink]
end
TO rep
output-show ticks
output-show xcor
output-show ycor
output-show last-destination
output-show cid
end
*this is an edited excerpt of my code I made because the original is using GIS layers for coordinates and turtle making

Related

add another turtle's id to another turtle's attribute

In the model below, a bank can only fund customers with a credit score that matches the scores in their acceptable_scores attribute. and if it doesn't match any of the banks acceptable_scores it is rejected.
globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
list_of_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set list_of_customers []
]
reset-ticks
end
to go
ask one-of banks [
fund-loan
reject-loan
]
tick
end
to fund-loan
let person one-of customers-here with [
(member? credit_score [acceptable_scores] of myself)
]
if person != nobody [
ask person [
set status "funded"
]
set list_of_customers lput person list_of_customers
]
end
to reject-loan
let person one-of customers-here with [
(not member? credit_score [acceptable_scores] of myself)
]
if person != nobody [
ask person [
set status "funded"
]
set list_of_customers lput person list_of_customers
output-print list_of_customers
]
end
I want to add each funded customer to the list_of_customers after funding here:
set list_of_customers lput person list_of_customers
but the list is always empty when printed out. What is the right way to add another turtle's id to another turtle's attribute? In general, is this the best way to handle the funding and rejection procedures? Can it be done in one function?
Here is a pared-down version of your model using agentsets. The bank behavior may not be just what you want, but it should get you started.
globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
my_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set my_customers no-turtles
]
reset-ticks
end
to go
ask banks [
fund-loan
]
ask banks [ show my_customers ]
tick
end
to fund-loan
let person one-of customers-here
ifelse (member? [credit_score] of person acceptable_scores) and ([status] of person != "funded") [
ask person [
set status "funded"
]
set my_customers (turtle-set person my_customers)
]
[
ask person [
set status "rejected"
]
]
end

what is wrong with the way I am coding the probability of surviving?

I'm trying to create a model in which turtles move through a landscape and each type of patch means a different probability of survival for the turtles (representing patches that have more resources = higher chance of survival, patches with less resources = lower chance of survival).
However, all my turtles die out super quickly and don't seem to be following the differences in the probability of survival.
The only thing I have identified is that only if they are in a patch with probability of survival = 1, they survive. If not (even if the probability is .96), they die.
The probability of survival that each type of patch represents is determined by a slider.
extensions [
gis
palette
]
patches-own [
TipoRaster
tipoDeUso
**probSupervivencia**
]
breed [bichos bicho]
to go
if not any? turtles [stop]
if ticks = 120 [stop] ;; representa un ciclo de vida de las hembras adultas (donde cada tick = 1 dia). ***180
ask turtles [
**move
if random-float 1.00 > probSupervivencia [die]**
]
tick
end
to initHabitat
if Habitat = "bichos" [
ask patches with [ tipoDeUso = "Urbano" ][
set probSupervivencia probabilidad-supervivencia-urbano
]
ask patches with [ tipoDeUso = "Nada" ][
set probSupervivencia probabilidad-supervivencia-nada
]
ask patches with [ tipoDeUso = "Bosque" ][
set probSupervivencia probabilidad-supervivencia-bosque
]
ask patches with [ tipoDeUso = "CuerposDeAgua" ][
set probSupervivencia probabilidad-supervivencia-agua
]
ask patches with [ tipoDeUso = "Pastizal" ][
set probSupervivencia probabilidad-supervivencia-pastizal
]
if calidad-matriz = "actual" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" ][
ifelse random-float 1.00 < 0.32 [ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja ][ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta ]
]
ask patches with [ tipoDeUso = "AgriculturaRiego" ][
ifelse random-float 1.00 < 0.63 [ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja ][ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta ]
]
]
if calidad-matriz = "alta" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" or tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta
]
]
if calidad-matriz = "baja" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" or tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja
]
]
if calidad-matriz = "contrastante" [
ask patches with [ tipoDeUso = "AgriculturaTemporal"][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta
]
ask patches with [ tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja
]
]
]
end
**to move**
if random 100 < 10 [move-to one-of patches in-radius (tasa-movimiento / longitud-step)]
end
Can anybody figure out what it is I am doing wrong?
Your agents need to inquire about the patch they occupy.
Something like
ask turtles [
if ([probSupervivencia] of patch-here < random-float 1.00) [die]
]

how to identify the breed of a turtle within a dynamic agentset by using a foreach loop in netlogo?

I am trying to scan all the turtles in the vicinity of a turtle and if they are eligible, and if the ratios of the different breeds within a cluster of size greater than 10 turtles is okay, then I link the turtle up with the leader of the cluster.
But I am having trouble identifying the breed of each item within the agentset 'candidates', which is a list of all turtles within the vicinity of the turtle I am asking. According to the breed of the item/turtle, I want to execute a command block.
Can anyone help please?
let candidates turtles in-radius radius_scan with [ leader != [leader] of myself and exempt_from_immobilisation = false and aggregated = false]
if (any? candidates) ;; if there are candidates around and the cluster is too small, then proceed to increase the size of the cluster without taking into account any ratios
[
ifelse
length(aggregate-list) < 10 [
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
create-links-with candidates [show-link ]
ask candidates [
set aggregated true
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
;set aggregate-list lput myself aggregate-list
merge ]
]
[ ;; if cluster is big enough, start checking if the ratios are approximately making sense
(foreach candidates [ t ->
;let t-breed breed of t
(ifelse
breed = sykfactive [
ifelse ( ( (length(filter is-monomer1? aggregate-list)) + (length(filter is-dimer2? aggregate-list)) + (length(filter is-monomer2syk1active_crosslink? aggregate-list))) <= ( (length(filter is-sykfactive? aggregate-list)) + 5 ))
[
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
create-links-with t [show-link ]
ask t [
set aggregated true
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
;set aggregate-list lput myself aggregate-list
merge ]
]
[;;else commands
print "nothing to print or do"
]
]
is-monomersykactive? [
if ( (length(filter is-monomersykactive? aggregate-list)) <= ( (length(filter is-monomer1? aggregate-list)) + 5 ))
[
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
create-links-with t [show-link ]
ask t [
set aggregated true
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
;set aggregate-list lput myself aggregate-list
merge ]
]
]
is-dimer2syk1active? [
if ( ( (length(filter is-monomer1? aggregate-list)) + (length(filter is-dimer2? aggregate-list)) ) >= ( (length(filter is-dimer2syk1active? aggregate-list) + 5 )) )
[
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
create-links-with t [show-link ]
ask t [
set aggregated true
if who not member? aggregate-list [ set aggregate-list lput myself aggregate-list ]
;set aggregate-list lput myself aggregate-list
merge ]
]
]
[;;else commands
print "nothing to print or do"
])
]
)
]
]
I can't work out what all the filtering and merging is supposed to do so I can't fix your code directly. Breed is a variable of the turtle in the same way as any other attribute, so I would count the different breeds and store that in local variables, then use the local variables for the if/then decisions.
Something like (assumes there are two breeds called breedA and breedB):
if any? candidates
[ let numA count candidates with [breed = breedA]
let numB count candidates with [breed = breedB]
if numA < numB / 2
[ print "A is rare here"
]
]
If you want to do something specifically with the different candidate types, then you can subset candidates by breed and do the counting after:
if any? candidates
[ let candidatesA candidates with [breed = breedA]
let numA count candidatesA
let candidatesB candidates with [breed = breedB]
let numB count candidatesB
if numA < numB / 2
[ ask candidatesA
[ set color red
]
]
]

Expected Command

I think this is an error somewhere in my brackets, but I am not sure where this error is located.
to feed
let prey one-of humans-here
if prey != nobody [
[ifelse random-float 1 <= zombie-victory-probability
ifelse random-float 1 <= conversion-probability
[ ask prey [ convert ] ]
[ ask prey [ die ] ]
[ die ]
]]
end
Hard to say for sure as I can't test without seeing your setup code, but maybe like this?
to feed
let prey one-of humans-here
if prey != nobody [
ifelse random-float 1 <= zombie-victory-probability
[ ifelse random-float 1 <= conversion-probability ; option a1
[ ask prey [ convert ] ] ; option b1
[ ask prey [ die ] ] ; option b2
]
[ die ] ; option a2
]
end

Query / create subset of turtles for each turtle

I have an agentset where all the turtles have different values for age/experience. What I would like to do is find the more experienced turtles for each turtle and then follow those turtles. Unfortunately, I get the following error for the ifelse [ age-experience > my-own-age-experience ] line:
Expected a TRUE/FALSE here, rather than a list or block.
Here's my code:
turtles-own [
age-experience
more-dominant
dominant-flockmates
]
to setup
clear-all
create-turtles 10 [ set age-experience random-float 1 ]
reset-ticks
end
to go
ask turtles [
find-dominant-flockmates
ifelse any? dominant-flockmates
[ show "follow the more dominant flockmates" ]
[ show "take the lead" ]
]
tick
end
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles [
ifelse [ age-experience > my-own-age-experience ]
[ set more-dominant true ]
[ set more-dominant false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
Okay, you have several choices here. You can get rid of the error by removing the []
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles [
ifelse age-experience > my-own-age-experience
[ set more-dominant true ]
[ set more-dominant false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
But there's much more efficient ways to code this. If you are going to use the variable more-dominant for other purposes (so you need it), you can use ifelse-value like this (and because it's true/false, you don't actually need ifelse-value but it's a good thing to know about):
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles
[ set more-dominant ifelse-value (age-experience > my-own-age-experience)
[ true ]
[ false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
But if the only reason to have the variable is to create the agentset, you can do the whole thing directly:
to find-dominant-flockmates
let my-own-age-experience age-experience
set dominant-flockmates other turtles with [ age-experience > my-own-age-experience ]
end