PyEvolve: Genetic Algorithm Simulation

What is PyEvolve?

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:

🎮 Try the Demo

Want to see PyEvolve in action without setting up Python? Download our pre-compiled demo executable and run the simulation immediately!

The demo includes:

📥 Download Demo (Windows .exe)

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! ;)

Quick Installation Guide

  1. Clone the repository:
    git clone https://github.com/Papaya-Voldemort/Creature-Evolution-Sim.git
    cd Creature-Evolution-Sim
  2. Install the required dependencies:
    pip install -r requirements.txt
  3. Run the simulation:
    python main.py

Example Usage

Basic Simulation

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)

Customizing the Simulation

You can easily modify the simulation parameters:

Visualization Examples

Fitness trends over generations

Fitness trends over generations showing average, maximum, and minimum fitness values.

Trait evolution over generations

Evolution of average trait values (speed, strength, vision, stamina) across generations.

Trait distribution in final generation

Distribution of trait values in the final generation.

Understanding the Code

Key Components

Fitness Calculation

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

Future Development

Check out the TODO.md file for planned improvements and features. Contributions are welcome!

Get Started Today!

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