Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
prsabahrami committed Jan 24, 2025
1 parent 220fed0 commit 0426ba3
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 84 deletions.
8 changes: 5 additions & 3 deletions src/solver/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ impl Clause {
false,
)
} else {
// No valid requirement candidate, use first condition candidate and mark conflict
// No valid requirement candidate and condition is true
// This is an immediate conflict - we can't satisfy the requirement
// We need to watch the condition candidate to detect when it becomes true
(
Clause::Conditional(parent_id, condition, requirement),
Some([parent_id.negative(), condition_first_candidate.positive()]),
Some([parent_id.negative(), condition_first_candidate.negative()]),
true,
)
}
Expand All @@ -284,7 +286,7 @@ impl Clause {
false,
)
} else {
// All conditions false
// All conditions false, no conflict
(
Clause::Conditional(parent_id, condition, requirement),
None,
Expand Down
34 changes: 34 additions & 0 deletions src/solver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,40 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
self.decide_assertions(level)?;
self.decide_learned(level)?;

// Check for conflicts in conditional clauses
for ((solvable_id, condition), clauses) in &self.conditional_clauses {
// Only check clauses where the parent is true
if self.decision_tracker.assigned_value(*solvable_id) != Some(true) {
continue;
}

Check warning on line 1164 in src/solver/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/resolvo/resolvo/src/solver/mod.rs
// Check if the condition is true
let condition_requirement: Requirement = (*condition).into();
let conditional_candidates = &self.requirement_to_sorted_candidates[&condition_requirement];
let condition_is_true = conditional_candidates.iter().any(|candidates| {
candidates.iter().any(|&candidate| {
self.decision_tracker.assigned_value(candidate) == Some(true)
})
});

if condition_is_true {
// For each clause, check if all requirement candidates are false

Check warning on line 1175 in src/solver/mod.rs

View workflow job for this annotation

GitHub Actions / Format and Lint

Diff in /home/runner/work/resolvo/resolvo/src/solver/mod.rs
for (requirement, clause_id) in clauses {
let requirement_candidates = &self.requirement_to_sorted_candidates[requirement];
let all_candidates_false = requirement_candidates.iter().all(|candidates| {
candidates.iter().all(|&candidate| {
self.decision_tracker.assigned_value(candidate) == Some(false)
})
});

if all_candidates_false {
// This is a conflict - we have a true condition but can't satisfy the requirement
return Err(PropagationError::Conflict(*solvable_id, true, *clause_id));
}
}
}
}

// For each decision that has not been propagated yet, we propagate the
// decision.
//
Expand Down
10 changes: 0 additions & 10 deletions tests/.solver.rs.pending-snap

This file was deleted.

Loading

0 comments on commit 0426ba3

Please sign in to comment.