Colonies of ants foraging for food in MGS


In this project, a colony of ants forages for food. Ant behavior follows a set of MGS 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.

anim1 anim2

The corresponding MGS program

data structures

record place      =
   { phero_nest:float, phero_food:int };;

record nest        =
   place + { nest };;

record food =
   place + { food:int };;

record ant     =
   place + { load_food : int };;

record empty       =
  place + {~nest, ~food, , ~load_food};;

A place is a record containing two values indicating the quantity of  two chemicals: the first is the smell of the nest; the second is the chemical left by the ants that carry food.

The nest is a place with an additional field labeled "nest". The food is represented by a place with an additional field for the quantity of food.

Ants are represented by a place (since the presence of an ant is not incompatible with the presence of the chemicals) with two fields indicating thequantity of food carried by the ant.

A place is empty when it does not contains any field particular to the nest, the food or the ants.

gbf grid = <north, east>;;

gbf hexa = <north, neast, seast; north + seast= neast>;;

The simulation can be run on a NEWS grid or on an hexagonal pavement of the plane, without modifying the core program.

ants behavior
trans behavior = {

 f/seek(f), n:food =>

 f/bring(f) , n:nest =>
   (f+{load_food=0,phero_food = 255 }),n;

  f/track(f) ,
  p/( empty(p) &&
      (p.phero_food >0) &&
      [...] )
    { phero_nest = f.phero_nest,
      phero_food = f.phero_food
  f/seek(f) ,
  p/( empty(p) && (p.phero_food>0)) => 
    { phero_nest=f.phero_nest,
      phero_food = f.phero_food

 f/seek(f), p/empty(p) =>  
   { phero_nest=f.phero_nest,
     phero_food = f.phero_food},

(* an ant brings the food to the nest *)
  f/bring(f) ,
  p/(  empty(p) &&
   { phero_nest=f.phero_nest,
     phero_food = (255)},


This is the main transformation of the simulation.

(1) when ant looking for food reaches the neighborhood of some food it collectes some;

(2) when an ant carrying some food reaches the neighborhood of the nest it drops the food (and drops some chemicals);

(3) when an ant has found some food chemicals indicating a track to sme food it follows the track;

(4) ant finding some food chemicals;

(5) ant looking for food randomly (it has not found a chemical track);

(6) ant bringing the food to the nest an finding a short path to it (following the smell of the nest).

In the rules (3) and (4) the [...] hides the choice of the best neigbor place using the neighborfold operator.

diffusion of the chemicals
STEP = 5;;

trans phero_food_decrease = {
    x:place => x+{phero_food=max(x.phero_food - STEP, 0)}

RATE = 0.9;;

trans gradient_nest2 = {
  n / not (nest(n)) =>
   let m =
     neighborsfold ((\x.\r.( max(x.phero_nest,r))),0,n) in
   n +  {phero_nest = m * RATE}  };;

The first transformation  implements the evaporation of the food chemical.

The second transformation implements in a very simple way the diffusion of the smell of the nest.

outputing the graphical description
fun out_col(c)=
  print_coll("output.txt", c, id, "\t[", "", "]\n");;

The records inside the collection are simply dumped into a file which is interpreted by a viewing tool. This tool can be found here.


Links and references

This model was inspired by :

"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.

NetLogo Ants model.
Wilensky, U. (1998).
Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

The pictures and animations were created with a tool dedicated to the viewing of simulations on 2D pavements of the plane. This tool can be found here.

Back to top
MGS examples index
MGS home page

(currently under construction logo)
this site is under construction.
Pages started: May 2002. Last revision: 24 jully 2003.

Creative Commons License
Pictures, graphics and animations are licensed under a Creative Commons License.

English keywords for indexation:  topological collections, transformation,  simulation of biological processes, integrative simulation, biological organization, dynamical systems, dynamical structure,  cellular automata,  GBF, Cayley graph, data fields, rewriting, rule based programming, pattern-matching, intentional programming, compilation, interpretation, type,  polytypism, catamorphism, ants foraging.