pub struct Mode { /* private fields */ }Expand description
Stateful constrained MODE optimizer.
Objective columns precede constraint columns in every row passed to
tell; constraints are feasible when they are non-positive.
Implementations§
Source§impl Mode
impl Mode
Sourcepub fn try_new(
fitfun: Fitness,
nobj: usize,
ncon: usize,
ints: Option<Vec<bool>>,
p: &ModeParams,
) -> Result<Self, &'static str>
pub fn try_new( fitfun: Fitness, nobj: usize, ncon: usize, ints: Option<Vec<bool>>, p: &ModeParams, ) -> Result<Self, &'static str>
Construct MODE after validating dimensions, bounds, population size, probabilities, and the optional integer mask.
§Errors
Returns an error if the fitness dimension or bounds are inconsistent,
if nobj is zero, if the population size is below four, if any
probability parameter is outside its valid range, or if a supplied
integer mask does not have one entry per decision variable.
Sourcepub fn new(
fitfun: Fitness,
nobj: usize,
ncon: usize,
ints: Option<Vec<bool>>,
p: &ModeParams,
) -> Self
pub fn new( fitfun: Fitness, nobj: usize, ncon: usize, ints: Option<Vec<bool>>, p: &ModeParams, ) -> Self
Construct MODE, panicking on invalid configuration. Applications that
accept user input should prefer Mode::try_new.
§Panics
Panics on any configuration Mode::try_new rejects.
Sourcepub fn ask(&mut self) -> Vec<Vec<f64>>
pub fn ask(&mut self) -> Vec<Vec<f64>>
Ask for popsize offspring rows.
§Panics
Panics if a previous batch is still pending, that is if ask is called
twice without an intervening tell. Use Mode::try_ask to receive
that as an error instead.
Sourcepub fn try_ask(&mut self) -> Result<Vec<Vec<f64>>, &'static str>
pub fn try_ask(&mut self) -> Result<Vec<Vec<f64>>, &'static str>
Fallible ask variant for interfaces that need to report call-order errors rather than panic.
§Errors
Returns an error if the previously asked batch has not been told yet.
Sourcepub fn tell(&mut self, ys: &[Vec<f64>]) -> i32
pub fn tell(&mut self, ys: &[Vec<f64>]) -> i32
Tell objective+constraint values for the offspring from ask.
§Panics
Panics if no batch is pending, if ys does not have popsize rows, or
if a row width differs from nobj + ncon. Use Mode::try_tell to
receive these as errors instead.
Sourcepub fn try_tell(&mut self, ys: &[Vec<f64>]) -> Result<i32, &'static str>
pub fn try_tell(&mut self, ys: &[Vec<f64>]) -> Result<i32, &'static str>
Fallible tell variant validating call order and matrix shape.
§Errors
Returns an error if no batch is pending, if ys does not have
popsize rows, or if a row width differs from nobj + ncon.
Sourcepub fn tell_switch(
&mut self,
ys: &[Vec<f64>],
nsga_update: bool,
pareto_update: f64,
) -> i32
pub fn tell_switch( &mut self, ys: &[Vec<f64>], nsga_update: bool, pareto_update: f64, ) -> i32
Tell values while switching the population-update mode.
§Panics
Panics on everything Mode::tell panics on, and additionally if
pareto_update is not finite. Use Mode::try_tell_switch for the
fallible form.
Sourcepub fn try_tell_switch(
&mut self,
ys: &[Vec<f64>],
nsga_update: bool,
pareto_update: f64,
) -> Result<i32, &'static str>
pub fn try_tell_switch( &mut self, ys: &[Vec<f64>], nsga_update: bool, pareto_update: f64, ) -> Result<i32, &'static str>
Fallible tell_switch variant validating the
update probability and pending batch.
§Errors
Returns an error if pareto_update is not finite, or for any condition
Mode::try_tell rejects.
Sourcepub fn set_population(&mut self, xs: &[Vec<f64>], ys: &[Vec<f64>]) -> i32
pub fn set_population(&mut self, xs: &[Vec<f64>], ys: &[Vec<f64>]) -> i32
Replace the candidate population and tell its values.
§Panics
Panics if the population size is below four, or if xs/ys shapes do
not match the configured dimension and value width. Use
Mode::try_set_population for the fallible form.
Sourcepub fn try_set_population(
&mut self,
xs: &[Vec<f64>],
ys: &[Vec<f64>],
) -> Result<i32, &'static str>
pub fn try_set_population( &mut self, xs: &[Vec<f64>], ys: &[Vec<f64>], ) -> Result<i32, &'static str>
Fallible set_population variant validating
dimensions and population sizes.
§Errors
Returns an error if the population size is below four, if xs and ys
have different lengths, if a decision row width differs from the
configured dimension, or if a value row width differs from
nobj + ncon.
Sourcepub fn population(&self) -> Vec<Vec<f64>>
pub fn population(&self) -> Vec<Vec<f64>>
Current population (rows = individuals).
Sourcepub fn result(&self) -> ModeResult
pub fn result(&self) -> ModeResult
Return a snapshot of the current population and its values.
Auto Trait Implementations§
impl Freeze for Mode
impl RefUnwindSafe for Mode
impl Send for Mode
impl Sync for Mode
impl Unpin for Mode
impl UnsafeUnpin for Mode
impl UnwindSafe for Mode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.