Ants are awesome, their co-operation and coordination are really impressive, these behaviors pushed the scientists to discover and study more about ants, and how these creatures communicate with each other to preform these behaviors which help them to accomplish their tasks and missions.

*Stigmergy*, an indirect communication that the ants use to communicate with each other, you can imagine it as a kind of mechanism that an ant affects the environment(the ground) by it to tell other ants to do a specific task or move, this helps the ants to achieve self-organization.

Biologists found something interesting, some of ants species use something called *Trail of pheromones*, ants spread them on the path they walk on, other ants sense this trail and follow the same path as an influence for them. By using this trail of pheromones, ants can follow each other to reach a source of food, then return back to their colony. The amount of the pheromones is directly proportional to the intensity of the ants, which means that the higher of pheromones on a path, the more of ants walk on that path.

Scientists decide to do an experiment to fully understand the trail of pheromones, they put some ants on a dynamic environment in which new paths added to it in the run time to see the ants’ behaviors, see the following figure

The figure contains before-after adding a new shorter path from nest to food source, initially ants were on the nest, before adding a shorter path there was only one path to get the source food, so that all ants walked on it, after each of ants’ walk they left the trail of pheromones, and that helped ants to follow each other. After adding a new shorter path, it was expected that the ants will change their path immediately, but they continue use the longer path, after many trips from the nest to the source food, the ants changed their way to the shorter path.

Scientists explained that ants always follow the trail of pheromones, the longer path has much pheromones than the shorter path so the ants continued to follow that path, after many iterations, they changed their path to the shorter one because some of ants explored the new path and found it shorter, so more and more ants took a decision to use the new path, and for each trip on it they left the “Trail of pheromones” which made all ants to follow the new path, regarding the pheromones on the longer path, the scientists found that the pheromones always evaporate after several minutes and that made all ants to ignore the longer path.

Well, it the time to simulate this in a mathematical perspective by creating a probabilistic model (Stochastic model), assume that the probability that an ant at a decision position* i ∈ [p1, p2]* chooses a path *a* where *a ∈ [s, l]* is *pia(t),* *s* denotes short path and* l* is the long path, the amount of pheromones at time *t* is denoted as *φia(t)*

The probability that an ant reaches from the nest to the source using short or long path is *pis(t) + **pil(t) = 1, *according to the experiment, they concluded that the amount of the pheromones is proportional to the intensity of the ants, so the probability that an ant chooses the short path is:

where α = 2 which is concluded from the experiment .. as the amount of pheromones changes and evolves during the time, this evolution can be described using differential equations:

dφis / d*t* = ΨPjs(*t* – *t*s) + ΨPis(*t*) ======> (i = a, j = b; i = b, j = a)

dφil / d*t* = ΨPjl(*t* – (r . *t*s)) + ΨPil(*t*) ======> (i = a, j = b; i = b, j = a)

Ψ: is a constant

r: is the ratio between the long and short paths

Note that, this model represents that ants are spreading pheromones in both trips (from nest to food, and from food to nest)

These equations inspired the scientists to use ants’ behaviors to get a minimum cost path in a simple graph.

**Build A Simple Ant Colony
**

Problems appeared when they tried to use ants’ behavior (described above), we can conclude them in two points ..

[1]Loops generation

– Ants in their trip, they spread pheromones forward (from nest to food) and backward (from food to nest),

this may causes a loop that traps the ants, due to forward pheromone trail, increasing amount of pheromones in loop’s path attracts all ants to follow only the loop’s paths.

[2]Ignoring short paths

– If an ant survive from the loop, the pheromones trails on the short paths will be evaporated, that makes the ant ignores them

The solution is to create some behaviors that help them to find minimum cost path in simple graph without only depending on trails of pheromones, these behaviors are..

[1]Probabilistic solution constructed by pheromone trails

[2]Deterministic backward path with pheromone updating (loops are eliminated)

[3]Evaluation for a generated solution in each iteration

Next, we will discuss each of these behaviors.

[1]**Probabilistic solution constructed by pheromone trails
**– In the forward trip, ant chooses probabilistically a path according to the amount of pheromones on this path which has been spreaded by the other ants, ants in the forward trip don’t spread any pheromones.

[2]**Deterministic backward path with pheromone updating (loops are eliminated)
**– When an ant is in the destination node (source food), before it starts its backward trip, it memorizes the paths and eliminates all loops from them, ants in the backward trip spread trails of pheromones. This with the probabilistic solution eliminate the loops generation problem.

[3]**Evaluation for a generated solution in each iteration
**– Ants in their trip, they memorize the paths they talk and the cost from the start node to the end node, depends on that, they spread the pheromones according to the quality of the solution, the higher amount of pheromones the better of the solution.

– Controlling the pheromones evaporation rate leads to avoid the poor solutions

Implementing all these behaviors leads to build a simple ant colony optimization algorithm (*S-ACO*) to find the minimum cost path on a simple graph. The next post will about this algorithm.

References: Marco Dorigo and Thomas Stützle ant colony optimization book