Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Genetic Algorithm Optimization for Benchmark Functions

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.

Functions

1. 2D Rastrigin Function

  • 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

2. Schaffer N.2 Function

  • 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

Genetic Algorithm Implementations

The project implements two types of genetic algorithms:

1. Binary Encoding

  • One-point crossover
  • Two-point crossover
  • Bit-flip mutation

2. Real-valued Encoding

  • Arithmetic crossover
  • BLX-α crossover
  • Gaussian mutation

Project Structure

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

Requirements

  • Python 3.7+
  • numpy
  • matplotlib
  • scipy
  • pandas
  • seaborn

Install dependencies:

pip install -r requirements.txt

Usage

Run the main script to execute the experiments:

python main.py

This will:

  1. Create the necessary output directories
  2. Generate visualization plots for both benchmark functions
  3. Run experiments with different GA configurations
  4. Perform statistical analysis
  5. Generate comparison plots and convergence curves

Output

The script generates several output files in the out directory:

Plots (out/plots/)

  • contour_plots.png: 2D contour plots of the benchmark functions
  • surface_plots.png: 3D surface plots of the benchmark functions
  • rastrigin_comparison.png: Box plots comparing GA configurations for Rastrigin function
  • rastrigin_convergence.png: Convergence curves for Rastrigin function
  • schaffer_comparison.png: Box plots comparing GA configurations for Schaffer function
  • schaffer_convergence.png: Convergence curves for Schaffer function

Results (out/results/)

  • Directory for storing any additional results or data files

Statistical Analysis

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages