pub struct ConstraintFactory<S, Sc: Score> { /* private fields */ }Expand description
Factory for creating constraint streams.
ConstraintFactory is parameterized by the solution type S and score type Sc.
It serves as the entry point for defining constraints using the fluent API.
§Example
use solverforge_core::score::SoftScore;
use solverforge_scoring::api::constraint_set::IncrementalConstraint;
use solverforge_scoring::stream::ConstraintFactory;
#[derive(Clone)]
struct Solution {
values: Vec<Option<i32>>,
}
let factory = ConstraintFactory::<Solution, SoftScore>::new();
let constraint = factory
.for_each(Solution::values())
.filter(|v: &Option<i32>| v.is_none())
.penalize(SoftScore::of(1))
.named("Unassigned");
let solution = Solution {
values: vec![Some(1), None, None],
};
assert_eq!(constraint.evaluate(&solution), SoftScore::of(-2));Implementations§
Source§impl<S, Sc> ConstraintFactory<S, Sc>
impl<S, Sc> ConstraintFactory<S, Sc>
Sourcepub fn for_each<A, E>(
self,
extractor: E,
) -> UniConstraintStream<S, A, E, TrueFilter, Sc>
pub fn for_each<A, E>( self, extractor: E, ) -> UniConstraintStream<S, A, E, TrueFilter, Sc>
Creates a zero-erasure uni-constraint stream over a collection source.
For macro-generated models, pass the inherent solution source method:
ConstraintFactory::new().for_each(Schedule::shifts()).
Low-level callers can still pass any CollectionExtract<S, Item = A>.
The extractor type is preserved as a concrete generic for full zero-erasure.
Trait Implementations§
Source§impl<S, Sc: Score> Clone for ConstraintFactory<S, Sc>
impl<S, Sc: Score> Clone for ConstraintFactory<S, Sc>
Source§impl<S, Sc: Score> Debug for ConstraintFactory<S, Sc>
impl<S, Sc: Score> Debug for ConstraintFactory<S, Sc>
Auto Trait Implementations§
impl<S, Sc> Freeze for ConstraintFactory<S, Sc>
impl<S, Sc> RefUnwindSafe for ConstraintFactory<S, Sc>
impl<S, Sc> Send for ConstraintFactory<S, Sc>
impl<S, Sc> Sync for ConstraintFactory<S, Sc>
impl<S, Sc> Unpin for ConstraintFactory<S, Sc>
impl<S, Sc> UnsafeUnpin for ConstraintFactory<S, Sc>
impl<S, Sc> UnwindSafe for ConstraintFactory<S, Sc>
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