Skip to main content

MultiObjective

Trait MultiObjective 

Source
pub trait MultiObjective<G: ?Sized> {
    // Required methods
    fn objectives(&self) -> usize;
    fn evaluate(&mut self, genome: &G, out: &mut [f64]) -> f64;
}
Expand description

Several costs to minimise at once, plus a constraint violation.

The violation is 0 for a feasible genome and grows with how far it is from feasibility (Jakob’s rule: never flatten infeasibility). Constrained domination prefers feasible over infeasible genomes and, among infeasible ones, the smaller violation (Deb 2000).

use evolutionary_planning::{MultiObjective, multi_objective_fn};

// Schaffer's problem: minimise x^2 and (x - 2)^2.
let mut schaffer = multi_objective_fn(2, |x: &f64, out: &mut [f64]| {
    out[0] = x * x;
    out[1] = (x - 2.0) * (x - 2.0);
    0.0
});
let mut out = [0.0; 2];
assert_eq!(schaffer.evaluate(&1.0, &mut out), 0.0);
assert_eq!(out, [1.0, 1.0]);

Required Methods§

Source

fn objectives(&self) -> usize

The number of objectives, m >= 1; constant for the lifetime of the problem.

Source

fn evaluate(&mut self, genome: &G, out: &mut [f64]) -> f64

Writes the m costs of genome into out (of length MultiObjective::objectives) and returns its constraint violation (0 if feasible, NaN treated as +∞).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<G: ?Sized, M: MultiObjective<G> + ?Sized> MultiObjective<G> for &mut M

Source§

fn objectives(&self) -> usize

Source§

fn evaluate(&mut self, genome: &G, out: &mut [f64]) -> f64

Implementors§