1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! The choices that steer MDD compilation: the order of the layers, which node to split, and how
//! to merge nodes.
//!
//! # Purpose
//!
//! Compiling a relaxed MDD involves three decisions that change its shape, and so its quality, but
//! never its soundness (every solution stays a path):
//!
//! - [`OrderingHeuristic`] chooses the variable branched on at each layer.
//! - [`SelectHeuristic`] chooses, during refinement, the node to split next.
//! - [`MergeHeuristic`] chooses which nodes are merged when a layer is wider than allowed.
//!
//! [`CompilationHeuristic`] groups the three, and is what `Compiler::new` takes.
//!
//! # Design notes
//!
//! - **Heuristics never see constraint semantics.** An order is repaired afterwards so that
//! order-sensitive constraints such as `Regular` are satisfied; see `Compiler::new`.
//!
//! # Example
//!
//! ```
//! use aicad::constraints::all_different;
//! use aicad::mdd::Compiler;
//! use aicad::mdd::heuristics::{
//! CompilationHeuristic, MergeHeuristic, OrderingHeuristic, SelectHeuristic,
//! };
//! use aicad::modelling::Problem;
//! use std::sync::Arc;
//!
//! let mut problem = Problem::default();
//! let vars = problem.add_variables(4, vec![0, 1, 2, 3]);
//! let constraint = all_different(&mut problem, vars.clone());
//!
//! // Branch on the variables in reverse, and keep at most two nodes per layer.
//! let mut compiler = Compiler::new(
//! Arc::new(problem),
//! CompilationHeuristic {
//! ordering: OrderingHeuristic::Custom(vec![3, 2, 1, 0]),
//! merge: MergeHeuristic::LessRelaxed,
//! selection: SelectHeuristic::Greedy,
//! },
//! &[constraint],
//! );
//! compiler.refine(2);
//! let mdd = compiler.into_mdd();
//!
//! assert_eq!(mdd.decision_at_layer(0), vars[3]);
//! assert!((0..4).all(|layer| mdd.number_nodes_in_layer(layer) <= 2));
//! ```
pub use MergeHeuristic;
pub use OrderingHeuristic;
pub use SelectHeuristic;
/// The three choices that steer the compilation of one MDD. See the [module documentation](self).