pub struct RandomTieBreaker<Var, Value> { /* private fields */ }Expand description
A tie breaker which selects the variable with the “best” value (according to the Direction),
if there is a tie then it will select any of the variables part of this tie with equal
probability.
The random selection proceeds as follows:
- If no variable has been considered yet then this is the one which is currently considered to be selected
- If a variable has previously been considered then we can split into 3 cases:
- If the direction is
Direction::Maximumand the value of the newly provided variable is stricly bigger than that of the currently selected variable then we update the currently selected variable - If the direction is
Direction::Minimumand the value of the newly provided variable is stricly smaller than that of the currently selected variable then we update the currently selected variable - If the values are equal then we randomly select the newly considered variable with
probability
1 / num_previously_seen_variableswherenum_previously_seen_variablesis the number of variables which have been previously considered with the same value
- If the direction is
Implementations§
Source§impl<Var, Value> RandomTieBreaker<Var, Value>
impl<Var, Value> RandomTieBreaker<Var, Value>
Trait Implementations§
Source§impl<Var, Value> Debug for RandomTieBreaker<Var, Value>
impl<Var, Value> Debug for RandomTieBreaker<Var, Value>
Source§impl<Var, Value> TieBreaker<Var, Value> for RandomTieBreaker<Var, Value>where
Var: Copy,
Value: PartialOrd,
impl<Var, Value> TieBreaker<Var, Value> for RandomTieBreaker<Var, Value>where
Var: Copy,
Value: PartialOrd,
Source§fn consider(&mut self, variable: Var, value: Value)
fn consider(&mut self, variable: Var, value: Value)
Consider the next additional element with corresponding value
Source§fn select(&mut self) -> Option<Var>
fn select(&mut self) -> Option<Var>
Get the final variable which was selected. After this method is called it resets the stored
values such that it can be used again. This resetting is done to prevent the tie-breaker
from returning a variable which has a value which is out-of-date.
Source§fn get_direction(&self) -> Direction
fn get_direction(&self) -> Direction
Returns whether the tie-breaker is attempting to find the minimum (
Direction::Minimum)
or maximum (Direction::Maximum) element.Auto Trait Implementations§
impl<Var, Value> Freeze for RandomTieBreaker<Var, Value>
impl<Var, Value> !RefUnwindSafe for RandomTieBreaker<Var, Value>
impl<Var, Value> !Send for RandomTieBreaker<Var, Value>
impl<Var, Value> !Sync for RandomTieBreaker<Var, Value>
impl<Var, Value> Unpin for RandomTieBreaker<Var, Value>
impl<Var, Value> !UnwindSafe for RandomTieBreaker<Var, Value>
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
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.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>
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 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>
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