Skip to main content

AllDifferent

Struct AllDifferent 

Source
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

Source

pub fn new(vars: impl IntoIterator<Item = Var>) -> Self

All-different over vars.

§Panics

Panics if a variable appears twice.

Trait Implementations§

Source§

impl Clone for AllDifferent

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AllDifferent

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for AllDifferent

Source§

impl PartialEq for AllDifferent

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<D: Domain> Propagator<D> for AllDifferent

Source§

type Scratch = MatchingScratch

Working memory reused across calls; () for none. See the trait docs.
Source§

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>

Removes the values the constraint rules out, using scratch as working memory. Read more
Source§

impl StructuralPartialEq for AllDifferent

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.