Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve preproc triviality checks #68

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/common/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{common::mk_dir, errors::*, instance::Instance};
macro_rules! app_fun {
// Internal rules.
(@app $app:expr, $order:expr =>) => ($app);
(@app $app:expr, $o7rder:expr =>
(@app $app:expr, $order:expr =>
, $($tail:tt)*
) => (
app_fun!(@app $app, $order => $($tail)*)
Expand Down Expand Up @@ -1179,6 +1179,12 @@ impl Config {
self.check.as_ref()
}

/// True if a timeout was specified.
#[inline]
pub fn has_timeout(&self) -> bool {
self.timeout.is_some()
}

/// Checks if we're out of time.
#[inline]
pub fn check_timeout(&self) -> Res<()> {
Expand Down
77 changes: 72 additions & 5 deletions src/common/smt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn preproc_reset<P>(solver: &mut Solver<P>) -> Res<()> {
}

/// Performs a check-sat.
pub fn tmo_multi_try_check_sat<P, F>(
pub fn tmo_multi_try_check_sat_legacy<P, F>(
solver: &mut Solver<P>,
tmo: ::std::time::Duration,
do_stuff: F,
Expand All @@ -87,6 +87,44 @@ where
}
}

/// Performs a check-sat.
pub fn tmo_multi_check_sat<P, F>(
solver: &mut Solver<P>,
tmo: ::std::time::Duration,
do_stuff: F,
) -> Res<bool>
where
F: FnOnce(&mut Solver<P>) -> Res<()>,
{
solver.set_option(":timeout", &format!("{}000", tmo.as_secs()))?;
if let Some(res) = multi_try_check_sat_or_unk(solver)? {
return Ok(res);
}
do_stuff(solver)?;
if let Some(res) = multi_try_check_sat_or_unk(solver)? {
Ok(res)
} else {
bail!(crate::errors::ErrorKind::Unknown)
}
}

/// Performs a check-sat.
pub fn tmo_multi_try_check_sat<P, F>(
solver: &mut Solver<P>,
tmo: ::std::time::Duration,
do_stuff: F,
) -> Res<Option<bool>>
where
F: FnOnce(&mut Solver<P>) -> Res<()>,
{
solver.set_option(":timeout", &format!("{}000", tmo.as_secs()))?;
if let Some(res) = multi_try_check_sat_or_unk(solver)? {
return Ok(Some(res));
}
do_stuff(solver)?;
multi_try_check_sat_or_unk(solver)
}

/// Performs a check-sat.
///
/// Tries to check-sat a solver with various strategies. Returns the result of the first tries that
Expand Down Expand Up @@ -298,19 +336,45 @@ where
}

solver.assert_with(self, false)?;
let sat = tmo_multi_try_check_sat(
let sat = tmo_multi_try_check_sat_legacy(
solver,
conf.until_timeout()
.map(|time| time / 20)
.map(|time| time / 100)
.unwrap_or_else(|| ::std::time::Duration::new(1, 0)),
|solver| {
solver.assert_with(self, true)?;
Ok(())
},
true,
!conf.has_timeout(),
)?;
Ok(!sat)
}

/// Checks if this conjunction is unsatisfiable.
fn try_is_unsat<Parser: Copy>(&self, solver: &mut Solver<Parser>) -> Res<Option<bool>> {
if self.terms.len() == 0 {
return Ok(Some(false));
}
for var in self.infos {
if var.active {
solver.declare_const(&var.idx, var.typ.get())?
}
}

solver.assert_with(self, false)?;
let is_unsat = tmo_multi_try_check_sat(
solver,
conf.until_timeout()
.map(|time| time / 100)
.unwrap_or_else(|| ::std::time::Duration::new(1, 0)),
|solver| {
solver.assert_with(self, true)?;
Ok(())
},
)?
.map(|b| !b);
Ok(is_unsat)
}
}

impl<'a, 'b, Trms> Expr2Smt<bool> for SmtConj<'b, Trms>
Expand Down Expand Up @@ -1033,7 +1097,10 @@ impl<Parser: Copy> ClauseTrivialExt for Solver<Parser> {
if lhs.is_empty() {
Ok(Some(false))
} else {
conj.is_unsat(self).map(Some)
match conj.try_is_unsat(self) {
Ok(Some(true)) => Ok(Some(true)),
_ => Ok(Some(false)),
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/teacher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ impl<'a> Teacher<'a> {
let tru_preds = & self.tru_preds;
let fls_preds = & self.fls_preds;
let instance = & self.instance;
smt::tmo_multi_try_check_sat(
smt::tmo_multi_try_check_sat_legacy(
solver,
conf.until_timeout().map(
|time| time / 20
Expand Down
Loading