Skip to main content

solverforge_scoring/stream/
unassigned.rs

1use solverforge_core::score::Score;
2
3use super::collection_extract::CollectionExtract;
4use super::filter::{AndUniFilter, FnUniFilter, UniFilter};
5use super::UniConstraintStream;
6
7#[doc(hidden)]
8pub trait UnassignedEntity<S>: Clone + Send + Sync + 'static {
9    fn is_unassigned(solution: &S, entity: &Self) -> bool;
10}
11
12impl<S, A, E, F, Sc> UniConstraintStream<S, A, E, F, Sc>
13where
14    S: Send + Sync + 'static,
15    A: UnassignedEntity<S>,
16    E: CollectionExtract<S, Item = A>,
17    F: UniFilter<S, A>,
18    Sc: Score + 'static,
19{
20    /// Keeps only entities whose planning variable is unassigned, as reported by
21    /// the macro-generated `UnassignedEntity` impl.
22    pub fn unassigned(
23        self,
24    ) -> UniConstraintStream<S, A, E, AndUniFilter<F, FnUniFilter<fn(&S, &A) -> bool>>, Sc> {
25        let (extractor, filter) = self.into_parts();
26        UniConstraintStream::from_parts(
27            extractor,
28            AndUniFilter::new(
29                filter,
30                FnUniFilter::new(A::is_unassigned as fn(&S, &A) -> bool),
31            ),
32        )
33    }
34}