PyEvolve is a simple yet powerful genetic algorithm simulation that demonstrates evolutionary principles through computational modeling. The simulation creates a population of virtual creatures with various attributes (speed, strength, vision, and stamina), evolves them over multiple generations, and visualizes the results.
This project is perfect for:
Want to see PyEvolve in action without setting up Python? Download our pre-compiled demo executable and run the simulation immediately!
The demo includes:
Note: The demo executable is approximately 15-20MB and may trigger antivirus warnings due to being an unsigned executable. This is normal for Python-compiled executables. Don't worry it's not sketchy! Have fun reviewers! ;)
git clone https://github.com/Papaya-Voldemort/Creature-Evolution-Sim.git
cd Creature-Evolution-Sim
pip install -r requirements.txt
python main.py
The default configuration in main.py
creates a population of 100 creatures and evolves them over 10 generations:
import random
from helpers import Creature
from helpers import calculate_offspring, produce_next_generation
import matplotlib.pyplot as plt
import os
population_count = 100
population = []
generation_goal = 10
# Create initial population
for i in range(population_count):
speed = random.randint(1, 100)
strength = random.randint(1, 100)
vision = random.randint(1, 100)
stamina = random.randint(1, 100)
creature = Creature(speed, strength, vision, stamina)
population.append(creature)
# Sort by fitness
population = sorted(population, key=lambda c: c.fitness, reverse=True)
generations = [population]
# Evolve for multiple generations
for gen in range(1, generation_goal + 1):
survivors = generations[-1][:20] # top 20 from previous generation
next_generation = produce_next_generation(survivors, population_count)
next_generation = sorted(next_generation, key=lambda c: c.fitness, reverse=True)
generations.append(next_generation)
You can easily modify the simulation parameters:
population_count
to simulate larger or smaller populationsgeneration_goal
to run for more or fewer generationscalculate_fitness
method in the Creature
class to change how fitness is determinedcalculate_offspring
functionFitness trends over generations showing average, maximum, and minimum fitness values.
Evolution of average trait values (speed, strength, vision, stamina) across generations.
Distribution of trait values in the final generation.
The default fitness function weights the attributes as follows:
def calculate_fitness(self):
fitness = (0.3 * self.speed) + (0.3 * self.strength) + (0.2 * self.vision) + (0.2 * self.stamina)
return fitness
Check out the TODO.md
file for planned improvements and features. Contributions are welcome!
PyEvolve is a great way to learn about genetic algorithms and evolutionary computation. Clone the repository, run the simulation, and start experimenting with your own modifications!
View on GitHub