// Academic Project · Year 4

Evolving Foraging Agents with BEAST

Extended a C++ evolution framework with new sensors and deeper networks, tested over 5,000 generations.

AI & MLScientific & biomedicalC++Genetic AlgorithmsNeural NetworksCo-evolutionPythonBash

Individual coursework for Bio-Inspired Computation, using BEAST, a C++ framework for evolving simulated creatures. Mice with small neural networks for brains evolve to find cheese, and then predators and prey evolve against each other. I extended the C++ code with new sensors, deeper networks and new fitness functions, and ran each experiment for 5,000 generations.

The setup

Module
COMP5400 Bio-Inspired Computation
Year
2025/26 · Year 4
Team
Individual
Weighting
40% of the module

Each mouse is steered by a small neural network that reads its sensors. A genetic algorithm evolves the network weights: mice that find more cheese are more likely to pass their weights on. The coursework asked how far better sensors, bigger brains and different fitness functions could improve them, and whether a predator-prey version really co-evolves.

Sensors and brains

  • • I wrote 9 sensor variants in C++, including distance, stereo, range, density and all-round sensors, plus custom sensors that report the angle and distance to the nearest few cheeses or mice.
  • • I compared networks from no hidden layer up to 50 hidden units, and wrote my own multi-layer network class to test deeper brains, up to five hidden layers.
  • • To get through all of this, I wrote headless runners and parallel Bash pipelines that ran every configuration with 5 random seeds, and Python scripts that plotted the results. The biggest networks took up to 3,515 seconds a run, against 227 for the simplest.
Two charts over 5,000 generations comparing the baseline, distance, range and stereo sensors: average fitness on the left, average cheeses collected on the right.
The distance and stereo sensors scored the highest fitness (left) but collected fewer cheeses than the baseline (right).

That gap was the most useful result. A higher fitness score didn't mean a better forager, so I wrote alternative fitness functions (one rewarding efficiency, one rewarding cheese count alone) and used the average number of cheeses found as an objective measure to compare them fairly.

Predators and prey

In the second part, predators that score by catching prey evolve alongside prey that score by not being caught. Over a 2,000-generation run, the predators did well early on, then the prey caught up: predator meals fell to a handful per generation while prey fitness kept climbing.

Chart over 2,000 generations: predator fitness spikes early then drops and stays low, while prey fitness rises in steps.
Average and best fitness for predators (red) and prey (blue) over 2,000 generations.
C++ Genetic algorithms Neural networks Python Bash matplotlib

Ask AI

answers from this site · DeepSeek

Starting assistant...