Crates.io | sefar |
lib.rs | sefar |
version | 0.1.4 |
source | src |
created_at | 2024-04-05 18:13:08.937107 |
updated_at | 2024-05-02 14:31:51.315938 |
description | sefar is library for evolutionary optimization algorithms. |
homepage | |
repository | |
max_upload_size | |
id | 1197605 |
size | 125,647 |
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.
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:
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.
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.
[dependencies]
sefar = {version = "0.1.3", features = ["binary"]}
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)
}
}
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 |