breeds [ leader followers ] globals [ nest-x nest-y ;; location of center of nest food-x food-y ;; location of center of food leader-heading ;; heading of the leader ant ] to setup ca set-default-shape turtles "ant" set nest-x 10 - screen-edge-x ;; set up nest and food locations set nest-y 0 set food-x screen-edge-x - 10 set food-y 0 ask patches with [ distancexy nest-x nest-y < 5 ] ;; draw nest [ set pcolor brown ] ask patches with [ distancexy food-x food-y < 5 ] ;; draw food [ set pcolor orange ] create-custom-leader 1 [ set color red ;; leader ant is red pd ;; ...and leaves a trail wiggle 50 ] ;; ...and starts out with a random heading create-custom-followers (num-ants - 1) [ set color yellow ] ;; middle ants are yellow ask turtles [ setxy nest-x nest-y ;; start the ants out at the nest set heading 90 ] ask turtle (num-ants - 1) [ set color blue ;; last ant is blue pd ] ;; ...and leaves a trail set leader-heading heading-of turtle 0 end to go if not any? turtles with [xcor < food-x] [ stop ] ask leader ;; the leader ant wiggles and moves [ wiggle wiggle-angle keep-in-bounds if (xcor > (food-x - 5 )) ;; leader heads straight for food, if it is close [ set heading towardsxy-nowrap food-x food-y ] if xcor < food-x ;; do nothing if you're at or past the food [ fd 0.5 ] ] ask followers [ if distance turtle (who - 1) > 0 [ set heading towards turtle (who - 1) ] ;; follower ants follow the ant ahead of them if time-to-start? and (xcor < food-x) ;; followers wait a bit before leaving nest [ fd 0.5 ] ] set leader-heading heading-of turtle 0 end ;; turtle procedure; wiggle a random amount, averaging zero turn to wiggle [angle] rt random-float angle lt random-float angle end ;; turtle procedure; keep the ants from wrapping the screen to keep-in-bounds ifelse heading > 180 [ rt 180 ] [ if ycor > (screen-edge-x - 5) [ rt 100 ] if ycor < (5 - screen-edge-x) [ lt 100 ] ] end ;; turtle reporter; if true, then the ant is authorized to move out of the nest to-report time-to-start? report (xcor-of (turtle (who - 1))) > (nest-x + start-delay + random start-delay ) 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 1997 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. (1997). NetLogo Ant Lines model. ; http://ccl.northwestern.edu/netlogo/models/AntLines. ; 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/AntLines ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 250 10 664 445 50 50 4.0 0 10 1 1 1 CC-WINDOW 7 290 241 473 Command Center SLIDER 31 81 209 114 num-ants num-ants 1 1000 45 1 1 NIL BUTTON 124 41 188 74 go go T 1 T OBSERVER T BUTTON 53 41 120 74 setup setup NIL 1 T OBSERVER T MONITOR 9 223 121 272 leader-heading leader-heading 0 1 SLIDER 31 149 209 182 start-delay start-delay 1 60 3 1 1 NIL SLIDER 31 115 209 148 wiggle-angle wiggle-angle 0.0 90.0 38.0 1.0 1 degrees MONITOR 123 223 229 272 ants-released count turtles with [xcor > nest-x] 3 1 @#$#@#$#@ WHAT IS IT? ----------- This project models the behavior of ants following a leader towards a food source. The leader ant moves towards the food along a random path; after a small delay, the second ant in the line follows the leader by heading directly towards where the leader is located. Each subsequent ant follows the ant ahead of it in the same manner. Even though the leader may take a very circuitous path towards the food, the ant trail, surprisingly, adopts a smooth shape. While it is not yet clear if this model is a biologically accurate model of ant behavior, it is an interesting mathematical exploration of the emergent behavior of a series of agents following each other serially. RUNNING THE MODEL ----------------- The SETUP button initializes the model. A brown ant nest is placed on the left side of the screen. Inside it are a number of ants (yellow) determined by the NUM-ANTS slider. On the right hand of the screen is an orange source of food. The GO button starts the ants moving. The leader ant (turtle 0) is set in motion roughly in the direction of the food. It wiggles as it moves. That is, it does not head directly towards the food, but changes its heading a random amount to the left or right before it takes each step. The maximum amount the leader ant can wiggle at each step (and therefore the raggedness of the leader ant's path) is governed by the WIGGLE-ANGLE slider. When the leader ant gets close enough to the food to "smell" it, it stops wiggling and heads directly for the food. The leader ant leaves a red trace as it moves. Each subsequent ant follows the ant ahead of it by heading directly towards it before it takes each step. The follower ants do not leave a trace. The yellow line of ants, however, traces out a curve on the screen. The last ant to go leaves a blue trace. The amount of time between ants departing their nest is governed by the START-DELAY slider (plus some random factor). The ANTS-RELEASED monitor shows you how many ants have left the nest. The other monitor shows you the heading of the lead ant. THINGS TO NOTICE ---------------- How does the shape of the ant line change over time? How does the path of the initial ant compare with the path of the final ant? THINGS TO TRY ------------- Try varying the maximum wiggle angle (WIGGLE-ANGLE). How does that affect the shape of initial and final ant lines? Try varying the delay. How does that affect the shape of initial and final ant lines? How can you slow down the flattening out of the ant line? Can you make the path fail to converge to a straight line? How can you speed up the flattening out of the ant line? EXTENDING THE MODEL ------------------- How might you keep track of, measure, or plot the flattening process? What if you relaxed the ant following rules -- maybe add some "wiggle" to their behavior? NETLOGO FEATURES ----------------- In NetLogo, the default behavior of the ants is to move in parallel. Notice the use of delays based on turtle ids in the TIME-TO-START? reporter to make the turtles leave the nest serially. CREDITS AND REFERENCES ------------------------ The model was inspired by the work of Alfred Bruckstein (see Bruckstein 1993: "Why the ant trails look so straight and nice", The Mathematical Intelligencer, Vol. 15, No. 2). To refer to this model in academic publications, please use: Wilensky, U. (1997). NetLogo Ant Lines model. http://ccl.northwestern.edu/netlogo/models/AntLines. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1997 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/AntLines for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 ant true 0 Polygon -7566196 true true 136 61 129 46 144 30 119 45 124 60 114 82 97 37 132 10 93 36 111 84 127 105 172 105 189 84 208 35 171 11 202 35 204 37 186 82 177 60 180 44 159 32 170 44 165 60 Polygon -7566196 true true 150 95 135 103 139 117 125 149 137 180 135 196 150 204 166 195 161 180 174 150 158 116 164 102 Polygon -7566196 true true 149 186 128 197 114 232 134 270 149 282 166 270 185 232 171 195 149 186 149 186 Polygon -7566196 true true 225 66 230 107 159 122 161 127 234 111 236 106 Polygon -7566196 true true 78 58 99 116 139 123 137 128 95 119 Polygon -7566196 true true 48 103 90 147 129 147 130 151 86 151 Polygon -7566196 true true 65 224 92 171 134 160 135 164 95 175 Polygon -7566196 true true 235 222 210 170 163 162 161 166 208 174 Polygon -7566196 true true 249 107 211 147 168 147 168 150 213 150 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ setup repeat 250 [ go ] @#$#@#$#@ @#$#@#$#@