Crates.io | sefar |
lib.rs | sefar |
version | |
source | src |
created_at | 2024-04-05 18:13:08.937107 |
updated_at | 2024-12-05 17:50:31.649018 |
description | sefar is library for evolutionary optimization algorithms. |
homepage | |
repository | |
max_upload_size | |
id | 1197605 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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.
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:
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.
In the current version of Sefar, only the objective function evaluation is run in parallel mode using rayon crate.
[dependencies]
sefar = "0.1.7"
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))
}
}
Sefar supports report and parallel features.
# run report feature:
cargo run --features report;
# run parallel feature:
cargo run --features parallel;
Algorithm | report feature | parallel feature |
---|---|---|
PSO | :heavy_check_mark: | |
EO | :heavy_check_mark: | :heavy_check_mark: |
GO | :heavy_check_mark: | :heavy_check_mark: |
GSK | :heavy_check_mark: | :heavy_check_mark: |
LSHADE_SPACMA | ||
BiEO | :heavy_check_mark: |