turtles-own [ clock ;; each firefly's clock threshold ;; the clock tick at which a firefly stops its flash reset-level ;; the clock tick a firefly will reset to when it is triggered by other flashing window ;; a firefly can't reset its cycle if (clock <= window) ] globals [ ticks ] to setup ca init-plot set ticks 0 cct number [ setxy (random-float screen-size-x) (random-float screen-size-y) set clock random (round cycle-length) set threshold flash-length ifelse strategy = "delay" [ set reset-level threshold set window -1 ] [ set reset-level 0 set window (threshold + 1) ] recolor ] go end to go ask turtles [ move increment-clock if ( (clock > window) and (clock >= threshold) ) [ look ] ] ask turtles [ recolor ] do-plot set ticks (ticks + 1) end to recolor ; turtle procedure ifelse (clock < threshold) [ set color yellow ] [ ifelse show-dark-fireflies? [ set color gray ] [ set color black ] ] end to move ; turtle procedure rt random-float 90 - random-float 90 fd 1 end to increment-clock ; turtle procedure set clock (clock + 1) if clock = cycle-length [ set clock 0 ] end to look ; turtle procedure if ( count turtles in-radius 1 with [ color = yellow ] >= flashes-to-reset ) [ set clock reset-level ] end to init-plot set-current-plot "Flashing Fireflies" set-plot-y-range 0 number end to do-plot set-current-plot-pen "flashing" plot count turtles with [ color = yellow ] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Fireflies model. ; http://ccl.northwestern.edu/netlogo/models/Fireflies. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/Fireflies ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 301 18 666 404 35 35 5.0 0 10 1 1 1 CC-WINDOW 305 423 654 515 Command Center MONITOR 34 157 106 206 ticks ticks 0 1 SLIDER 7 95 162 128 number number 0 2000 1500 1 1 NIL SLIDER 67 273 224 306 cycle-length cycle-length 5 100 10 1 1 NIL SLIDER 159 230 295 263 flash-length flash-length 1 10 1 1 1 NIL SLIDER 18 232 152 265 flashes-to-reset flashes-to-reset 1 3 1 1 1 NIL BUTTON 14 50 102 83 setup setup NIL 1 T OBSERVER SWITCH 120 184 302 217 show-dark-fireflies? show-dark-fireflies? 0 1 -1000 BUTTON 122 50 210 83 go go T 1 T OBSERVER PLOT 10 311 277 516 Flashing Fireflies Time Number 0.0 100.0 0.0 1500.0 true false PENS "flashing" 1.0 0 -65536 true CHOICE 137 136 275 181 strategy strategy "delay" "advance" 0 @#$#@#$#@ WHAT IS IT? ----------- This model demonstrates a population of fireflies which synchronize their flashing using only the interactions between the individual fireflies. It is a good example of how a distributed system (i.e. a system with many interacting elements, but no 'leader') can coordinate itself without any central coordinator. Each firefly constantly cycles through its own clock, flashing at the beginning of each cycle and then resetting the clock to zero once it has reached the maximum. At the start of each simulation all fireflies begin at a random point in their cycles (though they all have the same cycle lengths) and so flashing will occur erratically through the population. As fireflies perceive other flashes around them they are able to use this information to reset their own clocks to try and synchronize with the other fireflies in their vicinity. Each firefly uses the same set of rules to govern its own clock, and depending on the parameters of the simulation, the population may synchronize more or less effectively. Though most species of firefly are not generally known to synchronize in groups, there are some (for example, Pteroptyx cribellata, Luciola pupilla,and Pteroptyx malaccae) that have been observed to do so in certain settings. This model generalizes two main strategies used by such insects to synchronize with each other (phase delay and phase advance synchronization, as described below), retaining the essentials of the strategies while downplaying biological detail. HOW TO USE IT -------------- GO: starts and stops the simulation. SETUP: resets the simulation according to the parameters set by the sliders. NUMBER: sets the number of fireflies to be created. CYCLE-LENGTH: sets the length of each firefly's clock before it resets to 0. NUMBER-FLASHES: sets the number of flashes a firefly must see in a single tick before its clock resets. FLASH-LENGTH: sets the duration, in ticks, of each flash. STRATEGY: sets the synchronization strategy to be used. One value is phase delay, where upon seeing NUMBER-FLASHES flashes a firefly will reset its clock to the FLASH-LENGTH tick (just after a flash would normally occur). This causes the firefly to synchronize with the next flash of the firefly it is responding to. The other value is phase advance, where upon seeing NUMBER-FLASHES flashes a firefly will reset its clock to zero. This causes the firefly to flash immediately. Under phase advance, fireflies can only begin to reset their clocks during a window which begins two ticks after they have flashed. This assures that flashes do not get stuck in a short cycle where they persistenly reset their clocks and stay lit indefinitely. SHOW-DARK-FIREFLIES: if switch set to on, non-flashing fireflies are displayed in grey. If switch set to off, non-flashing fireflies are colored black and, thus, invisible. All settings (except SHOW-DARK-FIREFLIES) must be set before pressing the SETUP button. Changes to the sliders (except SHOW-DARK-FIREFLIES) will have no effect on a simulation in progress. THINGS TO NOTICE ---------------- Using the default settings (number: 1500, cycle-length: 10, flash-length: 1, number-flashes: 1, strategy: "delay"), notice how local clusters of synchronization begin to form. See if you can figure out where each cluster is represented on the plot. As the simulation proceeds, try to determine which local cluster will eventually 'take over' the population. Did this cluster originally have the highest spike on the plot? In phase advance simulations, why do the plots generally top off before the peaks reach the entire population? In this model fireflies cannot reset their cycle when they are in the middle of a flash. Why was this restriction imposed? THINGS TO TRY ------------- Change the strategy choice between "delay" and "advance" while keeping the other settings steady (in particular, keep NUMBER-FLASHES at 2). Which strategy seems more effective? Why? Try adjusting NUMBER-FLASHES between 0, 1 and 2 using both phase delay and phase advance settings. Notice that each setting will give a characteristically different plot, and some of them do not allow for synchronization at all (for example, with the delay strategy, contrast NUMBER-FLASHES set to 1 as opposed to 2). Why does this control make such a difference in the outcome of the simulation? Changing the number of fireflies in a simulation affects the density of the population (as does adjusting the size of the graphics screen). What effect does this have on a simulation? EXTENDING THE MODEL ------------------- This model explores only two general strategies for attaining synchrony in such cycle-governed fireflies. Can you find any others? Can you improve the existing strategies (i.e., by speeding them up)? There are many other possible situations in which distributed agents must synchronize their behavior through the the use of simple rules. What if, instead of perceiving only other discrete flashes, an insect could sense where another insect was in its cycle (perhaps by hearing an increasingly loud hum)? What kinds of strategies for synchronization might be useful in such a situation? If all fireflies had adjustable cycle-lengths (initially set to random intervals) would it then be possible to coordinate both their cycle-lengths and their flashing? LANGUAGE FEATURES ------------------ Note the use of agentsets to count the number of nearby fireflies that are flashing: count turtles in-radius 1 with [ color = yellow ] CREDITS AND REFERENCES ---------------------- Buck, John. (1988). Synchronous Rhythmic Flashing of Fireflies. The Quarterly Review of Biology, September 1988, 265 - 286. Carlson, A.D. & Copeland, J. (1985). Flash Communication in Fireflies. The Quarterly Review of Biology, December 1985, 415 - 433. To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Fireflies model. http://ccl.northwestern.edu/netlogo/models/Fireflies. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Fireflies for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 arrow true 0 Polygon -7566196 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150 box true 0 Polygon -7566196 true true 45 255 255 255 255 45 45 45 circle true 0 Circle -7566196 true true 35 35 230 person false 0 Circle -7566196 true true 155 20 63 Rectangle -7566196 true true 158 79 217 164 Polygon -7566196 true true 158 81 110 129 131 143 158 109 165 110 Polygon -7566196 true true 216 83 267 123 248 143 215 107 Polygon -7566196 true true 167 163 145 234 183 234 183 163 Polygon -7566196 true true 195 163 195 233 227 233 206 159 spacecraft true 0 Polygon -7566196 true true 150 0 180 135 255 255 225 240 150 180 75 240 45 255 120 135 thin-arrow true 0 Polygon -7566196 true true 150 0 0 150 120 150 120 293 180 293 180 150 300 150 truck-down false 0 Polygon -7566196 true true 225 30 225 270 120 270 105 210 60 180 45 30 105 60 105 30 Polygon -8716033 true false 195 75 195 120 240 120 240 75 Polygon -8716033 true false 195 225 195 180 240 180 240 225 truck-left false 0 Polygon -7566196 true true 120 135 225 135 225 210 75 210 75 165 105 165 Polygon -8716033 true false 90 210 105 225 120 210 Polygon -8716033 true false 180 210 195 225 210 210 truck-right false 0 Polygon -7566196 true true 180 135 75 135 75 210 225 210 225 165 195 165 Polygon -8716033 true false 210 210 195 225 180 210 Polygon -8716033 true false 120 210 105 225 90 210 turtle true 0 Polygon -7566196 true true 138 75 162 75 165 105 225 105 225 142 195 135 195 187 225 195 225 225 195 217 195 202 105 202 105 217 75 225 75 195 105 187 105 135 75 142 75 105 135 105 @#$#@#$#@ NetLogo 2.0alpha2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@