The Evolving Ecosystem Simulator is a Python-based simulation that models simple evolutionary dynamics in a virtual ecosystem. In this simulation, digital organisms move around a virtual environment, searching for food. They gain energy by consuming food, lose energy over time due to metabolism, and reproduce when they accumulate enough energy. The simulation includes random mutations, allowing you to observe evolutionary changes in traits such as speed over time.
This project is built using Python and Pygame, with support for headless execution, making it suitable for environments like Google Colab.
- Interactive Simulation: Organisms autonomously search for food, gain energy, and reproduce.
- Evolutionary Dynamics: Traits like speed can mutate, demonstrating natural selection over time.
- Visualization: Organisms are color-coded by speed (red for faster, blue for slower), and food is displayed as green dots.
- Headless Mode Compatibility: Can run in headless mode, capturing frames to generate an animated GIF for visualization.
- Python 3.x
- Pygame
- pyvirtualdisplay (for headless mode)
- imageio (for GIF creation)
- numpy (for handling frame data)
Run the following command to install the necessary packages:
pip install pygame pyvirtualdisplay imageio numpy
If you are running this on Google Colab, you'll also need to install Xvfb:
!apt-get install -y xvfb
-
Clone the Repository:
git clone https://github.com/mohiuddin-khan-shiam/Evolving-Ecosystem-Simulator.git cd Evolving-Ecosystem-Simulator
-
Install Dependencies:
pip install pygame numpy imageio pyvirtualdisplay
-
Run the Simulator:
python evolving_ecosystem_simulator.py
This will open a Pygame window displaying the evolving ecosystem.
-
Install Dependencies:
!apt-get install -y xvfb !pip install pyvirtualdisplay imageio pygame numpy
-
Run the Simulation:
Upload
evolving_ecosystem_simulator.py
to your Colab environment and execute the script. The simulation will run headlessly and generate an animated GIF (simulation.gif
) displaying the ecosystem.
- Organisms: Each organism has traits such as position, speed, energy, and vision range. They search for food, move towards it, and consume it to gain energy.
- Food: Food items are randomly scattered across the environment. Organisms consume food when they come into contact with it.
- Reproduction and Mutation: When an organism's energy exceeds a certain threshold, it reproduces. Offspring inherit the parent's speed with a chance of mutation, leading to evolutionary changes.
- Visualization: Organisms are displayed as colored circles, where faster organisms appear redder, and slower ones appear bluer. Food is shown as small green dots.
You can tweak various parameters in evolving_ecosystem_simulator.py
to customize the simulation:
NUM_INITIAL_ORGANISMS
: Number of organisms at the start.NUM_INITIAL_FOOD
: Number of food items initially present.FOOD_ENERGY
: Energy gained from consuming food.REPRODUCTION_ENERGY_THRESHOLD
: Energy required for reproduction.MUTATION_RATE
: Probability of a mutation occurring during reproduction.MUTATION_AMOUNT
: Range of possible mutation changes.
evolving_ecosystem_simulator.py
: The main simulation script.output.gif
: Sample animated GIF showcasing the simulation.README.md
: This file.
This project is licensed under the MIT License. See the LICENSE file for more details.
- Thanks to the developers of Pygame, pyvirtualdisplay, and imageio for providing the tools that made this project possible.