RandomTieBreaker

Struct RandomTieBreaker 

Source
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::Maximum and 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::Minimum and 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_variables where num_previously_seen_variables is the number of variables which have been previously considered with the same value

Implementations§

Source§

impl<Var, Value> RandomTieBreaker<Var, Value>

Source

pub fn new( direction: Direction, rng: Box<dyn Random>, ) -> RandomTieBreaker<Var, Value>

Trait Implementations§

Source§

impl<Var, Value> Debug for RandomTieBreaker<Var, Value>

Source§

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

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

impl<Var, Value> TieBreaker<Var, Value> for RandomTieBreaker<Var, Value>
where Var: Copy, Value: PartialOrd,

Source§

fn consider(&mut self, variable: Var, value: Value)

Consider the next additional element with corresponding value
Source§

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

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>
where Var: Freeze, Value: Freeze,

§

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>
where Var: Unpin, Value: Unpin,

§

impl<Var, Value> !UnwindSafe for RandomTieBreaker<Var, Value>

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> Downcast for T
where T: Any,

Source§

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>

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)

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)

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> 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
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V