AntSim

Evolutionary ant colony simulation with genetics and pheromone trails

Python pygame-ce ACO Algorithms

The Problem

Traditional ant simulations often lack genetic diversity and realistic colony dynamics. The challenge was implementing evolutionary genetics, pheromone trail systems, and queen mortality while maintaining visual clarity and performance.

My Approach

  • 5-gene evolutionary system (sensitivity, speed, boldness, lifespan, energy_efficiency)
  • Pheromone trail system with exploratory and return-trail markers
  • Queen mortality with autonomous royal jelly raising
  • Split-view rendering (overhead foraging + ant hill cross-section)
  • Ant Colony Optimization (ACO) principles for efficient foraging

Key Highlights

  • Phase 3 (Hybrid Rendering) — In Progress
  • Stable Baseline: Phase 2C (Queen Mortality + Royal Jelly)
  • Realistic ant hill cross-section with chambers and tunnels
  • Tunable parameters for experimentation

How It Works

AntSim is an evolutionary ant colony simulation implementing genetics, pheromone trails, and realistic colony dynamics. It demonstrates Ant Colony Optimization (ACO) principles through visual simulation.

Features

Evolutionary Genetics:

  • 5 genes drive ant behavior: sensitivity, speed, boldness, lifespan, energy_efficiency
  • Traits inherit from parents with mutation
  • Natural selection favors efficient foragers

Pheromone Trails:

  • Ants lay exploratory and return-trail pheromones
  • Strong trails reinforce over time
  • Trail decay simulates natural evaporation

Queen Mortality:

  • Queens die randomly
  • Workers autonomously raise new queens from royal jelly
  • Colony continuity without external intervention

Split-View Rendering:

  • Top 2/3: Overhead foraging ground with trails and food nodes
  • Bottom 1/3: Realistic ant hill cross-section with chambers, tunnels, brood, and storage

ACO Behavior:

  • Ant Colony Optimization principles drive efficient foraging
  • Emergent pathfinding without centralized control
  • Scalable to large colony sizes

Status

Current Phase: Phase 3 (Hybrid Rendering) — In Progress
Stable Baseline: Phase 2C (Queen Mortality + Royal Jelly) ✅

Requirements

  • Python 3.10+
  • pygame-ce 2.5.6+

Installation

git clone https://github.com/rfd62794/AntSim.git
cd AntSim
pip install pygame-ce

Usage

Run the Simulation:

python main.py

Run Tuning Experiments: Modify parameters in the configuration file to experiment with death rates, pheromone decay, trail strength, and genetic mutation rates.

Key Concepts

Genes:

  • Sensitivity — ability to detect pheromones
  • Speed — movement velocity
  • Boldness — risk tolerance in exploration
  • Lifespan — maximum ant lifetime
  • Energy Efficiency — metabolic cost of movement

Pheromone Trails:

  • Exploratory trails — laid while searching for food
  • Return-trail markers — laid when carrying food back to nest
  • Trail strength — increases with repeated use
  • Trail decay — natural evaporation over time

Queen Mortality:

  • Random queen death events
  • Royal jelly production for queen rearing
  • Worker selection of new queen candidates

Experiments & Tuning

Baseline Tuning (Phase 2C):

  • Queen mortality rate calibrated for colony stability
  • Royal jelly production balanced against resource consumption
  • Genetic mutation rates tuned for adaptive evolution

Next Steps

Phase 3 focuses on hybrid rendering optimization, improving performance for larger colony sizes while maintaining visual clarity of both foraging ground and ant hill cross-section.


GitHub: AntSim


Built with Python and pygame-ce. Evolutionary genetics and ACO principles.

Explore