Expand description
The CaDiCaL incremental SAT solver. The literals are unwrapped positive and negative integers, exactly as in the DIMACS format. The common IPASIR operations are presented in a safe Rust interface.
Examples
let mut sat: cadical::Solver = Default::default();
sat.add_clause([1, 2]);
sat.add_clause([-1, 2]);
assert_eq!(sat.solve(), Some(true));
assert_eq!(sat.value(2), Some(true));
Implementations§
source§impl<C: Callbacks> Solver<C>
impl<C: Callbacks> Solver<C>
sourcepub fn with_config(config: &str) -> Result<Self, Error>
pub fn with_config(config: &str) -> Result<Self, Error>
Constructs a new solver with one of the following pre-defined configurations of advanced internal options:
default
: set default advanced internal optionsplain
: disable all internal preprocessing optionssat
: set internal options to target satisfiable instancesunsat
: set internal options to target unsatisfiable instances
sourcepub fn add_clause<I>(&mut self, clause: I)where
I: IntoIterator<Item = i32>,
pub fn add_clause<I>(&mut self, clause: I)where
I: IntoIterator<Item = i32>,
Adds the given clause to the solver. Negated literals are negative
integers, positive literals are positive ones. All literals must be
non-zero and different from i32::MIN
.
sourcepub fn solve(&mut self) -> Option<bool>
pub fn solve(&mut self) -> Option<bool>
Solves the formula defined by the added clauses. If the formula is
satisfiable, then Some(true)
is returned. If the formula is
unsatisfiable, then Some(false)
is returned. If the solver runs out
of resources or was terminated, then None
is returned.
sourcepub fn solve_with<I>(&mut self, assumptions: I) -> Option<bool>where
I: Iterator<Item = i32>,
pub fn solve_with<I>(&mut self, assumptions: I) -> Option<bool>where
I: Iterator<Item = i32>,
Solves the formula defined by the set of clauses under the given assumptions.
sourcepub fn status(&self) -> Option<bool>
pub fn status(&self) -> Option<bool>
Returns the status of the solver as returned by the last call to
solve
or solve_with
. The state becomes None
if a new clause
is added.
sourcepub fn value(&self, lit: i32) -> Option<bool>
pub fn value(&self, lit: i32) -> Option<bool>
Returns the value of the given literal in the last solution. The
state of the solver must be Some(true)
. The returned value is
None
if the formula is satisfied regardless of the value of the
literal.
sourcepub fn failed(&self, lit: i32) -> bool
pub fn failed(&self, lit: i32) -> bool
Checks if the given assumed literal (passed to solve_with
) was used
in the proof of the unsatisfiability of the formula. The state of the
solver must be Some(false)
.
sourcepub fn max_variable(&self) -> i32
pub fn max_variable(&self) -> i32
Returns the maximum variable index in the problem as maintained by the solver.
Examples
let mut sat: cadical::Solver = Default::default();
sat.add_clause([1, -3]);
assert_eq!(sat.max_variable(), 3);
assert_eq!(sat.num_variables(), 2);
assert_eq!(sat.num_clauses(), 1);
sourcepub fn num_variables(&self) -> i32
pub fn num_variables(&self) -> i32
Returns the number of active variables in the problem. Variables become active if a clause is added with it. They become inactive, if they are eliminated or become fixed at the root level.
sourcepub fn num_clauses(&self) -> usize
pub fn num_clauses(&self) -> usize
Returns the number of active irredundant clauses. Clauses become inactive if they are satisfied, subsumed or eliminated.
sourcepub fn set_limit(&mut self, name: &str, limit: i32) -> Result<(), Error>
pub fn set_limit(&mut self, name: &str, limit: i32) -> Result<(), Error>
Sets a solver limit with the corresponding name to the given value.
These limits are only valid for the next solve
or solve_with
call
and reset to their default values, which disables them.
The following limits are supported:
preprocessing
: the number of preprocessing rounds to be performed during the search (defaults to0
).localsearch
: the number of local search rounds to be performed during the search (defaults to0
).terminate
: this value is regularly decremented and aborts the solver when it reaches zero (defaults to0
).conflicts
: decremented when a conflict is detected and aborts the solver when it becomes negative (defaults to-1
).decisions
: decremented when a decision is made and aborts the solver when it becomes negative (defaults to-1
).
sourcepub fn set_callbacks(&mut self, cbs: Option<C>)
pub fn set_callbacks(&mut self, cbs: Option<C>)
Sets the callbacks to be called while the solver is running.
Examples
let mut sat: cadical::Solver = Default::default();
sat.add_clause([1, 2]);
sat.set_callbacks(Some(cadical::Timeout::new(0.0)));
assert_eq!(sat.solve(), None);
sourcepub fn get_callbacks(&mut self) -> Option<&mut C>
pub fn get_callbacks(&mut self) -> Option<&mut C>
Returns a mutable reference to the callbacks.
Trait Implementations§
impl<C: Callbacks + Send> Send for Solver<C>
CaDiCaL does not use thread local variables, so it is possible to
move it between threads. However it cannot be used queried concurrently
(for example getting the value from multiple threads at once), so we
do not implement Sync
.