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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! # aicad
//!
//! MDD compilation for constraint satisfaction problems, with strategies built on top of it:
//! belief propagation, local search, and local search guided by a trained neural network.
//!
//! Everything the Python package `pyaicad` does is available here too, for applications that
//! cannot afford the interpreter. The Rust API is **experimental** and may change between minor
//! versions until its users have shaped it.
//!
//! # Modules
//!
//! From the bottom up, each module only depends on the ones listed before it:
//!
//! - [`modelling`]: variables, the [`Problem`](modelling::Problem), and the traits that a
//! constraint implements.
//! - [`constraints`]: the constraints, with the contract that the compiler relies on.
//! - [`mdd`]: the compiler and the compiled diagram.
//! - [`sampling`]: sampling solutions from a compiled diagram.
//! - [`bp`]: belief propagation over the diagrams of the constraints.
//! - [`destroy`]: the operators that choose which variables a local search frees.
//! - [`local_search`]: the local search engine, its architectures and [`local_search::solve`].
//! - [`diagnostics`]: an optional log of structured events for offline analysis.
//!
//! # Features
//!
//! - `learning` (off by default): the neural networks (`neural`), their training (`learning`)
//! and the local searches that use them. It pulls in [burn](https://burn.dev), which is heavy to
//! build; the compiler, sampling, belief propagation and the belief-propagation local search do
//! not need it.
//! - `python` (off by default): the bindings built by maturin into `pyaicad`, and never needed from
//! Rust. Combined with `learning` they give the full wheel; alone, the slim one.
//!
//! # Settings
//!
//! A few settings are global: the number of threads of the worker pool that runs the parallel parts
//! of the library ([`set_num_threads`], [`num_threads`]), a quarter of the available threads
//! unless set, and the seed of the randomness ([`set_seed`]).
//!
//! # Example
//!
//! ```
//! use aicad::constraints::all_different;
//! use aicad::mdd::Compiler;
//! use aicad::mdd::heuristics::CompilationHeuristic;
//! use aicad::modelling::Problem;
//! use std::sync::Arc;
//!
//! let mut problem = Problem::default();
//! let vars = problem.add_variables(3, vec![0, 1, 2]);
//! let constraint = all_different(&mut problem, vars);
//!
//! let mut compiler = Compiler::new(
//! Arc::new(problem),
//! CompilationHeuristic::default(),
//! &[constraint],
//! );
//! compiler.refine(usize::MAX);
//! assert_eq!(compiler.into_mdd().count_solutions().to_string(), "6");
//! ```
pub use ;
/// Seeds every source of randomness of the crate, so that a later run of a compilation, a
/// training or a search reproduces itself given the same seed: the process-wide generator (the
/// sampling of diagrams, the destroy operators, the train and validation split, the masking of
/// training samples) and, with the `learning` feature, the generators of the burn backends (the
/// initial weights, the sampling of logits).
///
/// Compilation uses no randomness and local search is reproducible given its own seed; whether
/// a seeded training run reproduces itself bit for bit is not guaranteed.