patches-own [chemical food nest? nest-scent food-source-number] turtles-own [carrying-food? drop-size ahead scent-left scent-right] globals [clock] constants [ food1 [1] food2[2] food3 [3]] ;;sets food1=1, food2=2, food3=3 to setup ;;ca da laby zuerst gezeichnet wird setup-turtles setup-patches setclock 0 setup-plot end to setup-turtles ;create ants at the center crt 100 setxy 0 0 setc red seth random 360 setcarrying-food? false end to setup-patches setchemical 0 setup-nest setup-food update-display end to setup-nest setnest? ((distance 0 0) < 5) ;;sets nest? to 0 (true) inside the nest setnest-scent 200 - (distance 0 0) ;;spreads a nest-scent over the whole screen -- ;;stronger near the nest end to setup-food ;;sets up food sources with patches setfood 0 setfood-source-number -1 ;; setup food source one ;; on the right side of screen if ((distance (0.6 * screen-edge) 0) < 5) [setfood 1 + random 2 ;;set "food" of patches between 1 and 2 setfood-source-number food1] ;;indicates it's food in pile # 1 ;; setup food source two ;; on the lower-left of screen if ((distance (-0.5 * screen-edge) (-0.5 * screen-edge)) < 5) [setfood 1 + random 2 setfood-source-number food2] ;; setup food source three ;; on the upper-left of screen if ((distance (-0.8 * screen-edge) (0.8 * screen-edge)) < 5) [setfood 1 + random 2 setfood-source-number food3] end to update-display ;;gives color to nest and food sources ifelse nest? [setpc violet] [ifelse food > 0 [if(food-source-number = food1) [setpc 85] if(food-source-number = food2) [setpc 95 ] if(food-source-number = food3) [setpc 105]] [if pc != 5 [scale-pc green chemical 0.1 5]]] ;; [scale-pc green chemical 0.1 5]] ;;scales color where chemical is not zero end ;; schauen ob schildi auf einem labyrinth steht. grau=5, wenn ja umdrehen! to step if pc = 5 [rt 180 fd 1 unstep] fd 1 end to unstep if pc = 5 [ lt 45 lt random 45 fd 1 if pc = 5 [ rt 180 fd 1 rt 45 rt random 45 fd 1 unstep ] ] end to go go1 go2 end to go1 if who > clock [stop] ;;delays initial departure of ants ifelse carrying-food? [setc yellow return-to-nest] ;;if ant finds food, it returns to the nest [setc red look-for-food] ;;otherwise it keeps looking end to go2 diffuse chemical diffusion-rate / 100 ;;diffuses chemical setchemical chemical * (100 - evaporation-rate) / 100 ;;slowly evaporates chemical update-display ;;updates colors of food sources setclock clock + 1 IF PLOT? = TRUE [do-plotting] end to return-to-nest if nest? ;;if ant is in the nest, it drops food and heads out again [setcarrying-food? false rt 180 step stop] tsetchemical chemical + drop-size setdrop-size (drop-size - 1.5) if drop-size < 1 [setdrop-size 1] uphill-nest-scent ;;ant heads toward the greatest value of nest-scent which is ;;toward the nest wiggle grid-step end to look-for-food if food > 0 [setcarrying-food? true ;;ant picks up food tsetfood food - 1 ;;and reduces the food source setdrop-size 60 rt 180 step stop] ;;ant turns around ifelse chemical > 2 [step] [ifelse chemical < 0.05 [wiggle step] [uphill-chemical grid-step]] end to uphill-chemical setahead next-chemical rt 45 setscent-right next-chemical lt 90 setscent-left next-chemical rt 45 if (scent-right > ahead) and not (scent-right < scent-left) [rt 45 stop] if (scent-left > ahead) and not (scent-left < scent-right) [lt 45] end to next-chemical ;; output chemical-at dx dy end to uphill-nest-scent setahead next-nest-scent rt 45 setscent-right next-nest-scent lt 90 setscent-left next-nest-scent rt 45 if (scent-right > ahead) and not (scent-right < scent-left) [rt 45 stop] if (scent-left > ahead) and not (scent-left < scent-right) [lt 45] end to next-nest-scent output nest-scent-at dx dy end to grid-step step setxy round xcor round ycor end to wiggle rt random 40 lt random 40 end ;;----- plotting functions to setup-plot pw1 clearplot auto-plot-on setplot-xrange 0 200 setplot-yrange 0 100 setplotwindow-name "|Food in each pile| pp1 setppc 85 setpen-name "|food-pile1| pp2 setppc 95 setpen-name "|food-pile2| pp3 setppc 125 setpen-name "|food-pile3| end to startup setplotwindow-name "|Food in each pile| end to do-plotting pp1 plot count-pc 85 pp2 plot count-pc 95 pp3 plot count-pc 125 end @#$#@#$#@ BUTTON 102 12 177 41 gobutton go T 1 NIL BUTTON 17 13 92 41 button2 setup NIL 2 NIL SWITCH 34 128 134 157 switch3 plot? 1 3 -1000 SLIDER 42 89 132 114 slider2 diffusion-rate 0 100 29 1 2 SLIDER 44 60 134 85 slider1 evaporation-rate 0 100 20 1 1 PLOT-WINDOWS NIL NIL NIL NIL NIL NIL INTERFACE-WINDOW 4980734 11665608 LEGEND 19595271 CC-WINDOW 20578310 8061166 GRAPHICS-WINDOW 6357374 PROCS-WINDOW 8847580 38273625 INFO-WINDOW 14287337 31588775 OUTPUT-WINDOW 2621640 16384350 @#$#@#$#@ WHAT IS IT? ----------- In this project, a colony of 100 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. 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 window. 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. STARLOGOT 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." The new StarLogoT uphill primitives can be used to replace the specialized uphill procedures. RETURN-TO-NEST uses a similar gradient. CREDITS and REFERENCES ----------------------- This model was adapted from the ants model 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. @#$#@#$#@ StarLogoT2001 R2 @#$#@#$#@ (install-shapenames '(("duck-shape" . 2))) @#$#@#$#@ @#$#@#$#@