Skip to main content

Solver

Struct Solver 

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

CDCL SAT Solver

Implementations§

Source§

impl Solver

Source

pub fn new() -> Self

Create a new solver

Source

pub fn with_config(config: SolverConfig) -> Self

Create a new solver with configuration

Source

pub fn new_var(&mut self) -> Var

Create a new variable

Source

pub fn ensure_vars(&mut self, n: usize)

Ensure we have at least n variables

Source

pub fn add_clause(&mut self, lits: impl IntoIterator<Item = Lit>) -> bool

Add a clause

Source

pub fn add_clause_dimacs(&mut self, lits: &[i32]) -> bool

Add a clause from DIMACS literals

Source

pub fn solve(&mut self) -> SolverResult

Solve the SAT problem

Source

pub fn solve_with_assumptions( &mut self, assumptions: &[Lit], ) -> (SolverResult, Option<Vec<Lit>>)

Solve with assumptions and return unsat core if UNSAT

This is the key method for MaxSAT: it solves under assumptions and if the result is UNSAT, returns the subset of assumptions in the core.

§Arguments
  • assumptions - Literals that must be true
§Returns
  • (SolverResult, Option<Vec<Lit>>) - Result and unsat core (if UNSAT)
Source

pub fn solve_with_theory<T: TheoryCallback>( &mut self, theory: &mut T, ) -> SolverResult

Solve with theory integration via callbacks

This implements the CDCL(T) loop:

  1. BCP (Boolean Constraint Propagation)
  2. Theory propagation (via callback)
  3. On conflict: analyze and learn
  4. Decision
  5. Final theory check when all vars assigned
Source

pub fn model(&self) -> &[LBool]

Get the model (if sat)

Source

pub fn model_value(&self, var: Var) -> LBool

Get the value of a variable in the model

Source

pub fn stats(&self) -> &SolverStats

Get statistics

Source

pub fn memory_opt_stats(&self) -> &MemoryOptStats

Get memory optimizer statistics

Source

pub fn num_vars(&self) -> usize

Get number of variables

Source

pub fn num_clauses(&self) -> usize

Get number of clauses

Source

pub fn push(&mut self)

Push a new assertion level (for incremental solving)

This saves the current state so that clauses added after this point can be removed with pop(). Automatically backtracks to decision level 0 to ensure a clean state for adding new constraints.

Source

pub fn pop(&mut self)

Pop to previous assertion level

Source

pub fn backtrack_to_root(&mut self)

Backtrack to decision level 0 (for AllSAT enumeration)

This is necessary after a SAT result before adding blocking clauses to ensure the new clauses can trigger propagation correctly. Uses phase-saving backtrack to properly re-insert unassigned variables into the decision heaps (VSIDS, CHB, LRB).

Source

pub fn reset(&mut self)

Reset the solver

Source

pub fn trail(&self) -> &Trail

Get the current trail (for theory solvers)

Source

pub fn decision_level(&self) -> u32

Get the current decision level

Source

pub fn debug_print_learned_clauses(&self)

Debug method: print all learned clauses

Source

pub fn debug_print_binary_graph(&self)

Debug method: print binary implication graph entries

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 Default for Solver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more