A Python Tkinter app that runs a genetic algorithm and differential evolution on benchmark functions and shows how each one improves over generations.
The chart above was produced by a headless run of ProjectGA.py (see Results below).
The app minimizes one of five benchmark functions in any number of dimensions with either:
- a genetic algorithm (GA): tournament selection, uniform crossover, and random-reset mutation; or
- differential evolution (DE): mutant vectors
a + F * (b - c), binomial crossover, and greedy replacement.
Each run records the best and average fitness per generation, plus population diversity for the GA. The GUI shows these in tabs.
From the code in ProjectGA.py:
- Genetic algorithm with tournament selection (3 random candidates), uniform crossover, and mutation with a fixed rate.
- Differential evolution (DE/rand/1/bin style) with a differential weight and crossover rate.
- Five benchmark functions: Booth, Matyas, Rosenbrock, Sphere, and Zakharov.
- Tkinter GUI with four tabs: Optimization Setup, Results, Visualization, and Analysis.
- Optimization runs in a background thread so the window stays responsive.
- Per-generation tracking of best fitness, average fitness, and (GA) diversity.
For x = (x1, ..., xn):
| Function | Formula |
|---|---|
| Booth (2D) | (x1 + 2*x2 - 7)^2 + (2*x1 + x2 - 5)^2 |
| Matyas (2D) | 0.26*(x1^2 + x2^2) - 0.48*x1*x2 |
| Rosenbrock | sum(100*(x[i+1] - x[i]^2)^2 + (1 - x[i])^2) |
| Sphere | sum(x[i]^2) |
| Zakharov | sum(x[i]^2) + (sum(0.5*i*x[i]))^2 + (sum(0.5*i*x[i]))^4 |
flowchart LR
A[Choose algorithm, function, and parameters] --> B[Random population within bounds]
B --> C[Evaluate fitness]
C --> D{Generations left?}
D -- yes --> E[GA: selection, crossover, mutation<br/>DE: mutate, crossover, greedy replace]
E --> C
D -- no --> F[Show results, plots, and analysis]
Requires Python 3 with Tkinter (included with the python.org macOS and Windows installers).
git clone https://github.com/ali-ezz/evolutionary-algorithms-visualizer.git
cd evolutionary-algorithms-visualizer
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -r requirements.txt
python3 ProjectGA.pyIn the window: pick an algorithm and a benchmark function, set population size, generations, crossover rate, and mutation or differential weight, then start the run.
Headless run of both algorithms on the 2D Rosenbrock function, with population 100, 200 generations, crossover rate 0.8, GA mutation rate 0.1, DE differential weight 0.8, and NumPy seed 42. Produced by a script that imports the GA and DE classes from ProjectGA.py without starting the GUI, on macOS with Python 3.14.7:
| Algorithm | Best fitness | Best x | Run time |
|---|---|---|---|
| Genetic algorithm | 0.0306332 | (1.1749, 1.3810) | 0.13 s |
| Differential evolution | 2.00875e-20 | (1.0000, 1.0000) | 0.22 s |
These are results from one seed and one run, not a benchmark study.
- Checked: the GA and DE classes run to completion on the Rosenbrock function, and the chart in
docs/images/is generated from that run. - Not verified: launching the Tkinter GUI, the Results, Visualization, and Analysis tabs, and the other four benchmark functions. The headless run used a Python without Tkinter, so the script stubbed the Tkinter modules before importing
ProjectGA.py. - Not verified: Python versions other than 3.14.7.
- No automated tests in the repository.
- Results depend on the random seed and parameters; one run does not show typical performance.
- The GA mutation rate is fixed. The code comment calls it adaptive, but it is not.
- The app has no export of results to files.
- Benchmark functions are continuous and unconstrained beyond the search bounds.
.
├── ProjectGA.py # GA, DE, benchmark functions, Tkinter GUI
├── requirements.txt # numpy and matplotlib, pinned
├── docs/images/
│ └── convergence.png # chart from a headless run
├── .github/ # issue and pull request templates
├── CHANGELOG.md
├── CONTRIBUTING.md
├── CODE_OF_CONDUCT.md
├── SECURITY.md
└── LICENSE
Team project: a six-person course project. The git history in this repository has one author, Ali Alyan. No roles are claimed here.
MIT License. See LICENSE.
