diff --git a/README.md b/README.md index 9b713049..9acc0d37 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ fn main() { let width = FixedWidth(100); // here we mean max 100 nodes per layer // 5. Add a dominance relation checker - let dominance = SimpleDominanceChecker::new(KPDominance); + let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); // 6. Decide of a cutoff heuristic (if you don't want to let the solver run for ever) let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) diff --git a/ddo/examples/alp/main.rs b/ddo/examples/alp/main.rs index ac545d48..0667d429 100644 --- a/ddo/examples/alp/main.rs +++ b/ddo/examples/alp/main.rs @@ -82,7 +82,7 @@ fn main() { let ranking = AlpRanking; let width = max_width(&problem, args.width); - let dominance = SimpleDominanceChecker::new(AlpDominance); + let dominance = SimpleDominanceChecker::new(AlpDominance, problem.nb_variables()); let cutoff = cutoff(args.duration); let mut fringe = NoDupFringe::new(MaxUB::new(&ranking)); diff --git a/ddo/examples/alp/tests.rs b/ddo/examples/alp/tests.rs index da67b346..8495950c 100644 --- a/ddo/examples/alp/tests.rs +++ b/ddo/examples/alp/tests.rs @@ -41,7 +41,7 @@ pub fn solve_id(id: &str) -> isize { let ranking = AlpRanking; let width = NbUnassignedWidth(problem.nb_variables()); - let dominance = SimpleDominanceChecker::new(AlpDominance); + let dominance = SimpleDominanceChecker::new(AlpDominance, problem.nb_variables()); let cutoff = NoCutoff; let mut fringe = NoDupFringe::new(MaxUB::new(&ranking)); diff --git a/ddo/examples/knapsack/main.rs b/ddo/examples/knapsack/main.rs index 60a6ccfb..804b4968 100644 --- a/ddo/examples/knapsack/main.rs +++ b/ddo/examples/knapsack/main.rs @@ -317,7 +317,7 @@ fn main() { let relaxation= KPRelax{pb: &problem}; let heuristic= KPRanking; let width = max_width(problem.nb_variables(), args.width); - let dominance = SimpleDominanceChecker::new(KPDominance); + let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); let cutoff = TimeBudget::new(Duration::from_secs(15));//NoCutoff; let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); diff --git a/ddo/examples/knapsack/tests.rs b/ddo/examples/knapsack/tests.rs index 22fb4e86..ccc83d38 100644 --- a/ddo/examples/knapsack/tests.rs +++ b/ddo/examples/knapsack/tests.rs @@ -42,7 +42,7 @@ pub fn solve_id(id: &str) -> isize { let ranking = KPRanking; let width = NbUnassignedWidth(problem.nb_variables()); - let dominance = SimpleDominanceChecker::new(KPDominance); + let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); let cutoff = NoCutoff; let mut fringe = NoDupFringe::new(MaxUB::new(&ranking)); diff --git a/ddo/examples/lcs/main.rs b/ddo/examples/lcs/main.rs index f9b79ec7..adbc3a95 100644 --- a/ddo/examples/lcs/main.rs +++ b/ddo/examples/lcs/main.rs @@ -83,7 +83,7 @@ fn main() { let ranking = LcsRanking; let width = max_width(&problem, args.width); - let dominance = SimpleDominanceChecker::new(LcsDominance); + let dominance = SimpleDominanceChecker::new(LcsDominance, problem.nb_variables()); let cutoff = cutoff(args.duration); let mut fringe = NoDupFringe::new(MaxUB::new(&ranking)); diff --git a/ddo/examples/lcs/tests.rs b/ddo/examples/lcs/tests.rs index d146456f..bb9a486f 100644 --- a/ddo/examples/lcs/tests.rs +++ b/ddo/examples/lcs/tests.rs @@ -42,7 +42,7 @@ pub fn solve_id(id: &str) -> isize { let ranking = LcsRanking; let width = FixedWidth(100); - let dominance = SimpleDominanceChecker::new(LcsDominance); + let dominance = SimpleDominanceChecker::new(LcsDominance, problem.nb_variables()); let cutoff = NoCutoff; let mut fringe = NoDupFringe::new(MaxUB::new(&ranking)); diff --git a/ddo/examples/tsptw/main.rs b/ddo/examples/tsptw/main.rs index 89d49950..fd04be1e 100644 --- a/ddo/examples/tsptw/main.rs +++ b/ddo/examples/tsptw/main.rs @@ -73,7 +73,7 @@ fn main() { let pb = Tsptw::new(inst); let relax = TsptwRelax::new(&pb); let width = TsptwWidth::new(pb.nb_variables(), args.width.unwrap_or(1)); - let dominance = SimpleDominanceChecker::new(TsptwDominance); + let dominance = SimpleDominanceChecker::new(TsptwDominance, pb.nb_variables()); let cutoff = TimeBudget::new(Duration::from_secs(args.duration.unwrap_or(u64::MAX))); let mut fringe = NoDupFringe::new(MaxUB::new(&TsptwRanking)); let mut solver = DefaultCachingSolver::custom( diff --git a/ddo/examples/tsptw/tests.rs b/ddo/examples/tsptw/tests.rs index 1e104eae..5cc6db5e 100644 --- a/ddo/examples/tsptw/tests.rs +++ b/ddo/examples/tsptw/tests.rs @@ -37,7 +37,7 @@ pub fn solve(instance: &str, width: Option, threads: Option) -> f3 let mut fringe = NoDupFringe::new(MaxUB::new(&TsptwRanking)); let relax = TsptwRelax::new(&pb); let width = TsptwWidth::new(pb.nb_variables(), width.unwrap_or(1)); - let dominance = SimpleDominanceChecker::new(TsptwDominance); + let dominance = SimpleDominanceChecker::new(TsptwDominance, pb.nb_variables()); let cutoff = NoCutoff; let mut solver = DefaultCachingSolver::custom( &pb, diff --git a/ddo/src/abstraction/dominance.rs b/ddo/src/abstraction/dominance.rs index 89778219..fd50a959 100644 --- a/ddo/src/abstraction/dominance.rs +++ b/ddo/src/abstraction/dominance.rs @@ -113,9 +113,12 @@ pub struct DominanceCheckResult { pub trait DominanceChecker { type State; + /// Removes all entries associated with states at the given depth. + fn clear_layer(&self, depth: usize); + /// Returns true if the state is dominated by a stored one, and a potential /// pruning threshold, and inserts the (key, value) pair otherwise - fn is_dominated_or_insert(&self, state: Arc, value: isize) -> DominanceCheckResult; + fn is_dominated_or_insert(&self, state: Arc, depth: usize, value: isize) -> DominanceCheckResult; /// Comparator to order states by increasing value, regardless of their key fn cmp(&self, a: &Self::State, val_a: isize, b: &Self::State, val_b: isize) -> Ordering; diff --git a/ddo/src/implementation/dominance/empty.rs b/ddo/src/implementation/dominance/empty.rs index 73944320..998f811d 100644 --- a/ddo/src/implementation/dominance/empty.rs +++ b/ddo/src/implementation/dominance/empty.rs @@ -35,7 +35,9 @@ impl Default for EmptyDominanceChecker { impl DominanceChecker for EmptyDominanceChecker { type State = T; - fn is_dominated_or_insert(&self, _: Arc, _: isize) -> DominanceCheckResult { + fn clear_layer(&self, _: usize) {} + + fn is_dominated_or_insert(&self, _: Arc, _: usize, _: isize) -> DominanceCheckResult { DominanceCheckResult { dominated: false, threshold: None } } diff --git a/ddo/src/implementation/dominance/simple.rs b/ddo/src/implementation/dominance/simple.rs index 85bf1734..b9a732a9 100644 --- a/ddo/src/implementation/dominance/simple.rs +++ b/ddo/src/implementation/dominance/simple.rs @@ -31,6 +31,8 @@ struct DominanceEntry { value: isize, } +type DominanceMap = DashMap>, fxhash::FxBuildHasher>; + #[derive(Debug)] pub struct SimpleDominanceChecker where @@ -38,7 +40,7 @@ where D::Key: Eq + PartialEq + Hash, { dominance: D, - data: DashMap>, fxhash::FxBuildHasher>, + data: Vec>, } impl SimpleDominanceChecker @@ -46,8 +48,12 @@ where D: Dominance, D::Key: Eq + PartialEq + Hash, { - pub fn new(dominance: D) -> Self { - Self { dominance, data: Default::default() } + pub fn new(dominance: D, nb_variables: usize) -> Self { + let mut data = vec![]; + for _ in 0..=nb_variables { + data.push(Default::default()); + } + Self { dominance, data } } } @@ -58,9 +64,13 @@ where { type State = D::State; - fn is_dominated_or_insert(&self, state: Arc, value: isize) -> DominanceCheckResult { + fn clear_layer(&self, depth: usize) { + self.data[depth].clear(); + } + + fn is_dominated_or_insert(&self, state: Arc, depth: usize, value: isize) -> DominanceCheckResult { if let Some(key) = self.dominance.get_key(state.clone()) { - match self.data.entry(key) { + match self.data[depth].entry(key) { Entry::Occupied(mut e) => { let mut dominated = false; let mut threshold = Some(isize::MAX); @@ -113,104 +123,104 @@ mod tests { #[test] fn not_dominated_when_keys_are_different() { - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![3, 0]), 3)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![2, 0]), 2)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![1, 0]), 1)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![3, 0]), 0, 3)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![2, 0]), 0, 2)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![1, 0]), 0, 1)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 0)); } #[test] fn dominated_when_keys_are_equal() { - let dominance = SimpleDominanceChecker::new(DummyDominance); + let dominance = SimpleDominanceChecker::new(DummyDominance, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 3]), 0)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 3]), 0, 0)); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 2]), 2); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 2]), 0, 2); assert!(res.dominated); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 1); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 0, 1); assert!(res.dominated); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 0); assert!(res.dominated); - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 3)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 3)); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 2); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 2); assert!(res.dominated); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 1); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 1); assert!(res.dominated); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 0); assert!(res.dominated); - let res = dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 3); + let res = dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 0, 3); assert!(res.dominated); } #[test] fn not_dominated_when_keys_are_equal() { - let dominance = SimpleDominanceChecker::new(DummyDominance); + let dominance = SimpleDominanceChecker::new(DummyDominance, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 3]), 3)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 3]), 1)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1, 1]), 5)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 4]), 3)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 3]), 0, 3)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 3]), 0, 1)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1, 1]), 0, 5)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0, 4]), 0, 3)); - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 3)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 3]), 0)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 1)); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 5)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 3)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 3]), 0, 0)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 0, 1)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 5)); } #[test] fn pruning_threshold_when_value_is_used() { - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 3)); - assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 2)); - assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 1)); - assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(3) }, dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 0)); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 3)); + assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 2)); + assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 1)); + assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(3) }, dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 0, 0)); } #[test] fn entry_is_added_only_when_dominant() { - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 3)); - assert!(dominance.data.get(&0).is_some()); - assert_eq!(1, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 3)); + assert!(dominance.data[0].get(&0).is_some()); + assert_eq!(1, dominance.data[0].get(&0).unwrap().len()); - assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 1)); - assert_eq!(1, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: true, threshold: Some(2) }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 1)); + assert_eq!(1, dominance.data[0].get(&0).unwrap().len()); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 1)); - assert_eq!(2, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 0, 1)); + assert_eq!(2, dominance.data[0].get(&0).unwrap().len()); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 5)); - assert_eq!(3, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, -1]), 0, 5)); + assert_eq!(3, dominance.data[0].get(&0).unwrap().len()); } #[test] fn entry_is_removed_when_dominated() { - let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue); + let dominance = SimpleDominanceChecker::new(DummyDominanceWithValue, 0); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 3)); - assert!(dominance.data.get(&0).is_some()); - assert_eq!(1, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 0]), 0, 3)); + assert!(dominance.data[0].get(&0).is_some()); + assert_eq!(1, dominance.data[0].get(&0).unwrap().len()); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 5)); - assert_eq!(1, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 1]), 0, 5)); + assert_eq!(1, dominance.data[0].get(&0).unwrap().len()); - assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 2]), 7)); - assert_eq!(1, dominance.data.get(&0).unwrap().len()); + assert_eq!(DominanceCheckResult{ dominated: false, threshold: None }, dominance.is_dominated_or_insert(Arc::new(vec![0, 2]), 0, 7)); + assert_eq!(1, dominance.data[0].get(&0).unwrap().len()); } struct DummyDominance; diff --git a/ddo/src/implementation/heuristics/cutoff.rs b/ddo/src/implementation/heuristics/cutoff.rs index 0cea053d..bebe8470 100644 --- a/ddo/src/implementation/heuristics/cutoff.rs +++ b/ddo/src/implementation/heuristics/cutoff.rs @@ -141,7 +141,7 @@ use crate::Cutoff; /// }; /// let relaxation = KPRelax{pb: &problem}; /// let width = FixedWidth(100); -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// let heuristic = KPRanking; /// let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); /// # @@ -281,7 +281,7 @@ impl Cutoff for NoCutoff { /// }; /// let relaxation = KPRelax{pb: &problem}; /// let width = FixedWidth(100); -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// let heuristic = KPRanking; /// /// // this solver will be allowed to run for 30 seconds diff --git a/ddo/src/implementation/heuristics/width.rs b/ddo/src/implementation/heuristics/width.rs index ece4c08b..4abbc3c2 100644 --- a/ddo/src/implementation/heuristics/width.rs +++ b/ddo/src/implementation/heuristics/width.rs @@ -149,7 +149,7 @@ use crate::{WidthHeuristic, SubProblem}; /// # }; /// # let relaxation = KPRelax{pb: &problem}; /// # let heuristic = KPRanking; -/// # let dominance = SimpleDominanceChecker::new(KPDominance); +/// # let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// # let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) /// # let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); /// # @@ -380,7 +380,7 @@ impl WidthHeuristic for FixedWidth { /// }; /// let relaxation = KPRelax{pb: &problem}; /// let heuristic = KPRanking; -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) /// let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); /// # @@ -619,7 +619,7 @@ impl WidthHeuristic for NbUnassignedWidth { /// }; /// let relaxation = KPRelax{pb: &problem}; /// let heuristic = KPRanking; -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) /// let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); /// # @@ -858,7 +858,7 @@ impl > WidthHeuristic for Times { /// }; /// let relaxation = KPRelax{pb: &problem}; /// let heuristic = KPRanking; -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) /// let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic)); /// # diff --git a/ddo/src/implementation/mdd/clean.rs b/ddo/src/implementation/mdd/clean.rs index 8a5eee6e..9b2fcb0b 100644 --- a/ddo/src/implementation/mdd/clean.rs +++ b/ddo/src/implementation/mdd/clean.rs @@ -688,7 +688,7 @@ where curr_l.retain(|id| { let node = get!(mut node id, self); if node.flags.is_exact() { - let DominanceCheckResult { dominated, threshold } = input.dominance.is_dominated_or_insert(node.state.clone(), node.value_top); + let DominanceCheckResult { dominated, threshold } = input.dominance.is_dominated_or_insert(node.state.clone(), node.depth, node.value_top); if dominated { node.theta = threshold; false diff --git a/ddo/src/implementation/mdd/pooled.rs b/ddo/src/implementation/mdd/pooled.rs index 301c7161..fe0f0224 100644 --- a/ddo/src/implementation/mdd/pooled.rs +++ b/ddo/src/implementation/mdd/pooled.rs @@ -644,7 +644,7 @@ where curr_l.retain(|id| { let node = get!(mut node id, self); if node.flags.is_exact() { - let DominanceCheckResult { dominated, threshold } = input.dominance.is_dominated_or_insert(node.state.clone(), node.value_top); + let DominanceCheckResult { dominated, threshold } = input.dominance.is_dominated_or_insert(node.state.clone(), node.depth, node.value_top); if dominated { node.theta = threshold; // set theta for later propagation false diff --git a/ddo/src/implementation/solver/parallel.rs b/ddo/src/implementation/solver/parallel.rs index 7a516e13..6bca12ad 100644 --- a/ddo/src/implementation/solver/parallel.rs +++ b/ddo/src/implementation/solver/parallel.rs @@ -246,7 +246,7 @@ enum WorkLoad { /// let width = FixedWidth(100); // here we mean max 100 nodes per layer /// /// // 5. Add a dominance relation checker -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// /// // 6. Decide of a cutoff heuristic (if you don't want to let the solver run for ever) /// let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) diff --git a/ddo/src/implementation/solver/sequential.rs b/ddo/src/implementation/solver/sequential.rs index 76fed103..efdc4029 100644 --- a/ddo/src/implementation/solver/sequential.rs +++ b/ddo/src/implementation/solver/sequential.rs @@ -161,7 +161,7 @@ enum WorkLoad { /// let width = FixedWidth(100); // here we mean max 100 nodes per layer /// /// // 5. Add a dominance relation checker -/// let dominance = SimpleDominanceChecker::new(KPDominance); +/// let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); /// /// // 6. Decide of a cutoff heuristic (if you don't want to let the solver run for ever) /// let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) diff --git a/ddo/src/lib.rs b/ddo/src/lib.rs index eb80564e..a851f4a3 100644 --- a/ddo/src/lib.rs +++ b/ddo/src/lib.rs @@ -425,7 +425,7 @@ //! let width = FixedWidth(100); // here we mean max 100 nodes per layer //! //! // 5. Add a dominance relation checker -//! let dominance = SimpleDominanceChecker::new(KPDominance); +//! let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables()); //! //! // 6. Decide of a cutoff heuristic (if you don't want to let the solver run for ever) //! let cutoff = NoCutoff; // might as well be a TimeBudget (or something else) diff --git a/seminar/ddo_seminar.ipynb b/seminar/ddo_seminar.ipynb index 254f3a30..962d1977 100644 --- a/seminar/ddo_seminar.ipynb +++ b/seminar/ddo_seminar.ipynb @@ -646,7 +646,7 @@ " let mut fringe = SimpleFringe::new(MaxUB::new(&heuristic));\n", "\n", " // And then we instanciate the dominance relationship (this is a bit more advanced)\n", - " let dominance = SimpleDominanceChecker::new(KPDominance);\n", + " let dominance = SimpleDominanceChecker::new(KPDominance, problem.nb_variables());\n", "\n", " // Create your solver object\n", " let mut solver = DefaultCachingSolver::new(\n",