pub struct AllDifferent { /* private fields */ }Expand description
The variables take pairwise distinct values.
Propagation is complete (generalised arc consistency, Régin 1994): afterwards every value
left in a domain is part of some assignment of distinct values. This subsumes all Hall-set
reasoning: a fixed value leaves the other domains, k variables sharing k values keep
those values to themselves, and a value that only one variable can still take goes to it
when the values must all be used. It fails as soon as fewer values than variables remain.
Each run builds a matching between variables and values, in O(n · e) for n variables
and e variable–value pairs. Its buffers live in MatchingScratch and are reused.
§Examples
use constraint_search::{AllDifferent, Domains, MatchingScratch, Propagator};
let mut domains = Domains::<u16>::new();
let x = domains.add(0b011);
let y = domains.add(0b011);
let z = domains.add(0b111);
// x and y use up the values 0 and 1, so z must be 2.
AllDifferent::new([x, y, z]).propagate(&mut domains, &mut MatchingScratch::default())?;
assert_eq!(domains.value(z), Some(2));Implementations§
Source§impl AllDifferent
impl AllDifferent
Sourcepub fn new(vars: impl IntoIterator<Item = Var>) -> Self
pub fn new(vars: impl IntoIterator<Item = Var>) -> Self
Trait Implementations§
Source§impl Clone for AllDifferent
impl Clone for AllDifferent
Source§impl Debug for AllDifferent
impl Debug for AllDifferent
impl Eq for AllDifferent
Source§impl PartialEq for AllDifferent
impl PartialEq for AllDifferent
Source§impl<D: Domain> Propagator<D> for AllDifferent
impl<D: Domain> Propagator<D> for AllDifferent
Source§type Scratch = MatchingScratch
type Scratch = MatchingScratch
Working memory reused across calls;
() for none. See the trait docs.Source§fn scope(&self) -> &[Var]
fn scope(&self) -> &[Var]
The variables the constraint is over. A change to any of them wakes the propagator.
Source§fn propagate(
&self,
domains: &mut Domains<D>,
graph: &mut MatchingScratch,
) -> Result<(), Inconsistent>
fn propagate( &self, domains: &mut Domains<D>, graph: &mut MatchingScratch, ) -> Result<(), Inconsistent>
Removes the values the constraint rules out, using
scratch as working memory. Read moreimpl StructuralPartialEq for AllDifferent
Auto Trait Implementations§
impl Forget for AllDifferent
impl Freeze for AllDifferent
impl Move for AllDifferent
impl RefUnwindSafe for AllDifferent
impl Send for AllDifferent
impl Sync for AllDifferent
impl Unpin for AllDifferent
impl UnsafeUnpin for AllDifferent
impl UnwindSafe for AllDifferent
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