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 = { (1) f/seek(f), n:food => (f+{load_food=255}),n; (2) f/bring(f) , n:nest => (f+{load_food=0,phero_food = 255 }),n; (3) f/track(f) , p/( empty(p) && (p.phero_food >0) && [...] ) => { phero_nest = f.phero_nest, phero_food = f.phero_food }, (f+p); (4) f/seek(f) , p/( empty(p) && (p.phero_food>0)) => { phero_nest=f.phero_nest, phero_food = f.phero_food }, (f+p); (5) f/seek(f), p/empty(p) => { phero_nest=f.phero_nest, phero_food = f.phero_food}, (f+p); (6) (* an ant brings the food to the nest *) f/bring(f) , p/( empty(p) && [...]) => { phero_nest=f.phero_nest, phero_food = (255)}, (f+p); };; |
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. |
Back
to top |
MGS examples index |
MGS home page |
Pictures, graphics and animations are licensed under a Creative Commons License.
|