I'm currently working on a model where I could simulated pedestrian movement while shopping. So, I have already figure some of things I need but I have been trying to figure out how to release 2 turtles per tick (like a pair) in a certain patch. Both turtles are release at the same time. My code is base from ant lines but it just releases all the num-of-pedestrians in one time and then the turtles start walking. the ticks also start after all turtles are release. I want the turtles to start "walking" as they enter. Here is my code:
breed [ leadvisitors leadvisitor ]
breed [ visitors visitor ]
to setup
clear-all
setup-visitors
reset-ticks
end
to setup-visitors
create-leadvisitors num-of-pedestrians * 0.1 ;;create 10% of the total number of pedestrians
[
set demand-type "none"
set color black
set size 1
setxy 0 16
set heading 180
set pen-size 1
set destination one-of patches
set wait-time -1
set demand-lvl 0
]
create-visitors (num-of-pedestrians - (num-of-pedestrians * 0.1))
[ set demand-type 0
set size 1
setxy 0 16
set heading 180
set pen-size 1
set destination one-of patches
set wait-time -1
set demand-lvl 1
set attracted? false
] ]
end
to go
if turtles = 0 [ stop ]
ask turtles
[
set-demand-type
have-demand
]
if ticks > 100 [ stop ]
tick
display-labels
end
;;;;; visitor's internal state of demand ;;;;;
to set-demand-type
if demand-type = 0
[ set demand-type "food"
set color red
let target (patches in-cone visitor-vision-depth visitor-view-angle) with [pcolor = red]
]
end
to have-demand
if demand-lvl = 0
[
ifelse wait-time = -1
[ stroll ]
[ set wait-time wait-time - 1
if wait-time = 0
[ stroll ]]
]
if demand-lvl = 1
[ ifelse wait-time = -1
[ stroll
evaluate ]
[ set wait-time wait-time - 1
if wait-time = 0
[ stroll
evaluate ]]
]
end
to stroll
if any? neighbors with [ pcolor = gray - 3 ]
[ die ]
ifelse any? neighbors with [ pcolor = gray or pcolor = orange or pcolor = blue or pcolor = red]
[ facexy exitpt-x exitpt-y ]
[ rt random-float visitor-view-angle lt random-float visitor-view-angle ]
fd walking-speed
end
to evaluate
if any? neighbors with [ pcolor = gray or pcolor = orange or pcolor = blue or pcolor = gray - 4 or pcolor = gray - 3 or pcolor = red + 2]
[ facexy exitpt-x exitpt-y
rt random-float visitor-view-angle lt random-float visitor-view-angle
fd walking-speed ]
let _mycolor color
if any? (patches in-cone visitor-vision-depth visitor-view-angle) with [pcolor = _mycolor]
[ let new-target max-one-of ( patches with [pcolor = _mycolor] in-cone visitor-vision-depth visitor-view-angle) [patch-influence]
let dist-to-new-target min-one-of (patches with [pcolor = _mycolor] in-cone visitor-vision-depth visitor-view-angle) [distance myself]
face new-target
set heading towards new-target
fd walking-speed
set attracted? true
attracted-and-visiting
re-evaluate
]
end
to attracted-and-visiting
if pcolor = red + 2
[ set heading towards one-of patches with [pcolor = red + 2]
fd 0
set patch-popularity patch-popularity + 1
set wait-time avg-waiting-time
if count turtles-here > 0
[ set num-of-visitors num-of-visitors + 1 ]
set plabel num-of-visitors
]
end
to re-evaluate
let _mycolor color
if not any? (patches in-cone visitor-vision-depth visitor-view-angle) with [pcolor = _mycolor]
[ set attracted? false ]
ifelse choose? [set heading towards one-of patches with [pcolor = _mycolor]] [facexy exitpt-x exitpt-y]
end
to-report choose?
report random 2 = 0
end