Skip to content

Commit dc1c663

Browse files
feat: debug clone does not synchronise at level 0 + random splitter edge cases (#146)
This PR addresses 2 issues: - Debug clone was backtracking to level 0 which could throw an exception for `TrailedAssignments` - The `RandomSplitter` had edge cases related to bounds
1 parent 31fef92 commit dc1c663

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pumpkin-solver/src/branching/value_selection/random_splitter.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ impl ValueSelector<DomainId> for RandomSplitter {
2121
context.lower_bound(decision_variable)..context.upper_bound(decision_variable) + 1;
2222
let bound = context.random().generate_i32_in_range(range);
2323

24+
// We need to handle two special cases:
25+
//
26+
// 1. If the bound is equal to the lower-bound then we need to assign it to this bound since
27+
// [x >= lb] is currently true
28+
// 2. If the bound is equal to the upper-bound then we need to assign it to this bound since
29+
// [x <= ub] is currentl true
30+
if bound == context.lower_bound(decision_variable) {
31+
return predicate!(decision_variable <= bound);
32+
} else if bound == context.upper_bound(decision_variable) {
33+
return predicate!(decision_variable >= bound);
34+
}
35+
2436
// Then randomly determine how to split the domain
2537
if context.random().generate_bool(0.5) {
2638
predicate!(decision_variable >= bound)

pumpkin-solver/src/engine/cp/trailed/trailed_assignments.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ impl TrailedAssignments {
7373
pub(crate) fn debug_create_empty_clone(&self) -> Self {
7474
let mut new_trail = self.trail.clone();
7575
let mut new_values = self.values.clone();
76-
new_trail
77-
.synchronise(0)
78-
.for_each(|state_change| new_values[state_change.reference] = state_change.old_value);
76+
if new_trail.get_decision_level() > 0 {
77+
new_trail.synchronise(0).for_each(|state_change| {
78+
new_values[state_change.reference] = state_change.old_value
79+
});
80+
}
7981
Self {
8082
trail: new_trail,
8183
values: new_values,

0 commit comments

Comments
 (0)