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
pub mod space;
pub mod recomputation;
pub mod branching;
pub mod search_tree_visitor;
pub mod propagation;
pub mod engine;
pub mod monitor;
pub mod statistics;
pub mod branch_and_bound;
pub mod debugger;
pub mod stop_node;
pub use search::space::*;
pub use search::search_tree_visitor::*;
use propagation::CStoreFD;
use variable::VStoreSet;
use search::engine::one_solution::*;
use search::branching::*;
use search::propagation::*;
use gcollections::VectorStack;
pub type VStore = VStoreSet;
type CStore = CStoreFD<VStore>;
pub type FDSpace = Space<VStore, CStore, NoRecomputation<VStore, CStore>>;
pub fn one_solution_engine() -> Box<dyn SearchTreeVisitor<FDSpace>> {
let search =
OneSolution::<_, VectorStack<_>, FDSpace>::new(
Propagation::new(
Brancher::new(FirstSmallestVar, MiddleVal, BinarySplit)));
Box::new(search)
}
#[cfg(test)]
mod test {
pub use super::*;
use propagators::cmp::*;
use propagators::distinct::*;
use term::*;
use gcollections::ops::*;
use interval::interval_set::*;
use concept::*;
pub fn nqueens(n: usize, space: &mut FDSpace) {
let mut queens: Vec<Var<VStore>> = vec![];
for _ in 0..n {
queens.push(Box::new(space.vstore.alloc((1, n as i32).to_interval_set())));
}
for i in 0..n-1 {
for j in i + 1..n {
let q1 = (i + 1) as i32;
let q2 = (j + 1) as i32;
space.cstore.alloc(Box::new(XNeqY::new(queens[i].bclone(), Box::new(Addition::new(queens[j].bclone(), q2 - q1)))));
space.cstore.alloc(Box::new(XNeqY::new(queens[i].bclone(), Box::new(Addition::new(queens[j].bclone(), -q2 + q1)))));
}
}
space.cstore.alloc(Box::new(Distinct::new(queens)));
}
}