1 unstable release
0.1.4 | May 2, 2024 |
---|---|
0.1.3 |
|
0.1.2 |
|
0.1.1 |
|
0.1.0 |
|
#389 in Algorithms
Used in neuros
120KB
2K
SLoC
Sefar
Sefar is a simple and comprehensive Rust library for evolutionary optimization algorithms, exclusively written using safe code. It supports continuous and binary optimization in both sequential and parallel modes through its features. In the current version, the parallel mode executes objective function evaluations in parallel (multi-threading) using the 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);
- [] Modified Equilibrium optimizer (MEO);
- Growth Optimizer (GO).
Important
In the current version, binary and parallel optimization are implemented exclusively for the Equilibrium Optimizer (EO) and the Growth Optimizer (GO). Soon, these features will be available for the other algorithms as well.
Binary optimization
In the current version, binarization is performed using the S-Shape function provided below:
$S(x) = 1/(1 + e^{(-x)})$
In this context, x represents a "gene" and signifies each element in the candidate solution X ("genome") within a search space of length d, where $X= {x_1, x_2, ..., x_d}$.
The Binary optimization can be executed using the binary feature.
Example
- Import Sefar with binary feature in the Cargo.Toml file of your project.
[dependencies]
sefar = {version = "0.1.3", features = ["binary"]}
- 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!("Binary optimization using Growth optimizer in Sefar crate:");
go_f1_binary_test();
}
///
/// run the binary version of Growth Optimizer (Binary-GO).
///
fn go_f1_binary_test(){
// Define the parameters of GO:
let search_agents : usize = 20;
let dim : usize = 10;
let max_iterations : usize = 100;
let lb = vec![0.0; dim];
let ub = vec![1.0; dim];
// 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 Binary-GO : {}", result.to_string());
// The results show something like :
// Binary optimization using Growth optimizer in Sefar crate:
// The optimization results of Binary-GO : Best-fitness : Some(0.0)
// ; Best-solution : Some(Genome { id: 22, genes: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], fitness: Some(0.0) })
// ; Time : Some(3.326498ms)
// ; Err-report: None
}
// Define the objective function to minimize. Here, the Sphere function is implemented.
///
/// F1 : Sphere benchmark function.
/// Fi(X) = Sum(|X|)
/// 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)
}
}
Supported features
Features | Designation |
---|---|
binary | Run binary optimization using S-Shape function (only with EO & GO) |
parallel | Run optimization in parallel mode using Rayon crate (only with EO & GO) |
report | Show the evolution of the optimization process at each iteration |
Dependencies
~4.5MB
~79K SLoC