The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.
powered by NetLogo
view/download model file: simulating_an_ant_colony.nlogo
The aim of the model is to represent the behaviour of the ants that provide for foraging (working class). Four piles of food are randomly created troughout the world and a variable number of ants are engaged in looking for seeds. The simulation runs as far as all food is collected or all the ants die.
The model works trough a series of quantitative variables like energy or pheromones,and some Boolean ones, whose value can only be true or false. At each step,all the variables are updated and the behavior of ants opportunely corrected.
Home-pheromones (HP) are released when an ant is leaving the nest and they are signals that will help the ant and its colleagues to find the way home. Each ant, as it walks, leaves a decreasing amount of it, so that higher concentration means closeness to the nest. When the ant finds food, it will take it and leave food-pheromones(FP) returning to nest by following a positive gradient of concentration of HP. Similarly ants that happen to feel FP will follow the positive gradient of the track in order to reach the food source.
At each step ants consume a unit of energy and insects will die when they run out of forces. However there are many strategies to survive. First of all if they found a seed and will manage to bring it back to the nest they can take some pieces of food if their energy happen to be below 100. When they are performing their tasks and the energy goes below 100, they will try to return to nest, but it is not always possible. In this situation if the energy is decreasing reaching the value of 50, they will use Trophallaxis. This that allows hungry ants to get some food from a colleague that has stored it in a social stomach. This way they will get a little bit of energy to return to nest.
The interface allows the user to choose how many ants will be created at the beginning and, eventually, the probabily of creation of new ants at each step. It is possible to decide either to show the tracks of pheromones or not. After deciding this features, click on the SETUP button and on the screen a new nest is displayed in yellow, the food piles will appear and ants are created in the nest. The GO button starts the simualtion.
Try to add enemies and a new kind of ants, the soldiers. Try to add obstacles and teach ants how to avoid them.
In NetLogo Models Library there are two scripts related to the present one:
- Ants
- Ant Lines
In order to write the script and the essay related i referred to the following material:
S. Cacace, E. Cristiani, D. D’Eustacchio, Mymedrome: Simulatinig the life in an ant colony
M. Emmer, Imaging Math. 2. Between Culture and Mathematics Springer-Verlag
Italia, 2013.
Deborah Gordon, The emergent genius of ant colonies
TED Conference, 2008.
David Shindleman, The behavior of ants
Department of Biochemistry and Molecular Biophysics
The University of Ariziona, 2002.
Copyright 2013 Greta Greco.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
globals [ storage totfood totfood1 ] patches-own [ home-pheromon food-pheromon nest? ] breed [workers worker] breed [seeds seed] workers-own[ ant-home-pheromon ant-food-pheromon hasSeed? energy social-stomach ] to setup clear-all populate setup-patches set totfood count seeds set totfood1 count seeds reset-ticks end to populate set-default-shape workers "ant" crt population [ set size 3 set color black] ask turtles [set breed workers] ask workers [ set hasSeed? false set ant-home-pheromon 10 set ant-food-pheromon 10 set energy 600 set social-stomach 200 ] end to setup-patches ask patches [ set pcolor white setup-nest ] setup-food end to setup-nest set nest? (distancexy 0 0) < 4 if nest? [set pcolor yellow] end to setup-food set-default-shape seeds "egg" ask n-of initial_food_piles patches [ sprout-seeds random(5) ask patches in-radius(2) [ sprout-seeds random(5)] ask seeds [set color green] ] end ;;;;;;;;;;;;TO GO;;;;;;;;;;;;;; to go if count workers > 0 and totfood1 > 0 [ ask workers [ consume-energy ifelse energy < 50 [eat2] [ ifelse hasSeed? [return-to-nest] [go-foraging]] ] ask patches [ ifelse showTrack?[print-chemical] [ifelse nest? [set pcolor yellow][set pcolor white]] evaporate] tick] end to consume-energy ifelse energy > 0 [ set energy energy - 1 ] [ die if hasSeed?[set totfood1 totfood1 - 1] ] end to go-foraging release-home-pheromon follow-fp pick-seed end to move fd 1 let turn-angle random(10) if turn-angle < 1 [ lt random(30) ] if turn-angle > 8 [ rt random(30) ] end to sprout-ants ask patches [if pxcor = 0 and pycor = 0[ if random-float(1) < 0.05 [sprout-workers 1 [ set hasSeed? false set energy 600 set ant-home-pheromon 10 set ant-food-pheromon 10 set color black set size 3]]]] end ;;;;;;;;;;;REPORT QUANTITIES;;;;;;;;;;;;;;; to-report ant-hp let a one-of workers-here if a = nobody [ report 0 ] report [ant-home-pheromon] of a end to-report ant-fp let b one-of workers-here if b = nobody [ report 0 ] report [ant-food-pheromon] of b end to release-home-pheromon if (ant-home-pheromon > 0 and not hasSeed?) [ set ant-home-pheromon (ant-home-pheromon * 0.9) ask patch-here [ set home-pheromon home-pheromon + (ant-hp * 0.9) ]] end to follow-fp let fs (patch-set patch-ahead 1 patch-right-and-ahead 45 1 patch-right-and-ahead 90 1 patch-left-and-ahead 45 1 patch-left-and-ahead 90 1 patch-ahead 2 patch-right-and-ahead 45 2 patch-right-and-ahead 90 2 patch-left-and-ahead 45 2 patch-left-and-ahead 90 2 patch-ahead 3 patch-right-and-ahead 45 3 patch-right-and-ahead 90 3 patch-left-and-ahead 45 3 patch-left-and-ahead 90 3) let f max-one-of fs [food-pheromon] ifelse [food-pheromon] of f > food-pheromon [ face f fd 1] [move] end to pick-seed let food one-of seeds in-radius 2 if food != nobody [ face food fd 1] let food1 one-of seeds-here if food1 != nobody [ set hasSeed? true ask food [die] set shape "ant-seed" rt 180 ] end to return-to-nest release-food-pheromon follow-hp1 leave-food eat1 end to release-food-pheromon if ant-food-pheromon > 0 and hasSeed?[ set ant-food-pheromon (ant-food-pheromon - 0.1) ask patch-here [ set food-pheromon (food-pheromon + ant-fp)]] end to print-chemical if home-pheromon > 0 [ set pcolor scale-color red home-pheromon 20 0 ] if food-pheromon > 0 [ set pcolor scale-color blue food-pheromon 20 0 ] end to evaporate if food-pheromon > 0 [set food-pheromon food-pheromon * 0.99 ] if home-pheromon > 0 [set home-pheromon home-pheromon * 0.99 ] if food-pheromon > 20 [set food-pheromon food-pheromon * 0.95 ] if home-pheromon > 20 [set home-pheromon home-pheromon * 0.95 ] end to follow-hp1 let ps (patch-set patch-ahead 1 patch-right-and-ahead 45 1 patch-right-and-ahead 90 1 patch-left-and-ahead 45 1 patch-left-and-ahead 90 1 patch-ahead 2 patch-right-and-ahead 45 2 patch-right-and-ahead 90 2 patch-left-and-ahead 45 2 patch-left-and-ahead 90 2 patch-ahead 3 patch-right-and-ahead 45 3 patch-right-and-ahead 90 3 patch-left-and-ahead 45 3 patch-left-and-ahead 90 3) let p max-one-of ps [home-pheromon] ifelse [home-pheromon] of p > home-pheromon [ face p fd 1] [move] end to leave-food if nest? [ if hasSeed? [ set hasSeed? false ask patch-at 0 0 [ set storage storage + 1 set totfood1 totfood1 - 1] set shape "ant"] set ant-home-pheromon 10 set ant-food-pheromon 10 rt 180 ] end ;;;;;;;;;;;;;;;;TO EAT;;;;;;;;;;;;;;;;;;;;, to eat1 if energy < 100 and nest? [ if [storage] of patch-at 0 0 > 1 [ set energy 600 set social-stomach 200 ask patch-at 0 0 [ set storage storage - 2]]] end to eat2 return-to-nest let help one-of workers in-radius 2 if help != nobody and [social-stomach] of help > 0 [ set energy energy + 100 ask help [ set social-stomach social-stomach - 100 ]] end