Struct Solver

Source
pub struct Solver { /* private fields */ }
Expand description

Solver object representing an instance of the boolean satisfiability problem.

Implementations§

Source§

impl Solver

Source

pub fn new() -> Self

Create a new SAT solver instance.

Source

pub fn new_lit(&mut self) -> Bool

Create a fresh boolean variable.

Source

pub fn add_clause<I: IntoIterator<Item = Bool>>(&mut self, lits: I)

Add a clause to the SAT instance (assert the disjunction of the given literals).

Source

pub fn solve<'a>(&'a mut self) -> Result<Model<'a>, ()>

Solve the SAT instance, returning a solution (Model) if the instance is satisfiable, or returning an Err(()) if the problem is unsatisfiable.

Source

pub fn solve_under_assumptions<'a, I: IntoIterator<Item = Bool>>( &'a mut self, lits: I, ) -> Result<Model<'a>, ()>

Solve the SAT instance under given assumptions, returning a solution (Model) if the instance is satisfiable, or returning an Err(()) if the problem is unsatisfiable.

The conjunction of the given literals are temporarily added to the SAT instance, so the result is the same as if each literal was added as a clause, but the solver object can be re-used afterwards and does then not contain these assumptions. This interface can be used to build SAT instances incrementally.

Source

pub fn and_literal<I: IntoIterator<Item = Bool>>(&mut self, xs: I) -> Bool

Return a literal representing the conjunction of the given booleans.

Source

pub fn or_literal<I: IntoIterator<Item = Bool>>(&mut self, xs: I) -> Bool

Return a literal representing the disjunctino of the given booleans.

Source

pub fn assert_at_most_one(&mut self, xs: impl Iterator<Item = Bool>)

Assert that at most one of the given booleans can be true.

Source

pub fn assert_exactly_one<I: IntoIterator<Item = Bool>>(&mut self, xs: I)

Assert that exactly one of the given booleans is set to true.

Source

pub fn implies(&mut self, a: Bool, b: Bool) -> Bool

Returns a literal representing the truth value of the implication a -> b.

Source

pub fn equiv(&mut self, a: Bool, b: Bool) -> Bool

Returns a literal representing whether the two given booleans have the same value.

Source

pub fn assert_parity<I: IntoIterator<Item = Bool>>(&mut self, xs: I, x: bool)

Assert that the odd parity bit of the given list of booleans has the given value.

Source

pub fn assert_parity_or<I: IntoIterator<Item = Bool>, J: IntoIterator<Item = Bool>>( &mut self, prefix: I, xs: J, c: bool, )

Assert that the odd parity bit of the given list of booleans has the given value, except if any of the values in prefix are true.

Source

pub fn xor_literal<I: IntoIterator<Item = Bool>>(&mut self, xs: I) -> Bool

Returns a Bool which represents the odd parity bit for the given sequence of Bool values.

Source

pub fn equal<T: ModelEq>(&mut self, a: &T, b: &T)

Assert the equality of the given objects.

Source

pub fn not_equal<T: ModelEq>(&mut self, a: &T, b: &T)

Assert the non-equality of the given objects.

Source

pub fn greater_than<T: ModelOrd>(&mut self, a: &T, b: &T)

Assert a > b.

Source

pub fn greater_than_equal<T: ModelOrd>(&mut self, a: &T, b: &T)

Assert a >= b.

Source

pub fn less_than<T: ModelOrd>(&mut self, a: &T, b: &T)

Assert a < b.

Source

pub fn less_than_equal<T: ModelOrd>(&mut self, a: &T, b: &T)

Assert a <= b.

Source

pub fn greater_than_or<T: ModelOrd, I: IntoIterator<Item = Bool>>( &mut self, prefix: I, a: &T, b: &T, )

Assert a > b unless any of the booleans in the given prefix are true.

Source

pub fn greater_than_equal_or<T: ModelOrd, I: IntoIterator<Item = Bool>>( &mut self, prefix: I, a: &T, b: &T, )

Assert a >= b unless any of the booleans in the given prefix are true.

Source

pub fn less_than_or<T: ModelOrd, I: IntoIterator<Item = Bool>>( &mut self, prefix: I, a: &T, b: &T, )

Assert a < b unless any of the booleans in the given prefix are true.

Source

pub fn less_than_equal_or<T: ModelOrd, I: IntoIterator<Item = Bool>>( &mut self, prefix: I, a: &T, b: &T, )

Assert a <= b unless any of the booleans in the given prefix are true.

Source

pub fn num_assigns(&self) -> isize

Return the number of assignments to variables made in the solver instance.

Source

pub fn num_clauses(&self) -> isize

Return the number of clauses in the solver instance.

Source

pub fn num_learnts(&self) -> isize

Return the number of learnt clauses in the solver instance.

Source

pub fn num_vars(&self) -> isize

Return the number of variables in the solver instance.

Source

pub fn num_free_vars(&self) -> isize

Return the number of free variables in the solver instance.

Source

pub fn solver_name(&self) -> &'static str

Name and version of SAT solver.

Trait Implementations§

Source§

impl Debug for Solver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Solver

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Solver

§

impl RefUnwindSafe for Solver

§

impl !Send for Solver

§

impl !Sync for Solver

§

impl Unpin for Solver

§

impl UnwindSafe for Solver

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.