globals [ clock edge-patches ;; used to prevent chemical from wrapping around edges of screen ] turtles-own [ carrying-food? drop-size ;; how much chemical we're currently dropping ] patches-own [ chemical food nest? nest-scent food-source-number ] ;;;;;;;;;;;;;;;;;;;;;;;; ;;; Setup Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;; to setup ca setup-turtles setup-patches set clock 0 do-plotting end to setup-turtles set-default-shape turtles "ant" cct ants [ set size 2 ;; easier to see this way rt random-float 360 set color red set carrying-food? false ] end to setup-patches set edge-patches (patches with [abs pxcor = screen-edge-x or abs pycor = screen-edge-y]) ask patches [ set chemical 0 set food 0 set food-source-number -1 setup-nest setup-food update-display ] end to setup-nest ;; patch procedure ;; set nest? variable to true inside the nest set nest? ((distancexy 0 0) < 5) ;; spread a nest-scent over the whole screen -- stronger near the nest set nest-scent (200 - (distancexy 0 0)) end to setup-food ;; patch procedure ;; setup food source one on the right of screen if ((distancexy (0.6 * screen-edge-x) 0) < 5) [ set food-source-number 1 ] ;; setup food source two on the lower-left of screen if ((distancexy (-0.6 * screen-edge-x) (-0.6 * screen-edge-y)) < 5) [ set food-source-number 2 ] ;; setup food source three on the upper-left of screen if ((distancexy (-0.8 * screen-edge-x) (0.8 * screen-edge-y)) < 5) [ set food-source-number 3 ] ;; set "food" at sources to either 1 or 2 if (food-source-number > 0) [ set food (1 + random 2) ] end to update-display ;; patch procedure ;; give color to nest and food sources ifelse nest? [ set pcolor violet ] [ ifelse (food > 0) [ if (food-source-number = 1) [ set pcolor cyan ] if (food-source-number = 2) [ set pcolor sky ] if (food-source-number = 3) [ set pcolor blue ] ] [ set pcolor scale-color green chemical 0.1 5 ] ;; scale color to show chemical concentration ] end ;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Runtime Procedures ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;; to go ;; forever button ask turtles [ go-turtles ] diffuse chemical (diffusion-rate / 100) ask edge-patches [ set chemical 0 ] ;; prevent wrapping around screen edges ask patches [ go-patches ] do-plotting set clock (clock + 1) end to go-turtles ;; turtle procedure if (who < clock) ;; delay the initial departure of ants [ ifelse carrying-food? [set color orange + 1 return-to-nest ] ;; if ant finds food, it returns to the nest [set color red look-for-food ] ;; otherwise it keeps looking ] end to go-patches ;; patch procedure set chemical (chemical * (100 - evaporation-rate) / 100) ;;slowly evaporate chemical update-display ;; Refresh the Display end to return-to-nest ;; turtle procedure ifelse nest? ;; if ant is in the nest, it drops food and heads out again [ set carrying-food? false rt 180 fd 1 ] [ set chemical (chemical + drop-size) ;; drop some chemical, but the amount decreases each time set drop-size (drop-size - 1.5) if (drop-size < 1) [set drop-size 1] uphill-nest-scent ;; head toward the greatest value of nest-scent wiggle ;; which is toward the nest fd 1] end to look-for-food ;; turtle procedure if (food > 0) [ set carrying-food? true ;; pick up food set food (food - 1) ;; and reduce the food source set drop-size 60 rt 180 stop ;; and turn around ] flatten-world ifelse (chemical > 2) [ fd 1 ] [ ifelse (chemical < 0.05) ;; go in the direction where the chemical smell is strongest [ wiggle fd 1] [ uphill-chemical fd 1] ] end to uphill-chemical ;; turtle procedure locals [scent-ahead scent-left scent-right] flatten-world wiggle ;; sniff left and right, and go where the strongest smell is set scent-ahead chemical-of patch-ahead 1 set scent-right chemical-of patch-right-and-ahead 45 1 set scent-left chemical-of patch-left-and-ahead 45 1 if ((scent-right > scent-ahead) or (scent-left > scent-ahead)) [ ifelse (scent-right > scent-left) [ rt 45 ] [ lt 45 ] ] end to uphill-nest-scent ;; turtle procedure locals [scent-ahead scent-left scent-right] flatten-world ;; sniff left and right, and go where the strongest smell is set scent-ahead nest-scent-of patch-ahead 1 set scent-right nest-scent-of patch-right-and-ahead 45 1 set scent-left nest-scent-of patch-left-and-ahead 45 1 if ((scent-right > scent-ahead) or (scent-left > scent-ahead)) [ ifelse (scent-right > scent-left) [ rt 45 ] [ lt 45 ] ] end to wiggle ;; turtle procedure rt random 40 - random 40 end to flatten-world ;; turtle procedure if (abs xcor > screen-edge-x - 1) [ set heading towardsxy-nowrap 0 ycor ] if (abs ycor > screen-edge-y - 1) [ set heading towardsxy-nowrap xcor 0 ] end to do-plotting if not plot? [ stop ] set-current-plot "Food in each pile" set-current-plot-pen "food-in-pile1" plot count patches with [pcolor = cyan] set-current-plot-pen "food-in-pile2" plot count patches with [pcolor = sky] set-current-plot-pen "food-in-pile3" plot count patches with [pcolor = blue] 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 Ants model. ; http://ccl.northwestern.edu/netlogo/models/Ants. ; 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/Ants ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 257 10 675 449 25 25 8.0 1 10 1 1 1 CC-WINDOW 5 383 249 499 Command Center BUTTON 5 10 73 43 Setup setup NIL 1 T OBSERVER T SLIDER 5 100 184 133 diffusion-rate diffusion-rate 0.0 99.0 50.0 1.0 1 NIL SLIDER 5 141 184 174 evaporation-rate evaporation-rate 0.0 99.0 15.0 1.0 1 NIL BUTTON 78 10 148 43 Go go T 1 T OBSERVER T SWITCH 156 10 246 43 plot? plot? 1 1 -1000 SLIDER 5 59 184 92 ants ants 0 200 100 1 1 NIL PLOT 5 182 248 378 Food in each pile Time Food 0.0 100.0 0.0 100.0 true false PENS "food-in-pile1" 1.0 0 -16711681 true "food-in-pile2" 1.0 0 -16745473 true "food-in-pile3" 1.0 0 -16776961 true @#$#@#$#@ WHAT IS IT? ----------- In this project, a colony of ants forages for food. Each ant follows a set of simple rules, but the colony as a whole acts in a sophisticated way. When an ant finds a piece of food, it carries the food back to the nest, dropping a chemical as it moves. When other ants "sniff" the chemical, they follow the chemical toward the food. As more ants carry food to the nest, they reinforce the chemical trail. HOW TO USE IT ------------- Click the SETUP button to set up the ant nest (in violet, at center) and three piles of food. Click the GO button to start the simulation. The chemical is shown in a green-to-white gradient. The EVAPORATION-RATE slider controls the evaporation rate of the chemical. The DIFFUSION-RATE slider controls the diffusion rate of the chemical. There is an on-off PLOT? switch. Turning off the plotting lets the model run faster. THINGS TO NOTICE ---------------- The ant colony generally exploits the food source in order, starting with the food closest to the nest, and finishing with the food most distant from the nest. It is more difficult for the ants to form a stable trail to the more distant food, since the chemical trail has more time to evaporate and diffuse before being reinforced. Once the colony finishes collecting the closest food, the chemical trail to that food naturally disappears, freeing up ants to help collect the other food sources. The more distant food sources require a larger "critical number" of ants to form a stable trail. The consumption of the food source is shown in a plot. In CYAN you see food1 which is on the right side of the screen. In BLUE you see food2 which is on the lower left of the screen. In MAGENTA you see food3 which is on the upper left of the screen. EXPLORATIONS ------------- Try different placements for the food sources. What happens if two food sources are equidistant from the nest? When that happens in the real world, ant colonies typically exploit one source then the other (not at the same time). In this project, the ants use a "trick" to find their way back to the nest: they follow the "nest scent." Real ants use a variety of different approaches to find their way back to the nest. Try to implement some alternative strategies. NETLOGO FEATURES ------------------- In the UPHILL-CHEMICAL procedure, the ant "follows the gradient" of the chemical. That is, it "sniffs" in three directions, then turns in the direction where the chemical is strongest. You might want to try variants of the UPHILL-CHEMICAL procedure, changing the number and placement of "ant sniffs." RETURN-TO-NEST uses a similar gradient. CREDITS AND REFERENCES ----------------------- This model was developed at the MIT Media Lab. See Resnick, M. (1994) "Turtles, Termites and Traffic Jams: Explorations in Massively Parallel Microworlds." Cambridge, Ma: MIT Press. Adapted to StarLogoT, 1997, as part of the Connected Mathematics Project. Adapted to NetLogo, 2000, as part of the Participatory Simulations Project. To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Ants model. http://ccl.northwestern.edu/netlogo/models/Ants. 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/Ants for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 ant true 0 Circle -7566196 true true 110 215 80 Circle -7566196 true true 110 145 80 Circle -7566196 true true 110 75 80 Line -7566196 true 150 100 80 30 Line -7566196 true 150 100 220 30 @#$#@#$#@ NetLogo 2.0beta4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@