Skip to content

Commit d9db162

Browse files
committed
fix logging more root level unit thingies
1 parent efc33e2 commit d9db162

File tree

3 files changed

+45
-14
lines changed

3 files changed

+45
-14
lines changed

pumpkin-solver/src/engine/conflict_analysis/conflict_analysis_context.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ use crate::variables::DomainId;
2727
/// Used during conflict analysis to provide the necessary information.
2828
///
2929
/// All fields are made public for the time being for simplicity. In the future that may change.
30-
pub(crate) struct ConflictAnalysisContext<'a> {
30+
pub(crate) struct ConflictAnalysisContext<'a, 'reasons> {
3131
pub(crate) assignments: &'a mut Assignments,
3232
pub(crate) solver_state: &'a mut CSPSolverState,
33-
pub(crate) reason_store: &'a mut ReasonStore,
33+
pub(crate) reason_store: &'reasons mut ReasonStore,
3434
pub(crate) brancher: &'a mut dyn Brancher,
3535
pub(crate) propagators: &'a mut PropagatorStore,
3636
pub(crate) semantic_minimiser: &'a mut SemanticMinimiser,
@@ -50,13 +50,13 @@ pub(crate) struct ConflictAnalysisContext<'a> {
5050
pub(crate) unit_nogood_step_ids: &'a HashMap<Predicate, StepId>,
5151
}
5252

53-
impl Debug for ConflictAnalysisContext<'_> {
53+
impl Debug for ConflictAnalysisContext<'_, '_> {
5454
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5555
f.debug_struct(std::any::type_name::<Self>()).finish()
5656
}
5757
}
5858

59-
impl<'a> ConflictAnalysisContext<'a> {
59+
impl<'reasons> ConflictAnalysisContext<'_, 'reasons> {
6060
/// Returns the last decision which was made by the solver.
6161
pub(crate) fn find_last_decision(&mut self) -> Option<Predicate> {
6262
self.assignments.find_last_decision()
@@ -133,11 +133,11 @@ impl<'a> ConflictAnalysisContext<'a> {
133133
predicate: Predicate,
134134
assignments: &Assignments,
135135
current_nogood: CurrentNogood<'_>,
136-
reason_store: &'a mut ReasonStore,
137-
propagators: &'a mut PropagatorStore,
138-
proof_log: &'a mut ProofLog,
136+
reason_store: &'reasons mut ReasonStore,
137+
propagators: &'reasons mut PropagatorStore,
138+
proof_log: &mut ProofLog,
139139
unit_nogood_step_ids: &HashMap<Predicate, StepId>,
140-
) -> &'a [Predicate] {
140+
) -> &'reasons [Predicate] {
141141
// TODO: this function could be put into the reason store
142142

143143
// Note that this function can only be called with propagations, and never decision

pumpkin-solver/src/engine/conflict_analysis/resolvers/resolution_resolver.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use std::num::NonZero;
2+
13
use super::ConflictResolver;
24
use crate::basic_types::moving_averages::MovingAverage;
5+
use crate::basic_types::HashMap;
36
use crate::basic_types::PredicateId;
47
use crate::basic_types::PredicateIdGenerator;
58
use crate::branching::Brancher;
@@ -12,6 +15,7 @@ use crate::engine::conflict_analysis::LearnedNogood;
1215
use crate::engine::propagation::CurrentNogood;
1316
use crate::engine::Assignments;
1417
use crate::predicates::Predicate;
18+
use crate::proof::ProofLog;
1519
use crate::pumpkin_assert_advanced;
1620
use crate::pumpkin_assert_moderate;
1721
use crate::pumpkin_assert_simple;
@@ -75,6 +79,8 @@ impl ConflictResolver for ResolutionResolver {
7579
self.add_predicate_to_conflict_nogood(
7680
*predicate,
7781
context.assignments,
82+
context.proof_log,
83+
context.unit_nogood_step_ids,
7884
context.brancher,
7985
self.mode,
8086
context.is_completing_proof,
@@ -244,6 +250,8 @@ impl ConflictResolver for ResolutionResolver {
244250
self.add_predicate_to_conflict_nogood(
245251
*predicate,
246252
context.assignments,
253+
context.proof_log,
254+
context.unit_nogood_step_ids,
247255
context.brancher,
248256
self.mode,
249257
context.is_completing_proof,
@@ -273,13 +281,19 @@ impl ResolutionResolver {
273281
self.to_process_heap.clear();
274282
}
275283

284+
#[allow(
285+
clippy::too_many_arguments,
286+
reason = "borrow checker complains if passing through the context"
287+
)]
276288
fn add_predicate_to_conflict_nogood(
277289
&mut self,
278290
predicate: Predicate,
279291
assignments: &Assignments,
292+
proof_log: &mut ProofLog,
293+
unit_nogood_step_ids: &HashMap<Predicate, NonZero<u64>>,
280294
brancher: &mut dyn Brancher,
281295
mode: AnalysisMode,
282-
is_logging_complete_proof: bool,
296+
is_completing_proof: bool,
283297
) {
284298
let dec_level = assignments
285299
.get_decision_level_for_predicate(&predicate)
@@ -290,18 +304,34 @@ impl ResolutionResolver {
290304
assignments.get_upper_bound(predicate.get_domain()),
291305
)
292306
});
293-
// Ignore root level predicates.
294-
if !is_logging_complete_proof && dec_level == 0 {
295-
// do nothing
307+
308+
// Log all non-initial bounds to the proof.
309+
if dec_level == 0 && !is_completing_proof {
310+
if !assignments.is_initial_bound(predicate) {
311+
let trail_index = assignments
312+
.get_trail_position(&predicate)
313+
.expect("all predicates in reason are true");
314+
let trail_entry = assignments.get_trail_entry(trail_index);
315+
316+
// We do indicate their usage in the proof.
317+
let step_id = unit_nogood_step_ids
318+
.get(&trail_entry.predicate)
319+
.copied()
320+
.unwrap();
321+
proof_log.add_propagation(step_id);
322+
}
323+
324+
return;
296325
}
326+
297327
// 1UIP
298328
// If the variables are from the current decision level then we want to potentially add
299329
// them to the heap, otherwise we add it to the predicates from lower-decision levels
300330
//
301331
// All-decision Learning
302332
// If the variables are not decisions then we want to potentially add them to the heap,
303333
// otherwise we add it to the decision predicates which have been discovered previously
304-
else if match mode {
334+
if match mode {
305335
AnalysisMode::OneUIP => dec_level == assignments.get_decision_level(),
306336
AnalysisMode::AllDecision => !assignments.is_decision_predicate(&predicate),
307337
} {

pumpkin-solver/src/engine/constraint_satisfaction_solver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ impl ConstraintSatisfactionSolver {
386386
.iter()
387387
.copied()
388388
.all(Predicate::is_trivially_true),
389-
"At the root, conflict analysis should result in a trivial conflict"
389+
"At the root, conflict analysis should result in a trivial conflict: {:?}",
390+
result.predicates,
390391
);
391392

392393
let _ = self

0 commit comments

Comments
 (0)