Skip to content

Commit

Permalink
feat: return error when assumption is eliminated
Browse files Browse the repository at this point in the history
resolves #64
  • Loading branch information
chrjabs committed Mar 28, 2024
1 parent 9ca2be2 commit 9168a59
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
9 changes: 8 additions & 1 deletion glucose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
//! The version of Glucose in this crate is Version 4.2.1.
//! The used C++ source repository can be found [here](https://github.com/chrjabs/glucose4).
use rustsat::{solvers::SolverState, types::Lit};
use rustsat::{
solvers::SolverState,
types::{Lit, Var},
};
use std::{ffi::c_int, fmt};
use thiserror::Error;

Expand All @@ -26,6 +29,10 @@ pub struct InvalidApiReturn {
value: c_int,
}

#[derive(Error, Clone, Copy, PartialEq, Eq, Debug)]
#[error("assumption variable {0} has been eliminated by glucose simplification")]
pub struct AssumpEliminated(Var);

#[derive(Debug, PartialEq, Eq, Default)]
enum InternalSolverState {
#[default]
Expand Down
7 changes: 6 additions & 1 deletion glucose/src/simp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use core::ffi::{c_int, CStr};

use super::{InternalSolverState, InvalidApiReturn, Limit};
use super::{AssumpEliminated, InternalSolverState, InvalidApiReturn, Limit};
use cpu_time::ProcessTime;
use ffi::Glucose4Handle;
use rustsat::{
Expand Down Expand Up @@ -176,6 +176,11 @@ impl SolveIncremental for Glucose {
fn solve_assumps(&mut self, assumps: &[Lit]) -> anyhow::Result<SolverResult> {
let start = ProcessTime::now();
// Solve with glucose backend
for a in assumps {
if self.var_eliminated(a.var()) {
return Err(AssumpEliminated(a.var()).into());
}
}
for a in assumps {
unsafe { ffi::cglucosesimp4_assume(self.handle, a.to_ipasir()) }
}
Expand Down
9 changes: 8 additions & 1 deletion minisat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
//! The version of minisat in this crate is Version 2.2.0.
//! The used C++ source repository can be found [here](https://github.com/chrjabs/minisat).
use rustsat::{solvers::SolverState, types::Lit};
use rustsat::{
solvers::SolverState,
types::{Lit, Var},
};
use std::{ffi::c_int, fmt};
use thiserror::Error;

Expand All @@ -26,6 +29,10 @@ pub struct InvalidApiReturn {
value: c_int,
}

#[derive(Error, Clone, Copy, PartialEq, Eq, Debug)]
#[error("assumption variable {0} has been eliminated by minisat simplification")]
pub struct AssumpEliminated(Var);

#[derive(Debug, PartialEq, Eq, Default)]
enum InternalSolverState {
#[default]
Expand Down
7 changes: 6 additions & 1 deletion minisat/src/simp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use core::ffi::{c_int, CStr};

use super::{InternalSolverState, InvalidApiReturn, Limit};
use super::{AssumpEliminated, InternalSolverState, InvalidApiReturn, Limit};
use cpu_time::ProcessTime;
use ffi::MinisatHandle;
use rustsat::{
Expand Down Expand Up @@ -176,6 +176,11 @@ impl SolveIncremental for Minisat {
fn solve_assumps(&mut self, assumps: &[Lit]) -> anyhow::Result<SolverResult> {
let start = ProcessTime::now();
// Solve with minisat backend
for a in assumps {
if self.var_eliminated(a.var()) {
return Err(AssumpEliminated(a.var()).into());
}
}
for a in assumps {
unsafe { ffi::cminisatsimp_assume(self.handle, a.to_ipasir()) }
}
Expand Down

0 comments on commit 9168a59

Please sign in to comment.