Problem

Struct Problem 

Source
pub struct Problem<N: Value, C: Value> { /* private fields */ }
Expand description

An exact cover problem instance.

The subsets are identified with a name with a type N. The elements of the set are called constraints and have a type C.

§Order

The order of subsets and constraints is determined by the insertion order. It uses IndexMap and IndexSet internally to keep track of the order.

The subset order can affect the order of the solutions and the algorithm performance, but it would not be a significant effect as our algorithm uses the MRV heuristic.

Implementations§

Source§

impl<N: Value, C: Value> Problem<N, C>

Source

pub fn subsets(&self) -> &IndexMap<N, Vec<C>>

Returns a reference to the subsets of the problem.

Source

pub fn constraints(&self) -> &IndexSet<C>

Returns a reference to the constraints of the problem.

Source

pub fn add_subset(&mut self, name: N, subset: Vec<C>)

Adds a subset to the problem.

If the subset name already exists, it updates the subset of that name with the given new subset.

Examples found in repository?
examples/simple.rs (line 6)
3fn main() {
4    let mut prob = Problem::default();
5    prob.add_constraints(1..=3);
6    prob.add_subset("A", vec![1, 2, 3]);
7    prob.add_subset("B", vec![1]);
8    prob.add_subset("C", vec![2]);
9    prob.add_subset("D", vec![3]);
10    prob.add_subset("E", vec![1, 2]);
11    prob.add_subset("F", vec![2, 3]);
12
13    let mut solver = Solver::new(prob);
14    let mut solutions = vec![];
15    solver.run();
16
17    for event in solver {
18        if let SolverEvent::SolutionFound(sol) = event {
19            solutions.push(sol);
20        }
21    }
22
23    println!("{:?}", solutions);
24}
Source

pub fn add_constraint(&mut self, constraint: C)

Adds a constraint (set element) to the problem.

Source

pub fn add_constraints<I: IntoIterator<Item = C>>(&mut self, constraints: I)

Adds several constraints to the problem.

Examples found in repository?
examples/simple.rs (line 5)
3fn main() {
4    let mut prob = Problem::default();
5    prob.add_constraints(1..=3);
6    prob.add_subset("A", vec![1, 2, 3]);
7    prob.add_subset("B", vec![1]);
8    prob.add_subset("C", vec![2]);
9    prob.add_subset("D", vec![3]);
10    prob.add_subset("E", vec![1, 2]);
11    prob.add_subset("F", vec![2, 3]);
12
13    let mut solver = Solver::new(prob);
14    let mut solutions = vec![];
15    solver.run();
16
17    for event in solver {
18        if let SolverEvent::SolutionFound(sol) = event {
19            solutions.push(sol);
20        }
21    }
22
23    println!("{:?}", solutions);
24}

Trait Implementations§

Source§

impl<N: Clone + Value, C: Clone + Value> Clone for Problem<N, C>

Source§

fn clone(&self) -> Problem<N, C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<N: Value, C: Value> Default for Problem<N, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<N, C> Freeze for Problem<N, C>

§

impl<N, C> RefUnwindSafe for Problem<N, C>

§

impl<N, C> Send for Problem<N, C>
where N: Send, C: Send,

§

impl<N, C> Sync for Problem<N, C>
where N: Sync, C: Sync,

§

impl<N, C> Unpin for Problem<N, C>
where N: Unpin, C: Unpin,

§

impl<N, C> UnwindSafe for Problem<N, C>
where N: UnwindSafe, C: UnwindSafe,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.