This repository contains a Python implementation of the Gravitational Search Algorithm (GSA), a physics-inspired metaheuristic optimization algorithm. The implementation includes several benchmark functions and visualization tools for analyzing the algorithm's performance.
- Pure NumPy implementation of GSA
- Multiple benchmark functions (Sphere, Rastrigin, Rosenbrock, Ackley)
- Population size analysis tools
- Visualization of convergence behavior
- Comprehensive documentation and examples
git clone https://github.com/yourusername/gsa-optimization.git
cd gsa-optimization
pip install -r requirements.txtBasic usage example:
from src.gsa import gravitational_search
import numpy as np
# Run GSA optimization
best_position, best_fitness = gravitational_search(
n_particles=30,
n_dimensions=30,
fitness_function='sphere'
)For more examples, check the examples/ directory.
The examples show:
-
simple_example.py: Basic usage of GSA
-
compare_functions.py: How GSA performs on different optimization problems
-
population_study.py: How population size affects optimization performance
python examples/simple_example.py
# Compare different functions
python examples/compare_functions.py
# Study population sizes
python examples/population_study.pyThe implementation includes several standard benchmark functions:
- Sphere Function (unimodal)
- Rastrigin Function (multimodal)
- Rosenbrock Function (valley-shaped)
- Ackley Function (multimodal)
Example convergence analysis for different population sizes on the Rosenbrock function:
[
]
- numpy
- matplotlib
- time
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request