Witnessing an Event
WHAT IS IT?
Two streams of turtles move on perpendicular roads. The turtles are either green, white, or red. Red turtles are witnesses, and when they meet other turtles they report the incident to a set of bar graphs across the bottom of the canvas.
HOW TO USE IT
Pressing setup returns the program to its original state. Go starts the turtles walking and spreading out if they are crowded. Red turtles also grab other turtles and report their colors on the graph. Three sliders control the numbers of red, green, and white turtles. One slider controls a global value of credibility.
THINGS TO NOTICE
An incident happens when a red turtle grabs a white or green turtle. The 'eyewitnesses' are actually the initiators of these contacts. This program appears to be quite complicated, and there are many lines of code controlling the graphics. The actual part of the program controlling whether a witness reports accurately or not is in two lines that begin with the words "if probability" in the definitions for report-green and report-falsegreen in the turtle procedures. Both lines depend entirely on a random number created at that time.
EXPLORATIONS
Does this program tell us anything aboout the reliability of witnesses? Can we write a program that model witness behavior more effectively? Design a model where incidents happen, and the reliability of witnesses is inversely proportional to their proximity to the incident. Averaging their reports might give interesting results.
STARLOGO FEATURES
The bar graphs are created and maintained in an original and interesting way. Turtles record their locations, jump to the next position on the graph, stamp it, and jump back to their original locations.
The line: ifelse who >= (random count-turtles) [ setswitch true ][ setswitch false ] is interesting in that it looks like it distributes true and false values randomly, but it weights the values based on the who value of the turtle. There is also an artifact that arises from the use of asking turtles to die in setup rather than clearing turtles, their who numbers are not reassigned.
Turtle procedures
to go
change-speed ;Sets speed of all turtles randomly between .5 and 1 by tenths.
test-switch ;Assigns true and false values to turtles' switch variables.
if (heading = 0) [ change-verticallanes ]
if (heading = 90)
[ change-horizontallanes]
if ((pc-ahead = blue) and (who mod 2) = 0) ;performs verticle wrap
[ setycor -13 ]
move
witness
end
;;Test-switch assigns random true or false values to a turtle's switch variable.
;;This is not a fair coin-toss, low who numbers favor false, highs favor true.
;;Switch is used only to place turtles to the left or right side of their lane.
to test-switch
ifelse who >= (random count-turtles) [ setswitch true ][ setswitch false ]
end
to move
fd speed
end
to witness
if color = red
[grab one-of-turtles-here
[if ((color-of partner) = green)
[report-truegreen report-green]
if ((color-of partner) = white)
[report-falsegreen]]]
end
to report-truegreen
setturtlex xcor
setturtley ycor
setxy truegreenx -22
stamp green
settruegreenx truegreenx + 1
setxy turtlex turtley
end
to report-green
setprobability random 99
if probability > (99 - credibility) ;credibility comes from a slider
[ setturtlex xcor
setturtley ycor
setxy greenx -29
stamp (green + 4)
setgreenx greenx + 1
setxy turtlex turtley]
end
to report-falsegreen
setprobability random 99
if probability < 5
[ setturtlex xcor
setturtley ycor
setxy falsegreenx -37
stamp (yellow )
setfalsegreenx falsegreenx + 1
setxy turtlex turtley]
end
to place-odds ;called during setup in the observer procedures.
seth 0 jump 14 seth 90 jump random 50
end
to change-horizontallanes
if (((switch = true) and
(count-turtles-here > 1))
and (ycor != 23))
[ set xcor xcor + 1 setycor ycor + 1 ]
if (((switch = true) and
(count-turtles-here > 1))
and (ycor = 23))
[ set xcor xcor + 1 setycor ycor - 10 ]
if (((switch = false) and
(count-turtles-here > 1))
and (ycor != 7))
[ set xcor xcor + 1 setycor ycor - 1 ]
if (((switch = false) and
(count-turtles-here > 1))
and (ycor = 7))
[ set xcor xcor + 1 setycor ycor + 10 ]
end
to change-verticallanes
if (((switch = true) and
(count-turtles-here > 1))
and (xcor != 14))
[ set xcor xcor + 1 setycor ycor + 1 ]
if (((switch = true) and
(count-turtles-here > 1))
and (xcor = 14))
[ set xcor xcor - 15 setycor ycor + 1 ]
if (((switch = false) and
(count-turtles-here > 1))
and (xcor != -15))
[ set xcor xcor - 1 setycor ycor + 1 ]
if (((switch = false) and
(count-turtles-here > 1))
and (xcor = -15))
[ set xcor xcor + 15 setycor ycor + 1 ]
end
to change-speed ;Despite the if statements, all turtles are treated the same.
if who <= 50
[ setspeed (.5 + ((random 6) / 10)) ]
if (who >= 51) and (who <= 100)
[ setspeed (.5 + ((random 6) / 10)) ]
if (who >= 101) and (who <= 200)
[ setspeed (.5 + ((random 6) / 10)) ]
if (who >= 201) and (who <= 300)
[ setspeed (.5 + ((random 6) / 10)) ]
if (who > 300) and (who <= 400)
[ setspeed (.5 + ((random 6) / 10)) ]
if (who > 400) and (who <= 500)
[ setspeed (.5 + ((random 6) / 10)) ]
if (who > 500) and (who < 602)
[ setspeed (.5 + ((random 6) / 10)) ]
end
Observer procedures
globals [ truegreenx greenx falsegreenx
probability]
turtles-own [ speed switch turtlex
turtley ]
patches-own [ background ]
to setup
ask-turtles [ die ]
Ask-patches [if ycor = -22 [setpc black] ;erases last graph
if ycor = -29 [setpc black]
if ycor = -37 [setpc black]]
create-and-do eye-witnesses
[ setc red ifelse (who mod 2) = 0
[ seth 0 jump random 40 ] [place-odds]]
create-and-do green-shirts
[ setc green ifelse (who mod 2) = 0
[seth 0 jump random 40] [place-odds]]
create-and-do white-shirts
[ setc white ifelse (who mod 2) = 0
[seth 0 jump random 40] [place-odds]]
settruegreenx -50 ;these lines set up the bar graph at the bottom of the canvas.
setgreenx -50
setfalsegreenx -50
end
to save-background
ask-patches [ setbackground pc ]
end
to monitor1
output count-pc green
end
to monitor2
output count-pc green + 4
end
to monitor3
output count-pc yellow
end
to monitor4
output (monitor3 / (monitor2 + monitor3 )) * 100
end
