Ant Colony Simulation

Finite-State Machines and Abstraction

Summary

This was a project I developed for one of my modules during my final year at university. It uses Finite-State Machines (FSMs) to simulate the colonial behaviour of ants, and more specifically their pathfinding using pheromones. This project also received a nomination to be presented at the University of Greenwich’s Digital Shark Expo 2025, where I demonstrated my work both to fellow university colleagues, as well as members of the faculty and company representatives.

BACKGROUND

During a lecture on Finite-State Machines (FSMs), I remember recalling another lecture from another module - specifically about pheromone pathfinding. This gave me the idea for creating a simulation of an ant colony, namely by abstracting ant behaviour down to a few simple states, and switching between them based on ‘external stimuli’ such as pheromones. After further discussion with (and subsequent approval by) my professor, I started working on this idea for my coursework project.

Initially, the simulation was supposed to be much more complex than what the final product ended up being. I wanted to add certain events, such as disease outbreaks in the colony, as well as potential predators and even specific behaviours for encountering rival colonies, but largely due to time constraints and due to the fact that FSMs tend to become slow and inefficient very fast as more states and transitions are added, these ideas were largely scrapped, though there are still references to them in the program’s source code.

The Result

For the scope of this project, only three kinds of behaviour needed to be simulated, those being Random Walk, Go to Food, and Go Home.

Every ant (except the Queen, which remains at the nest) starts in the Random Walk state, which, as its name suggests, means the ants walk around randomly, leaving pheromones behind in order to be able to reach the nest if they either become too hungry to continue, or if they find a food source. Once an ant discovers a food source, it transitions into the Go Home state and takes some food and follows its own pheromone path back to the nest. This state transition also affects the type of pheromone it drops on its path back to the nest, which signals to other ants that a food source has been found somewhere along said pheromone path. Once depositing the food at its nest, the ant will then transition into the Go to Food state and follow its own path back to the food source, and will keep cycling between Go to Food and Go Home until the food source is depleted. If an ant is in its Random Walk state and finds another ant’s Go to Food pheromones, it will transition into the Follow Path to Food state and follow them to the food source, and then depending on whether there is already a path back home or not, will either follow its own path (Go Home state) or follow the other ant’s pheromone trail back to the nest (Follow Path to Home state).

Though these five states and nine transitions seem relatively simple, they are already fairly slow and computationally expensive, which only becomes worse when there are multiple ants spawned. Even if I wasn’t constrained by time while making this project, the simulation would likely have become far too computationally expensive had I added all of the features and additional states and transitions I wanted to.

Despite this, I was pleasantly surprised when I found out that this project was nominated for the University of Greenwich’s Digital Shark Expo 2025 - an annual exposition held by the university meant to showcase the works of many brilliant students in the fields of Computer Science and Robotics. I got the chance to not only see other incredible work by fellow students, but also to demonstrate my project to several people, including faculty members and representatives from various companies that were attending the event.

Worker Ants and Soldier Ants searching for food around the nest

Same simulation, except with many more ants, including different ant types (Worker and Soldier)

A Worker randomly walking around the map, until it finds food, then tracing its pheromone path back to the nest

A diagram of ant behaviour abstracted down to five states, alongside the conditions needed to transition between states

Get in touch with me for a full demo