#algorithm #optimization #metaheuristic

no-std metaheuristics-nature

A collection of nature-inspired meta-heuristic algorithms

66 releases (40 stable)

new 9.2.1 Jun 9, 2023
9.0.1 Apr 26, 2023
8.0.4 Nov 21, 2022
7.7.0 Nov 19, 2022
0.8.0 Jul 27, 2021

#194 in Algorithms

Download history 183/week @ 2023-02-17 43/week @ 2023-02-24 56/week @ 2023-03-03 66/week @ 2023-03-10 100/week @ 2023-03-17 188/week @ 2023-03-24 105/week @ 2023-03-31 199/week @ 2023-04-07 177/week @ 2023-04-14 78/week @ 2023-04-21 66/week @ 2023-04-28 123/week @ 2023-05-05 91/week @ 2023-05-12 153/week @ 2023-05-19 164/week @ 2023-05-26 102/week @ 2023-06-02

514 downloads per month
Used in 2 crates (via four-bar)

MIT license

1.5K SLoC


dependency status documentation

A collection of nature-inspired metaheuristic algorithms. This crate provides objective function trait, well-known methods, and tool functions let you implement your own searching method.

This crate implemented following algorithms:

  • Real-coded Genetic Algorithm (RGA)
  • Differential Evolution (DE)
  • Particle Swarm Optimization (PSO)
  • Firefly Algorithm (FA)
  • Teaching-Learning Based Optimization (TLBO)

Each algorithm gives same API and default parameters to help you test different implementation. For example, you can test another algorithm by simply replacing Rga to De.

use metaheuristics_nature::{Rga, Solver};

let mut report = Vec::with_capacity(20);

// Build and run the solver
let s = Solver::build(Rga::default(), MyFunc::new())
    .task(|ctx| ctx.gen == 20)
    .callback(|ctx| report.push(ctx.best_f))
// Get the optimized XY value of your function
let xs = s.best_parameters();
let y = s.best_fitness();
// Get the history reports
let y2 = report[2];

What kinds of problems can be solved?

If your problem can be simulated and evaluated, the optimization method is the efficient way to find the best design! 🚀

Assuming that your simulation can be done with a function f, by inputting the parameters X and the evaluation value y, then the optimization method will try to adjust X={x0, x1, ...} to obtain the smallest y. Their relationship can be written as f(X) = y.

The number of the parameters X is called "dimension", imagine X is the coordinate in the multi-dimension, and y is the weight of the "point". If the dimension becomes higher, the problem will be more difficult to search.

The "metaheuristic" algorithms use multiple points to search for the minimum value, which detects the local gradient, across the most feasible solutions and keeps away from the local optimum. Even with an unknown gradient or feasible region.

Please see the API documentation for more information.

Gradient-based Methods

For more simple functions, for example, if the 1st derivative function is known, the gradient-based methods are recommended to use for the fastest speed. Such as OSQP.


~63K SLoC