Learn how evolution inspires algorithms — from natural selection to optimization with Python.
Welcome to the Genetic Algorithms Workshop — a hands-on coding series where you’ll build, visualize, and understand evolutionary algorithms step by step using Python and the DEAP framework.
This repository contains:
- 🧩 Interactive exercises (
.ipynb) with guided### TODOsections. - ✅ Full solutions for each problem.
- 🖼️ The PDF presentation used during the workshop.
- 🔗 Links to open each notebook directly in Google Colab.
📖 Read the full accompanying article here: 👉 Hands-On Genetic Algorithms with Python
-
The intuition behind Genetic Algorithms (GAs) — inspired by Darwin’s theory of evolution.
-
How to represent, mutate, and evolve digital organisms.
-
Step-by-step GA workflow:
- Population initialization
- Fitness evaluation
- Selection, crossover, mutation
- Statistics and visualization
-
Applying GAs to solve problems like:
- 🎯 OneMax Problem — evolve the perfect binary string.
- 🎒 Knapsack Problem — maximize value under constraints.
- 👩⚕️ Nurse Scheduling Problem — handle hard and soft constraints.
Genetic-Algorithms-Workshop/
│
├── 📄 README.md ← You are here
├── 🧾 slides.pdf ← Full presentation
│
├── notebooks/
│ ├── 01_one_max_exercise.ipynb
│ ├── 01_one_max_solution.ipynb
│ ├── 02_knapsack_exercise.ipynb
│ ├── 02_knapsack_solution.ipynb
│ ├── 03_nurse_scheduling_exercise.ipynb
│ ├── 03_nurse_scheduling_solution.ipynb
You can open each exercise directly in Colab — no installation required!
| Notebook | Exercise | Solution |
|---|---|---|
| 🧩 OneMax | Open in Colab | View Solution |
| 🎒 Knapsack | Open in Colab | View Solution |
| 👩⚕️ Nurse Scheduling | Open in Colab | View Solution |
To run locally:
pip install deap matplotlib seaborn numpy jupyterThen launch Jupyter Notebook:
jupyter notebook notebooks/Start with:
01_one_max_exercise.ipynb
📑 Download the PDF slides: ➡️ slides.pdf
The slides cover:
- The story of Darwin and the finches 🐦
- How evolution translates into computation
- Key GA components (population, fitness, mutation)
- Demo visuals and diagrams
| Part | Topic | Description |
|---|---|---|
| 🧩 1 | OneMax Problem | Introduction to genetic representation and basic operators. |
| 🎒 2 | Knapsack Problem | Combining value optimization with constraints. |
| 👩⚕️ 3 | Nurse Scheduling | Handling hard and soft constraints using GA. |
Article: Hands-On Genetic Algorithms with Python Learn the theory behind this workshop — how nature’s principles can guide machine intelligence.
Contributions and improvements are welcome! Feel free to open an issue or submit a pull request.
MadBrain Labs is building brain-inspired AI for humanoid robots — merging neuroscience, robotics, and machine learning. Learn more at madbrain.ai
