Ant Behavior Simulation
Meher Bhandari
Have you ever wondered how simple organisms, like ants, find the shortest path between their nest and a food source? You might think it's due to a particular communication system between them or an ability to perceive distance, but the answer lies in a much simpler chemical substance—pheromones. What's more, this process is a naturally occurring example of emergence, which is the backbone of complex artificial networks that power many generative AI models that we use today.
How do ants make decisions?
To be more specific, pheromones are chemical trails laid by ants as they depart from their nests to visit a food source and subsequently return to their nest. Fellow ants tend to follow the trail with the greatest quantity of pheromone on it. Given this background, we can imagine a simplified example with only two ants traveling, who we'll call TAL (takes a left) and TAR (takes a right). There is an obstacle in their path positioned such that the right path is shorter than the left, as shown in the figure below.


Figure 1: The Emergent Mind Chapter 2, Gaurav Suri and James McClelland
Because the right path is shorter, TAR arrives at the food source first, and then determines its return path by detecting the pheromone levels at that point. Because the right path is the only one that's been taken so far, TAR only finds pheromone on the right path and uses that one to return. Because the left path is longer, TAL reaches the food source later on, so it detects double the pheromone on the right path compared to the left. Therefore, TAL will also return using the right path. As more ants leave the nest to access the food source, the same process will occur and cause pheromone levels to compound on the right path, meaning that most of the ants will favor the shorter, more efficient trail. The ants' use of pheromones here resembles the concept of emergence in AI—tangible decisions rooted in simplistic logic lead to more advanced conclusions.
Program Overview
Reflecting this process through code, I created a visual of the ants using pheromone trails to navigate to the food source and back. The ants make decisions with some degree of randomness; paths are chosen using a stochastic function so that not every choice is the path with the highest pheromone level.
The program runs using a series of timesteps, during each of which a new ant leaves the nest and selects a path to the food source. Depending on the difference in length between the paths, the program will calculate the ant's arrival time in terms of timesteps and add it to the queue of ants accordingly. After this, any ants that reach the food source on the current timestep will increase the pheromones on their chosen path and then choose a return path. Finally, any ants returning to the nest on the current timestep will also increase the pheromone on their path.
This process repeats until all ants have returned to the nest, with the overall pheromone levels decaying each step to mimic the natural properties of pheromone. The full code can be found here: https://github.com/meher-bhandari/ant-behavior-simulation
Below is a recording of one such simulation playing out:
Simulation Trials
After creating the initial model, I chose to test the impacts of two main variables on the results: distance and noise. For the distance test, I shifted the placement of the obstacle in increments of 25 pixels, testing six differences in path length total. For each trial, I ran the simulation 10 times, with a constant noise level of 0.25, colony size of 100, and evaporation rate of 0.1. I took the averages of the number of ants taking the left and right paths for each obstacle position, and then plotted these values against the difference between the two path lengths, as seen in the following graph.

For the noise test, I chose 5 randomness values to test: 0, 0.25, 0.5, 0.75, and 1. For each noise value, I ran the simulation 10 times, keeping the other parameters constant with the obstacle positioned at -25, the evaporation rate at 0.1, and the colony size at 100. Similarly to the previous trials, I averaged the ants taking the left path and the ants taking the right path for each noise value before plotting them in the graph below.

These results are overall consistent with what is expected from the program. In the distance trial, more ants favor the shorter path as the difference in length between the two paths increases. In the noise trial, the number of ants taking each path grows more even as the randomness level increases.
Future Directions
From here, some future directions for this research could be investigating different types of pheromones as they occur naturally. In particular, some species of ants can deposit both short and long-term pheromones depending on the type of trail they are marking, and the next version of the program could reflect that to more accurately model ant behavior.

About Me
My name is Meher Bhandari, and I'm a current sophomore studying Computational Neuroscience at Carnegie Mellon University. I study neuroscience because I hope to better understand how we think and connect from a psychological perspective. I'm especially passionate about exploring behavioral phenomena through computational models and tools. If you have any questions about this project, please feel free to contact me at meherb@andrew.cmu.edu!