Did It Work?

The ants move around the bag and find shorter paths. There are lots of parameters to play around with. The ants’ starting position makes a big difference. Let’s see what happens with 25 ants, running for 50 epochs, and dropping to pheromone level by 0.25 each time.

Starting in the Same Place

If the ants start in the same place, they will find the best path quite quickly. Some of the ants still wander around a little but do improve. A typical run gives about 30 steps for the worst initial path, 6 for the best, and an average of 15. The best path gets to the minimal 5 steps relatively quickly. You can see the ants find the best possible path in the figure. The best path is the solid line; the worst path is the dashed line:

Since ...

Get Genetic Algorithms and Machine Learning for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.