antf: Ant Colony Simulation

Source code

About

A toy ant colony simulation I wrote when first learning Rust. The project originally started in C and once I had enough of re-inventing the wheel, I switched to Rust and re-wrote basically all of my existing code in one sitting.

There’s no fancy graphics rendering, just text output to stdout. The world is divided into a grid where food can randomly spawn. The ants walk around the world aimlessly until they run into the food, at which point they turn around and bring it back to the spawn point (which is hard-coded to be at the origin). Bringing food back to the origin spawns another ant and the cycle continues.

To help other ants find the food, they drop pheromones on the ground which other ants follow once food has been found. This quickly turns into a loop that exhausts all of the food on the screen.

This is known as ant-colony optimization, and has been studied extensively. I picked up the idea of using pheromones from Practicing Ruby and ported it into my own application. Turns out this implementation is based on Richard Hickey’s of clojure fame!

Last modified: September 24, 2024