BiConstraintStream

Struct BiConstraintStream 

Source
pub struct BiConstraintStream<S, A, K, E, KE, F, Sc>
where Sc: Score,
{ /* private fields */ }

Implementations§

Source§

impl<S, A, K, E, KE, Sc> BiConstraintStream<S, A, K, E, KE, TrueFilter, Sc>
where S: Send + Sync + 'static, A: Clone + Hash + PartialEq + Send + Sync + 'static, K: Eq + Hash + Clone + Send + Sync, E: Fn(&S) -> &[A] + Send + Sync, KE: Fn(&A) -> K + Send + Sync, Sc: Score + 'static,

Source

pub fn new_self_join(extractor: E, key_extractor: KE) -> Self

Source§

impl<S, A, K, E, KE, F, Sc> BiConstraintStream<S, A, K, E, KE, F, Sc>
where S: Send + Sync + 'static, A: Clone + Hash + PartialEq + Send + Sync + 'static, K: Eq + Hash + Clone + Send + Sync, E: Fn(&S) -> &[A] + Send + Sync, KE: Fn(&A) -> K + Send + Sync, F: BiFilter<A, A>, Sc: Score + 'static,

Source

pub fn new_self_join_with_filter( extractor: E, key_extractor: KE, filter: F, ) -> Self

Source

pub fn filter<P>( self, predicate: P, ) -> BiConstraintStream<S, A, K, E, KE, AndBiFilter<F, FnBiFilter<P>>, Sc>
where P: Fn(&A, &A) -> bool + Send + Sync,

Source

pub fn penalize( self, weight: Sc, ) -> BiConstraintBuilder<S, A, K, E, KE, F, impl Fn(&A, &A) -> Sc + Send + Sync, Sc>
where Sc: Clone,

Source

pub fn penalize_with<W>( self, weight_fn: W, ) -> BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>
where W: Fn(&A, &A) -> Sc + Send + Sync,

Source

pub fn penalize_hard_with<W>( self, weight_fn: W, ) -> BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>
where W: Fn(&A, &A) -> Sc + Send + Sync,

Source

pub fn reward( self, weight: Sc, ) -> BiConstraintBuilder<S, A, K, E, KE, F, impl Fn(&A, &A) -> Sc + Send + Sync, Sc>
where Sc: Clone,

Source

pub fn reward_with<W>( self, weight_fn: W, ) -> BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>
where W: Fn(&A, &A) -> Sc + Send + Sync,

Source

pub fn reward_hard_with<W>( self, weight_fn: W, ) -> BiConstraintBuilder<S, A, K, E, KE, F, W, Sc>
where W: Fn(&A, &A) -> Sc + Send + Sync,

Source§

impl<S, A, K, E, KE, F, Sc> BiConstraintStream<S, A, K, E, KE, F, Sc>
where S: Send + Sync + 'static, A: Clone + Hash + PartialEq + Send + Sync + 'static, K: Eq + Hash + Clone + Send + Sync, E: Fn(&S) -> &[A] + Send + Sync, KE: Fn(&A) -> K + Send + Sync, F: BiFilter<A, A>, Sc: Score + 'static,

Source

pub fn join_self<J>( self, joiner: J, ) -> TriConstraintStream<S, A, K, E, KE, impl TriFilter<A, A, A>, Sc>
where J: Joiner<A, A> + 'static, F: 'static,

Joins this stream with a third element to create triples.

§Example
use solverforge_scoring::stream::ConstraintFactory;
use solverforge_scoring::stream::joiner::equal;
use solverforge_scoring::api::constraint_set::IncrementalConstraint;
use solverforge_core::score::SimpleScore;

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
struct Task { team: u32 }

#[derive(Clone)]
struct Solution { tasks: Vec<Task> }

// Penalize when three tasks are on the same team
let constraint = ConstraintFactory::<Solution, SimpleScore>::new()
    .for_each(|s: &Solution| s.tasks.as_slice())
    .join_self(equal(|t: &Task| t.team))
    .join_self(equal(|t: &Task| t.team))
    .penalize(SimpleScore::of(1))
    .as_constraint("Team clustering");

let solution = Solution {
    tasks: vec![
        Task { team: 1 },
        Task { team: 1 },
        Task { team: 1 },
        Task { team: 2 },
    ],
};

// One triple on team 1: (0, 1, 2) = -1 penalty
assert_eq!(constraint.evaluate(&solution), SimpleScore::of(-1));

Trait Implementations§

Source§

impl<S, A, K, E, KE, F, Sc: Score> Debug for BiConstraintStream<S, A, K, E, KE, F, Sc>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, A, K, E, KE, F, Sc> Freeze for BiConstraintStream<S, A, K, E, KE, F, Sc>
where E: Freeze, KE: Freeze, F: Freeze,

§

impl<S, A, K, E, KE, F, Sc> RefUnwindSafe for BiConstraintStream<S, A, K, E, KE, F, Sc>

§

impl<S, A, K, E, KE, F, Sc> Send for BiConstraintStream<S, A, K, E, KE, F, Sc>
where E: Send, KE: Send, F: Send, S: Send, A: Send, K: Send,

§

impl<S, A, K, E, KE, F, Sc> Sync for BiConstraintStream<S, A, K, E, KE, F, Sc>
where E: Sync, KE: Sync, F: Sync, S: Sync, A: Sync, K: Sync,

§

impl<S, A, K, E, KE, F, Sc> Unpin for BiConstraintStream<S, A, K, E, KE, F, Sc>
where E: Unpin, KE: Unpin, F: Unpin, S: Unpin, A: Unpin, K: Unpin, Sc: Unpin,

§

impl<S, A, K, E, KE, F, Sc> UnwindSafe for BiConstraintStream<S, A, K, E, KE, F, Sc>

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> 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, 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.