Crate metaheuristics_nature[][src]

Expand description

A collection of nature-inspired metaheuristic algorithms.

use metaheuristics_nature::{Report, RGA, RGASetting, Solver, Task, ObjFunc};

let a = RGA::solve(
    MyFunc::new(),
    RGASetting::default().task(Task::MinFit(1e-20)),
    |_| true // Run without callback
);
let ans: f64 = a.result(); // Get the result from objective function
let (x, y): (Array1<f64>, f64) = a.parameters(); // Get the optimized XY value of your function
let history: Vec<Report> = a.history(); // Get the history reports

There are two traits Algorithm and Solver. The previous is used to design the optimization method, and the latter is a simple interface for obtaining the solution, or analyzing the result.

Solver will automatically implement for the type which implements Algorithm.

Objective Function

You can define your question as a objective function through implementing ObjFunc.

First of all, the array types are ndarray::ArrayBase. And then you should define the upper bound, lower bound, and objective function ObjFunc::fitness by yourself.

The final answer is ObjFunc::result, which is generated from the design parameters.

Random Function

This crate use 32bit PRNG algorithm to generate random value, before that, a random seed is required. The seed is generated by getrandom, please see its support platform.

Features

  • std: Default feature. Enable standard library function, such as timing and threading.
  • parallel: Enable parallel function, let objective function running without ordered, uses std::thread::spawn. Disable it for the platform that doesn’t supported threading, or if your objective function is not complicate enough.
  • wasm: Support for webassembly, especial for random seed generating.

Modules

The random function for building algorithm.

Macros

Define a data structure and its builder functions.

Structs

The base class of algorithms. Please see Algorithm for more information.

Differential Evolution type.

Differential Evolution settings.

Firefly Algorithm type.

Firefly Algorithm settings.

Particle Swarm Optimization type.

Particle Swarm Optimization settings.

Real-coded Genetic Algorithm type.

Real-coded Genetic Algorithm settings.

The data of generation sampling.

Base settings.

Teaching Learning Based Optimization type.

Enums

The Differential Evolution strategy. Each strategy has different formulas on the recombination.

The terminal condition of the algorithm setting.

Traits

The methods of the metaheuristic algorithms.

The base of the objective function.

A public API for Algorithm.

Functions

Product two iterators together.

Type Definitions

Teaching Learning Based Optimization settings. This is a type alias to Setting.