pub struct UniqueElementsConstraint<P, T, F>where
P: Phenotype,
T: Eq + Hash + Debug + Clone + Send + Sync,
F: Fn(&P) -> Vec<T> + Send + Sync + Debug,{ /* private fields */ }Expand description
Ensures that all elements in a collection are unique.
This constraint is useful for problems where each element can only be used once, such as assignment problems or permutation problems.
Implementations§
Source§impl<P, T, F> UniqueElementsConstraint<P, T, F>
impl<P, T, F> UniqueElementsConstraint<P, T, F>
Sourcepub fn new<S: Into<String>>(name: S, extractor: F) -> Result<Self>
pub fn new<S: Into<String>>(name: S, extractor: F) -> Result<Self>
Creates a new unique elements constraint with the given name and extractor function.
The extractor function is used to extract the elements to check for uniqueness from the phenotype.
§Arguments
name- The name of the constraint for error messages.extractor- A function that extracts the elements to check for uniqueness from the phenotype.
§Returns
A new unique elements constraint, or an error if the name is empty.
Trait Implementations§
Source§impl<P, T, F> Clone for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Clone for UniqueElementsConstraint<P, T, F>
Source§fn clone(&self) -> UniqueElementsConstraint<P, T, F>
fn clone(&self) -> UniqueElementsConstraint<P, T, F>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<P, T, F> Constraint<P> for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Constraint<P> for UniqueElementsConstraint<P, T, F>
Source§fn check(&self, phenotype: &P) -> Vec<ConstraintViolation>
fn check(&self, phenotype: &P) -> Vec<ConstraintViolation>
Checks if the phenotype satisfies this constraint. Read more
Source§fn repair_with_rng(
&self,
phenotype: &mut P,
rng: &mut RandomNumberGenerator,
) -> bool
fn repair_with_rng( &self, phenotype: &mut P, rng: &mut RandomNumberGenerator, ) -> bool
Attempts to repair the phenotype using a random number generator. Read more
Source§fn repair(&self, _phenotype: &mut P) -> bool
fn repair(&self, _phenotype: &mut P) -> bool
Attempts to repair the phenotype to satisfy this constraint. Read more
Source§fn penalty_score(&self, violations: &[ConstraintViolation]) -> f64
fn penalty_score(&self, violations: &[ConstraintViolation]) -> f64
Returns a penalty score for the given constraint violations. Read more
Source§impl<P, T, F> Debug for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Debug for UniqueElementsConstraint<P, T, F>
Auto Trait Implementations§
impl<P, T, F> Freeze for UniqueElementsConstraint<P, T, F>where
F: Freeze,
impl<P, T, F> RefUnwindSafe for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Send for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Sync for UniqueElementsConstraint<P, T, F>
impl<P, T, F> Unpin for UniqueElementsConstraint<P, T, F>
impl<P, T, F> UnwindSafe for UniqueElementsConstraint<P, T, F>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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