Optirustic
Optirustic is a framework written in Rust that provides algorithms and analysis tool to solve multi-objective problems using multi-objective evolutionary algorithms (MOEAs). It allows you to:
- define minimisation and maximisation problems with custom objective functions;
- define constraint and unconstrained variables (real, integer, boolean or choice);
- use multi-thread to evaluate objectives and constraints on population with many individuals
At the moment, it comes with the NSGA2 and NSGA3 algorithms.
Installing Optirustic
Optirustic is available on crates.io. The recommended way to use it is to add a line into your Cargo.toml:
[]
= "*"
Example
Problem definition
In this example, we are going to solve the Schaffer’s problem with the NSGA2 algorithm.
The problem aims to minimise the following 2 objectives:
- f1(x) = x2
- f2(x) = (x - 2)2
The problem has 1 variable (x) bounded to -1000 and 1000. The optional solution is expected
to lie in the [0; 2] range.
Problem implementation
The problem is implemented below using the SCHProblem struct. When an algorithm runs,
it first generates a set of potential solutions for the problem variables (in this case x). It
then calculates the objectives (f1(x) and f2(x)) in the Evaluator
trait exposed by this library.
;
// Implement the function to evaluate the objectives and constraints. The `evaluate`
// function below receives the individuals which contain the variables/solutions `x`
// proposed by the algorithm. The function must returns the evaluated objectives and
// constraints in the `EvaluationResult` struct.
Setup and run the genetic algorithm
The code below set up the NSGA2 algorithm with 100 individuals and will
stop when 250 population generations are reached.
...
The full example is available in the examples folder of this repository and can be run using
cargo run --example nsga2_sch --release
This is the serialised data exported by the algorithm: SCH_2obj_NSGA2_gen250.json and these are the plotted solutions:
Additional examples
Additional examples showcasing this library's features are available in the examples folder of this repository.