Dpll

Struct Dpll 

Source
pub struct Dpll<Config: SolverConfig + Clone = DefaultConfig> {
    pub trail: Trail<Config::Literal, Config::LiteralStorage>,
    pub assignment: Config::Assignment,
    pub decision_level: DecisionLevel,
    pub cnf: Cnf<Config::Literal, Config::LiteralStorage>,
    pub selector: Config::VariableSelector,
    pub propagator: Config::Propagator,
}
Expand description

Represents a DPLL SAT solver.

This struct encapsulates the state of the solver, including the CNF formula, current assignment, decision level, and components for propagation and variable selection. It is generic over Config, which defines the specific types and strategies used by the solver.

Fields§

§trail: Trail<Config::Literal, Config::LiteralStorage>

The trail of assignments and decisions made by the solver. It’s used by the propagator to manage assignments and detect conflicts.

§assignment: Config::Assignment

The current assignment of truth values to variables.

§decision_level: DecisionLevel

The current decision level in the DPLL search tree. Incremented each time a new variable is chosen for branching.

§cnf: Cnf<Config::Literal, Config::LiteralStorage>

The Conjunctive Normal Form (CNF) formula being solved.

§selector: Config::VariableSelector

The variable selection heuristic. Used to pick the next unassigned variable for a decision.

§propagator: Config::Propagator

The unit propagator. Responsible for performing unit propagation based on the current assignment.

Trait Implementations§

Source§

impl<Config: Clone + SolverConfig + Clone> Clone for Dpll<Config>
where Config::Literal: Clone, Config::LiteralStorage: Clone, Config::Assignment: Clone, Config::VariableSelector: Clone, Config::Propagator: Clone,

Source§

fn clone(&self) -> Dpll<Config>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Config: Debug + SolverConfig + Clone> Debug for Dpll<Config>
where Config::Literal: Debug, Config::LiteralStorage: Debug, Config::Assignment: Debug, Config::VariableSelector: Debug, Config::Propagator: Debug,

Source§

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

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

impl<Config: SolverConfig + Clone> Solver<Config> for Dpll<Config>

Source§

fn new<L: Literal, S: LiteralStorage<L>>(cnf: Cnf<L, S>) -> Self

Creates a new DPLL solver instance for the given CNF formula.

§Arguments
  • cnf: The CNF formula to be solved.
§Returns

A new Dpll instance initialised with the provided formula and default components (propagator, assignment tracker, trail, variable selector) based on the Config.

Source§

fn solve(&mut self) -> Option<Solutions>

Attempts to solve the SAT formula.

This method implements the core DPLL algorithm:

  1. It first performs unit propagation (self.propagate()).
  2. Then, it checks if the formula is already satisfied (self.is_sat()). If so, it returns the current assignment.
  3. It checks if the formula is unsatisfiable (self.is_unsat()) due to a conflict. If so, it returns None.
  4. If the formula is neither satisfied nor unsatisfiable, it selects an unassigned variable using self.selector.pick().
  5. It increments the decision level.
  6. It creates two branches: one where the chosen variable is assigned true, and one where it’s assigned false. These branches are explored recursively by calling solve() on cloned solver states.
  7. If the ‘true’ branch finds a solution, it’s returned.
  8. Otherwise, if the ‘false’ branch finds a solution, it’s returned.
  9. If neither branch finds a solution, the formula is unsatisfiable from the current state, and None is returned.
§Returns
  • Some(Solutions): If the formula is satisfiable, containing the satisfying assignment.
  • None: If the formula is unsatisfiable.
Source§

fn solutions(&self) -> Solutions

Returns the current satisfying assignment if the formula is SAT.

This method should typically be called after solve() returns Some(...). It retrieves the model (variable assignments) from the assignment component. Variables not assigned a value in the model might be “don’t care” variables.

Source§

fn stats(&self) -> SolutionStats

Returns statistics about the solving process.

Note: Some statistics, like propagations, might be estimations or specific to this simple DPLL implementation rather than a general count of propagation steps. conflicts, restarts, learnt_clauses, removed_clauses are currently placeholders.

Source§

fn debug(&mut self)

Placeholder for a debugging function.

Currently, this function is not implemented and will panic if called.

Source§

fn from_parts<L: Literal, S: LiteralStorage<L>>( cnf: Cnf<L, S>, assignment: Config::Assignment, _manager: Config::ClauseManager, propagator: Config::Propagator, _restarter: Config::Restarter, selector: Config::VariableSelector, ) -> Self

Creates a solver instance from its components. Read more

Auto Trait Implementations§

§

impl<Config> Freeze for Dpll<Config>

§

impl<Config> RefUnwindSafe for Dpll<Config>

§

impl<Config = DefaultConfig> !Send for Dpll<Config>

§

impl<Config = DefaultConfig> !Sync for Dpll<Config>

§

impl<Config> Unpin for Dpll<Config>
where <Config as SolverConfig>::Assignment: Unpin, <Config as SolverConfig>::VariableSelector: Unpin, <Config as SolverConfig>::Propagator: Unpin, <Config as SolverConfig>::Literal: Unpin, <Config as SolverConfig>::LiteralStorage: Unpin,

§

impl<Config> UnwindSafe for Dpll<Config>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.