diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index 4dbde4cc..287d6960 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -38,7 +38,7 @@ pub struct PartialSolution { current_decision_level: DecisionLevel, package_assignments: FnvIndexMap>, prioritized_potential_packages: PriorityQueue>, - just_backtracked: bool, + changed_this_decision_level: usize, } impl Display @@ -138,7 +138,7 @@ impl PartialSolution PartialSolution PartialSolution { + let idx = occupied.index(); let mut pa = occupied.get_mut(); pa.highest_decision_level = self.current_decision_level; match &mut pa.assignments_intersection { @@ -202,11 +208,21 @@ impl PartialSolution { *t = t.intersection(&term); + if t.is_positive() { + // we can use `swap_indices` to make `changed_this_decision_level` only go down by 1 + // but the copying is slower then the larger search + self.changed_this_decision_level = + std::cmp::min(self.changed_this_decision_level, idx); + } } } pa.dated_derivations.push(dated_derivation); } Entry::Vacant(v) => { + if term.is_positive() { + self.changed_this_decision_level = + std::cmp::min(self.changed_this_decision_level, pa_last_index); + } v.insert(PackageAssignments { smallest_decision_level: self.current_decision_level, highest_decision_level: self.current_decision_level, @@ -218,12 +234,12 @@ impl PartialSolution Priority) -> Option

{ - let check_all = self.just_backtracked; - self.just_backtracked = false; + let check_all = self.changed_this_decision_level + == self.current_decision_level.0.saturating_sub(1) as usize; let current_decision_level = self.current_decision_level; let package_assignments = &self.package_assignments; let prioritized_potential_packages = &mut self.prioritized_potential_packages; - (self.current_decision_level.0 as usize..package_assignments.len()) + (self.changed_this_decision_level..package_assignments.len()) .map(|i| package_assignments.get_index(i).unwrap()) .filter(|(_, pa)| check_all || pa.highest_decision_level == current_decision_level) .filter_map(|(p, pa)| pa.assignments_intersection.potential_package_filter(p)) @@ -231,6 +247,7 @@ impl PartialSolution PartialSolution