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>
impl<N: Value, C: Value> Problem<N, C>
Sourcepub fn subsets(&self) -> &IndexMap<N, Vec<C>>
pub fn subsets(&self) -> &IndexMap<N, Vec<C>>
Returns a reference to the subsets of the problem.
Sourcepub fn constraints(&self) -> &IndexSet<C>
pub fn constraints(&self) -> &IndexSet<C>
Returns a reference to the constraints of the problem.
Sourcepub fn add_subset(&mut self, name: N, subset: Vec<C>)
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?
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}Sourcepub fn add_constraint(&mut self, constraint: C)
pub fn add_constraint(&mut self, constraint: C)
Adds a constraint (set element) to the problem.
Sourcepub fn add_constraints<I: IntoIterator<Item = C>>(&mut self, constraints: I)
pub fn add_constraints<I: IntoIterator<Item = C>>(&mut self, constraints: I)
Adds several constraints to the problem.
Examples found in repository?
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}