This project implements and compares different Genetic Algorithm (GA) configurations for optimizing two benchmark functions: the 2D Rastrigin function and the Schaffer N.2 function.
The Report.pdf file contains a deep-dive paper.
- Formula: f(x,y) = 20 + x² + y² - 10(cos(2πx) + cos(2πy))
- Domain: [-5.12, 5.12] × [-5.12, 5.12]
- Global minimum: f(0,0) = 0
- Formula: f(x,y) = 0.5 + (sin²(x² - y²) - 0.5) / (1 + 0.001(x² + y²))²
- Domain: [-100, 100] × [-100, 100]
- Global minimum: f(0,0) = 0
The project implements two types of genetic algorithms:
- One-point crossover
- Two-point crossover
- Bit-flip mutation
- Arithmetic crossover
- BLX-α crossover
- Gaussian mutation
Project/
├── src/
│ ├── functions/
│ │ └── benchmark_functions.py
│ ├── genetic_algorithm/
│ │ ├── base_ga.py
│ │ ├── binary_ga.py
│ │ └── real_valued_ga.py
│ ├── visualization/
│ │ └── plot_functions.py
│ └── analysis/
│ └── statistical_analysis.py
├── out/
│ ├── plots/
│ │ ├── contour_plots.png
│ │ ├── surface_plots.png
│ │ ├── rastrigin_comparison.png
│ │ ├── rastrigin_convergence.png
│ │ ├── schaffer_comparison.png
│ │ └── schaffer_convergence.png
│ └── results/
├── main.py
├── requirements.txt
└── README.md
- Python 3.7+
- numpy
- matplotlib
- scipy
- pandas
- seaborn
Install dependencies:
pip install -r requirements.txtRun the main script to execute the experiments:
python main.pyThis will:
- Create the necessary output directories
- Generate visualization plots for both benchmark functions
- Run experiments with different GA configurations
- Perform statistical analysis
- Generate comparison plots and convergence curves
The script generates several output files in the out directory:
contour_plots.png: 2D contour plots of the benchmark functionssurface_plots.png: 3D surface plots of the benchmark functionsrastrigin_comparison.png: Box plots comparing GA configurations for Rastrigin functionrastrigin_convergence.png: Convergence curves for Rastrigin functionschaffer_comparison.png: Box plots comparing GA configurations for Schaffer functionschaffer_convergence.png: Convergence curves for Schaffer function
- Directory for storing any additional results or data files
The analysis includes:
- Summary statistics (mean, standard deviation, min, max)
- ANOVA test to compare all configurations
- Pairwise t-tests between different configurations
- Visualization of results using box plots and convergence curves