pub struct GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>where
Sc: Score,{ /* private fields */ }Expand description
Zero-erasure builder for finalizing a grouped constraint.
Implementations§
Source§impl<S, A, K, E, KF, C, W, Sc> GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>where
S: Send + Sync + 'static,
A: Clone + Send + Sync + 'static,
K: Clone + Eq + Hash + Send + Sync + 'static,
E: Fn(&S) -> &[A] + Send + Sync,
KF: Fn(&A) -> K + Send + Sync,
C: UniCollector<A> + Send + Sync + 'static,
C::Accumulator: Send + Sync,
C::Result: Clone + Send + Sync,
W: Fn(&C::Result) -> Sc + Send + Sync,
Sc: Score + 'static,
impl<S, A, K, E, KF, C, W, Sc> GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>where
S: Send + Sync + 'static,
A: Clone + Send + Sync + 'static,
K: Clone + Eq + Hash + Send + Sync + 'static,
E: Fn(&S) -> &[A] + Send + Sync,
KF: Fn(&A) -> K + Send + Sync,
C: UniCollector<A> + Send + Sync + 'static,
C::Accumulator: Send + Sync,
C::Result: Clone + Send + Sync,
W: Fn(&C::Result) -> Sc + Send + Sync,
Sc: Score + 'static,
Sourcepub fn as_constraint(
self,
name: &str,
) -> GroupedUniConstraint<S, A, K, E, KF, C, W, Sc>
pub fn as_constraint( self, name: &str, ) -> GroupedUniConstraint<S, A, K, E, KF, C, W, Sc>
Finalizes the builder into a zero-erasure GroupedUniConstraint.
§Example
use solverforge_scoring::stream::ConstraintFactory;
use solverforge_scoring::stream::collector::count;
use solverforge_scoring::api::constraint_set::IncrementalConstraint;
use solverforge_core::score::SimpleScore;
#[derive(Clone, Hash, PartialEq, Eq)]
struct Item { category: u32 }
#[derive(Clone)]
struct Solution { items: Vec<Item> }
let constraint = ConstraintFactory::<Solution, SimpleScore>::new()
.for_each(|s: &Solution| &s.items)
.group_by(|i: &Item| i.category, count())
.penalize_with(|n: &usize| SimpleScore::of(*n as i64))
.as_constraint("Category penalty");
assert_eq!(constraint.name(), "Category penalty");Trait Implementations§
Auto Trait Implementations§
impl<S, A, K, E, KF, C, W, Sc> Freeze for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>
impl<S, A, K, E, KF, C, W, Sc> RefUnwindSafe for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>where
E: RefUnwindSafe,
KF: RefUnwindSafe,
C: RefUnwindSafe,
W: RefUnwindSafe,
S: RefUnwindSafe,
A: RefUnwindSafe,
K: RefUnwindSafe,
Sc: RefUnwindSafe,
impl<S, A, K, E, KF, C, W, Sc> Send for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>
impl<S, A, K, E, KF, C, W, Sc> Sync for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>
impl<S, A, K, E, KF, C, W, Sc> Unpin for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>
impl<S, A, K, E, KF, C, W, Sc> UnwindSafe for GroupedConstraintBuilder<S, A, K, E, KF, C, W, Sc>where
E: UnwindSafe,
KF: UnwindSafe,
C: UnwindSafe,
W: UnwindSafe,
S: UnwindSafe,
A: UnwindSafe,
K: UnwindSafe,
Sc: UnwindSafe,
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