## "Simulating an ant colony."

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.

Here you can find an introduction to the Simulating an ant colony application.

## WHAT IS IT?

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.

## HOW IT WORKS

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.

## HOW TO USE IT

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.

## EXTENDING THE MODEL

Try to add enemies and a new kind of ants, the soldiers. Try to add obstacles and teach ants how to avoid them.

## RELATED MODELS

In NetLogo Models Library there are two scripts related to the present one:
- Ants
- Ant Lines

## CREDITS AND REFERENCES

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.

# CODE

```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]
set hasSeed? false
set ant-home-pheromon 10
set ant-food-pheromon 10
set energy 600
set social-stomach 200 ]
end

to setup-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"
sprout-seeds random(5)
]
end

;;;;;;;;;;;;TO GO;;;;;;;;;;;;;;

to go
if count workers > 0 and totfood1 > 0 [
consume-energy
ifelse energy < 50 [eat2] [
ifelse hasSeed?
[return-to-nest]
[go-foraging]]
]
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)
set home-pheromon home-pheromon + (ant-hp * 0.9) ]]
end

to follow-fp
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
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 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
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