Skip to main content

Nsga2

Struct Nsga2 

Source
pub struct Nsga2 { /* private fields */ }
Expand description

The optimizer’s settings: the variables, the number of goals, the population, the number of generations, and the crossover’s and mutation’s parameters. It serializes as its fields, and reads back through the same checks as Nsga2::new and its with_ methods.

Implementations§

Source§

impl Nsga2

Source

pub fn new( variables: Vec<Variable>, objectives: usize, ) -> Result<Self, AnalysisError>

The optimizer over variables for objectives goals, with the paper’s settings: a population of 100, 250 generations, crossover probability 0.9 and η_c = 20, mutation probability 1/n and η_m = 20.

§Errors

AnalysisError::TooFew or AnalysisError::Count for no variables or more than MAX_VARIABLES, or no goals or more than MAX_OBJECTIVES; AnalysisError::DuplicateVariable for two variables of one name; AnalysisError::Domain for a variable without two finite bounds, or with one beyond MAX_BOUND; and AnalysisError::Unsupported for an integer variable.

Source

pub fn with_population(self, size: usize) -> Result<Self, AnalysisError>

The same optimizer with a population of size: an even number, as children are bred two at a time, from 4 to MAX_POPULATION.

§Errors

AnalysisError::TooFew below 4, AnalysisError::Count above MAX_POPULATION, and AnalysisError::Domain for an odd size.

Source

pub fn with_generations(self, generations: usize) -> Result<Self, AnalysisError>

The same optimizer, run for generations generations, the first, random one included: it evaluates the population that many times.

§Errors

AnalysisError::TooFew for none.

Source

pub fn with_crossover( self, probability: f64, index: f64, ) -> Result<Self, AnalysisError>

The same optimizer with SBX crossing a pair of parents with probability, and distribution index index: the larger, the closer children fall to their parents.

§Errors

AnalysisError::Domain for a probability outside [0, 1], or an index that is negative or not finite.

Source

pub fn with_mutation( self, probability: f64, index: f64, ) -> Result<Self, AnalysisError>

The same optimizer with polynomial mutation changing each variable of a child with probability, and distribution index index: the larger, the smaller the changes.

§Errors

As Nsga2::with_crossover.

Source

pub fn variables(&self) -> &[Variable]

The variables.

Source

pub fn objectives(&self) -> usize

The number of goals.

Source

pub fn population(&self) -> usize

The population’s size.

Source

pub fn generations(&self) -> usize

The number of generations.

Source

pub fn start(&self, seed: u64) -> Run

Starts a run from seed: its first candidates are the random first population.

Source

pub fn minimize_constrained( &self, seed: u64, model: impl FnMut(&[f64]) -> Goals, ) -> Result<Front, AnalysisError>

Runs NSGA-II on model under constraints from seed, evaluating each candidate in turn.

§Errors

Run::tell_constrained’s.

Source

pub fn minimize( &self, seed: u64, model: impl FnMut(&[f64]) -> Vec<f64>, ) -> Result<Front, AnalysisError>

Runs NSGA-II on model from seed, evaluating each candidate in turn: the model gives each candidate’s goals, every one to be made as small as it can be.

§Errors

Run::tell’s.

Trait Implementations§

Source§

impl Clone for Nsga2

Source§

fn clone(&self) -> Nsga2

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Nsga2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Nsga2

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Nsga2

Source§

fn eq(&self, other: &Nsga2) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Nsga2

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Nsga2

Auto Trait Implementations§

§

impl Freeze for Nsga2

§

impl RefUnwindSafe for Nsga2

§

impl Send for Nsga2

§

impl Sync for Nsga2

§

impl Unpin for Nsga2

§

impl UnsafeUnpin for Nsga2

§

impl UnwindSafe for Nsga2

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.