Trait Constraint

Source
pub trait Constraint<P>:
    Debug
    + Send
    + Sync
where P: Phenotype,
{ // Required method fn check(&self, phenotype: &P) -> Vec<ConstraintViolation>; // Provided methods fn repair(&self, _phenotype: &mut P) -> bool { ... } fn repair_with_rng( &self, _phenotype: &mut P, _rng: &mut RandomNumberGenerator, ) -> bool { ... } fn penalty_score(&self, violations: &[ConstraintViolation]) -> f64 { ... } }
Expand description

Trait for defining constraints that can be applied to phenotypes.

Constraints check whether a phenotype satisfies certain requirements and optionally provide mechanisms to repair invalid phenotypes.

Required Methods§

Source

fn check(&self, phenotype: &P) -> Vec<ConstraintViolation>

Checks if the phenotype satisfies this constraint.

Returns a vector of constraint violations. An empty vector indicates that the phenotype satisfies the constraint.

Provided Methods§

Source

fn repair(&self, _phenotype: &mut P) -> bool

Attempts to repair the phenotype to satisfy this constraint.

Returns true if the phenotype was successfully repaired, false otherwise.

The default implementation does not perform any repair.

Source

fn repair_with_rng( &self, _phenotype: &mut P, _rng: &mut RandomNumberGenerator, ) -> bool

Attempts to repair the phenotype using a random number generator.

This method is useful for repair strategies that require randomness.

Returns true if the phenotype was successfully repaired, false otherwise.

The default implementation does not perform any repair.

Source

fn penalty_score(&self, violations: &[ConstraintViolation]) -> f64

Returns a penalty score for the given constraint violations.

This score can be used to adjust the fitness of phenotypes that violate the constraint. Higher values indicate more severe violations.

The default implementation sums the severity of all violations, or counts the number of violations if severity is not specified.

Implementors§

Source§

impl<P, K, V, F> Constraint<P> for CompleteAssignmentConstraint<P, K, V, F>
where P: Phenotype, K: Eq + Hash + Debug + Clone + Send + Sync, V: Debug + Clone + Send + Sync, F: Fn(&P) -> HashMap<K, V> + Send + Sync + Debug,

Source§

impl<P, K, V, F, G> Constraint<P> for CapacityConstraint<P, K, V, F, G>
where P: Phenotype, K: Eq + Hash + Debug + Clone + Send + Sync, V: Eq + Hash + Debug + Clone + Send + Sync, F: Fn(&P) -> HashMap<V, Vec<K>> + Send + Sync + Debug, G: Fn(&V) -> usize + Send + Sync + Debug,

Source§

impl<P, T, F> Constraint<P> for DependencyConstraint<P, T, F>
where P: Phenotype, T: Eq + Hash + Debug + Clone + Send + Sync, F: Fn(&P) -> Vec<T> + Send + Sync + Debug,

Source§

impl<P, T, F> Constraint<P> for UniqueElementsConstraint<P, T, F>
where P: Phenotype, T: Eq + Hash + Debug + Clone + Send + Sync, F: Fn(&P) -> Vec<T> + Send + Sync + Debug,