Skip to content

Commit

Permalink
Fix handling of empty clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekker1 committed Oct 8, 2024
1 parent 4a16611 commit f23baaa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 7 additions & 5 deletions crates/pindakaas-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,17 @@ pub fn ipasir_solver_derive(input: TokenStream) -> TokenStream {
&mut self,
clause: I,
) -> crate::Result {
let mut added = false;
let mut empty = true;
for lit in clause.into_iter() {
unsafe { #krate::ipasir_add( #ptr , lit.into()) };
added = true;
empty = false;
}
if added {
unsafe { #krate::ipasir_add( #ptr , 0) };
unsafe { #krate::ipasir_add( #ptr , 0) };
if empty {
Err(crate::Unsatisfiable)
} else {
Ok(())
}
Ok(())
}

type CondDB = Self;
Expand Down
8 changes: 5 additions & 3 deletions crates/pindakaas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,12 @@ impl ClauseDatabase for Cnf {
let size = self.lits.len();
self.lits.extend(cl);
let len = self.lits.len() - size;
if len > 0 {
self.size.push(len);
self.size.push(len);
if len == 0 {
Err(Unsatisfiable)
} else {
Ok(())
}
Ok(())
}

type CondDB = Self;
Expand Down
9 changes: 8 additions & 1 deletion crates/pindakaas/src/solver/cadical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod tests {
use crate::{
linear::LimitComp,
solver::{cadical::Cadical, SolveResult, Solver},
CardinalityOne, ClauseDatabase, Encoder, PairwiseEncoder, Valuation,
CardinalityOne, ClauseDatabase, Encoder, PairwiseEncoder, Unsatisfiable, Valuation,
};

#[test]
Expand Down Expand Up @@ -152,6 +152,13 @@ mod tests {
);
}

#[test]
fn test_cadical_empty_clause() {
let mut slv = Cadical::default();
assert_eq!(slv.add_clause([]), Err(Unsatisfiable));
assert_eq!(slv.solve(|_| unreachable!()), SolveResult::Unsat);
}

#[cfg(feature = "ipasir-up")]
#[test]
fn test_ipasir_up() {
Expand Down

0 comments on commit f23baaa

Please sign in to comment.