1 unstable release
new 0.1.7 | Dec 5, 2024 |
---|---|
0.1.6 |
|
0.1.4 |
|
0.1.3 |
|
#231 in Algorithms
422 downloads per month
Used in neuros
255KB
4.5K
SLoC
Sefar
Sefar is a simple and comprehensive Rust library for evolutionary optimization algorithms, exclusively written using Rust safe code. It supports continuous and binary optimization in both sequential and parallel modes. In the current version, the parallel mode executes objective function evaluations in parallel (multi-threading) using rayon crate.
Current state (Under development)
-
Sefar perfoms minimization by default. In the case of maximization, the objective function $f(X)$ can be expressed as $-f(X)$.
-
In this version, Sefar supports:
- Particle Swarm Optimization (PSO);
- Equilibrium optimizer (EO);
- Binary Equilibrium Optimizer (BiEO);
- Modified Equilibrium optimizer (MEO);
- Growth Optimizer (GO);
- Gaining-Sharing Knowledge (GSK);
- Gaining-Sharing Knowledge Based Algorithm With Adaptive Parameters (APGSK);
- LSHADE_SPACMA(LSHADE_SPACMA)
Binary optimization
The binary optimizatin in the older versions of Sefar will be replaced by more efficent binary optimization algorithms.* This approach aims to simplify the implementation of algorithms on one hand and to offer parallel mode for binary algorithms as well in simple way.
Parallel optimization
In the current version of Sefar, only the objective function evaluation is run in parallel mode using rayon crate.
Example
- Import Sefar in the Cargo.Toml file of your project.
[dependencies]
sefar = "0.1.7"
- In the main.rs file :
extern crate sefar;
use sefar::core::eoa::EOA;
use sefar::core::optimization_result::OptimizationResult;
use sefar::algos::go::{GOparams, GO};
use sefar::core::problem::Problem;
fn main() {
println!("Optimization using Growth optimizer in Sefar crate:");
// Define the parameters of GO:
let search_agents : usize = 20; // number of search agents.
let dim : usize = 5; // problem dimension.
let max_iterations : usize = 200; // maximum number of iterations.
let lb = vec![-100.0; dim]; // lower bound of search space.
let ub = vec![100.0; dim]; // upper bound of the search space.
// Build the parameter struct:
let settings : GOparams = GOparams::new(search_agents, dim, max_iterations, &lb, &ub);
// Define the problem to optimize:
let mut fo = F1{};
// Build the optimizer:
let mut algo : GO<F1> = GO::new(&settings, &mut fo);
// Run the GO algorithm:
let result : OptimizationResult = algo.run();
// Print the results:
println!("The optimization results of GO : {}", result.to_string());
// The result will be something like :
// The optimization results of GO : Best-fitness : Some(1.2106003206412792e-54);
// Best-solution : Some(Genome { id: 22, genes: [-7.586125521377413e-28, -7.519595439155215e-28, -2.2218253597758204e-29, -6.135485510888784e-29, -3.7827445210037567e-28], fitness: Some(1.2882857900967827e-54) });
// Time : Some(11.606888ms);
// Err-report: None
}
// Define the objective function to minimize. Here, the Sphere function is implemented.
///
/// F1 : Sphere benchmark function.
/// Fi(X) = Sum(|X^2|)
/// where X = {x1, x2, ..... xd}, and 'd' is the problem dimension.
///
#[derive(Debug,Clone)]
pub struct F1{}
impl Problem for F1 {
fn objectivefunction(&mut self, genome : &[f64])->f64 {
genome.iter().fold(0.0f64, |sum, x| sum + x.powi(2))
}
}
Supported features
Sefar supports report and parallel features.
- Run report feature:
# run report feature:
cargo run --features report;
# run parallel feature:
cargo run --features parallel;
Algorithm | report feature | parallel feature |
---|---|---|
PSO | ✔️ | |
EO | ✔️ | ✔️ |
GO | ✔️ | ✔️ |
GSK | ✔️ | ✔️ |
LSHADE_SPACMA | ||
BiEO | ✔️ |
Dependencies
~4.5MB
~79K SLoC