A comprehensive Rust library for metaheuristic optimization algorithms, providing efficient implementations of various optimization techniques.
- Particle Swarm Optimization (PSO)
- Differential Evolution (DE)
- Genetic Algorithm (GA)
- Simulated Annealing (SA)
- Artificial Bee Colony Optimization (ABCO)
- Grey Wolf Optimizer (GWO)
- Many more to come in future releases...
- Sphere Function
- Ackley Function
- Rosenbrock Function
- Rastrigin Function
- Many more to come in future releases...
- 2D Contour Plots
- 3D Surface Plots
- Multiple Plot Formats (PNG)
Add this to your Cargo.toml
:
[dependencies]
metaheurustics = "0.1.0"
Here's a simple example using PSO to minimize the Sphere function:
use metaheurustics::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a 2D sphere optimization problem
let sphere = Sphere::new(2);
// Configure PSO parameters
let params = PSOParams {
opt_params: OptimizationParams {
population_size: 30,
max_iterations: 100,
target_value: Some(1e-4),
},
w: 0.9,
c1: 2.0,
c2: 2.0,
w_decay: 0.01,
};
// Create and run optimizer
let optimizer = PSO::new(&sphere, params);
let result = optimizer.optimize()?;
println!("Best solution: {:?}", result.best_solution);
println!("Best fitness: {}", result.best_fitness);
Ok(())
}
For detailed documentation and examples, visit:
The library includes several example programs:
simple_optimization.rs
: Compare different algorithms on the Rosenbrock functionoptimize_sphere.rs
: Basic PSO optimization with visualizationalgorithm_comparison.rs
: Comprehensive comparison of all algorithms
Run examples using:
cargo run --example simple_optimization
cargo run --example optimize_sphere
cargo run --example algorithm_comparison
The library provides both 2D contour plots and 3D surface plots:
// Create plots directory
let plot_dir = "plots";
fs::create_dir_all(plot_dir)?;
// Generate plots
plot_2d_landscape(&problem, Some(&result.best_solution), "contour.png")?;
plot_3d_landscape(&problem, Some(&result.best_solution), "surface.png")?;
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.
If you use this library in your research, please cite:
@software{metaheurustics,
author = {Shah, Arya},
title = {MetaheuRUSTics: A Rust Library for Optimization Algorithms},
year = {2025},
publisher = {GitHub},
url = {https://github.com/aryashah2k/metaheurustics}
}