Ants finding a short path in a maze

Programmed by Erich Neuwirth

created with NetLogo

view/download model file: AntsOpt.nlogo

A similar model (finding the shortest path in a random terrain) can be found here

In this model ants try to find a short path from the
left upper corner to the right lower corner of the area.

There are pools and lakes (blue) which the ants cannot enter.
And there is normal soil (brown) and wood (green).
Ants are only half as fast in wood than on normal soil.

The ants "communicate" by dropping pheromone on the ground.
The purpose of the pheromone is to indicate "preferable directions"
to go on.
When an ant decides which directions to go
it does so randomly, with probabilities proportional
to the pheromone values for the different directions.

In the beginning, on any spot all legal directions have the same
pheromone value.
So the first ant takes a completely random path.
When an ant arrives, it traces its path back and drops pheromone
on all the spots, in the directions it has taken.
It drops only little pheromone if the path was long, and it drops
more pheromone if the path wath short. So pheromone "piles up"
on spots belonging to a short path.

Turtles starting later already get hints on which directions
to take, and so the paths becomes shorter and shorter for some time.

The setup button creates a new map of for an area.
Not all maps work. If the start or the goal is completely blocked
by water, start and goal cannot be connected.

The clear button resets the pheromone values to the initial state.
The remove-loops switch allows you to play with "smart ants".
When the switch is on, the ants remove all the loops the have
walked before retracing there paths backward.

The run button starts a number of ants (opne after the other),
and the slider next to it controls the number of ants to be started.

The delay slider allows you to stop the ants for some time before they start
retracing so you can see the pattern of the paths better.
The ant path is turqoise on the way to the goal, and yellow when the ant
goes back dropping the pheromone.

The monitors should be self explaining.

The histogram at the bottom displays the lengths of all paths so far.
You can change the width with the slider, and after a change you can replot
with the button.