dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
dlinear::PicosatSatSolver Class Reference

PicoSAT is a SAT solver written in C. More...

#include <PicosatSatSolver.h>

Inheritance diagram for dlinear::PicosatSatSolver:
dlinear::SatSolver

Public Member Functions

void AddLiteral (const Literal &l, bool learned) override
 Add a literal l to the SAT solver.
 
void AddLearnedClause (const LiteralSet &literals) override
 Given a clause = {f₁, ..., fₙ}, adds a clause (¬f₁ ∨ ... ∨ ¬ fₙ) to the solver.
 
void AddLearnedClause (const Literal &lit) override
 Given a clause = {f}, adds a clause (¬f) to the solver.
 
void MakeSatVar (const Variable &var) override
 Add a variable to the internal SAT solver.
 
std::optional< ModelCheckSat () override
 Check the satisfiability of the current configuration.
 
void FixedTheoryLiterals (LiteralSet &fixed_literals) override
 Get the theory literals that are fixed in the current configuration.
 
void Assume (const Literal &l) override
 Assumption a literals to be fixed for the next iteration.
 
void Assume (const LiteralSet &literals)
 Assumption a set of literals to be fixed for the next iteration.
 
LiteralSet FixedTheoryLiterals ()
 Get the theory literals that are fixed in the current configuration.
 
- Public Member Functions inherited from dlinear::SatSolver
 SatSolver (PredicateAbstractor &predicate_abstractor, const std::string &class_name="SatSolver")
 Construct a new SatSolver object.
 
void AddFormula (const Formula &f)
 Add a formula f to the solver.
 
void AddFormulas (const std::vector< Formula > &formulas)
 Add the formulas to the solver.
 
void AddClause (const Formula &f)
 Add a formula f to the solver.
 
void AddClauses (const std::vector< Formula > &formulas)
 Add a vector of formulas formulas to the solver.
 
LiteralSet FixedTheoryLiterals ()
 Get the theory literals that are fixed in the current configuration.
 
void Assume (const LiteralSet &literals)
 Assumption a set of literals to be fixed for the next iteration.
 
void MarkAsCnfVariable (const Variable &var)
 Mark var as a CNF variable.
 
const IterationStatsstats () const
 Get read-only access to the statistics of the SAT solver.
 
const IterationStatscnfizer_stats () const
 Get read-only access to the statistics of the cnfizer of the SAT solver.
 
const PredicateAbstractorpredicate_abstractor () const
 Get read-only access to the predicate abstractor of the SAT solver.
 

Protected Member Functions

void AddClauseToSat (const Formula &f) override
 Add a clause f to the internal SAT solver.
 
- Protected Member Functions inherited from dlinear::SatSolver
void AddLiteral (const Formula &f)
 Add a formula f to the solver.
 
void GetMainActiveLiterals (std::set< int > &lits) const
 Get a set of the currently active literals in the clauses, ignoring those required by learned clauses.
 
Model OnSatResult ()
 If the SAT solver returns SAT, this function can be used to obtain a model for the formula.
 
void UpdateLookup (int lit)
 Update data structures used to minimize the number of assigned literals the theory solver has to verify.
 

Private Member Functions

std::set< int > GetMainActiveLiterals () override
 Get a set of the currently active literals in the clauses, ignoring those required by learned clauses.
 

Additional Inherited Members

- Protected Attributes inherited from dlinear::SatSolver
const Configconfig_
 Configuration of the SAT solver.
 
std::vector< int > main_clauses_copy_
 Store the main clauses to restore them after the SAT solver call.
 
std::map< int, std::set< std::size_t > > main_clause_lookup_
 Lookup table for literals in the main clauses.
 
std::size_t cur_clause_start_
 Index of the first clause added by the SAT solver.
 
ScopedUnorderedMap< Variable::Id, int > var_to_sat_
 Map symbolic::Variable → int (Variable type in PicoSat).
 
ScopedUnorderedMap< int, Variablesat_to_var_
 Map int (Variable type in PicoSat) → symbolic::Variable.
 
ScopedUnorderedSet< Variable::Id > cnf_variables_
 Set of temporary Boolean variables introduced by CNF transformations.
 
PlaistedGreenbaumCnfizer cnfizer_
 Converts the formula to CNF.
 
PredicateAbstractorpredicate_abstractor_
 Converts the theory literals to boolean variables.
 
IterationStats stats_
 Statistics for the solver.
 

Detailed Description

PicoSAT is a SAT solver written in C.

It is able to solve SAT problems in CNF format.

Definition at line 31 of file PicosatSatSolver.h.

Member Function Documentation

◆ AddClauseToSat()

void dlinear::PicosatSatSolver::AddClauseToSat ( const Formula & f)
overrideprotectedvirtual

Add a clause f to the internal SAT solver.

Precondition
f must be a clause. That is, it is either a literal (b or ¬b) or a disjunction of literals (l₁ ∨ ... ∨ lₙ).
Parameters
fclause to add

Implements dlinear::SatSolver.

Definition at line 97 of file PicosatSatSolver.cpp.

◆ AddLearnedClause() [1/2]

void dlinear::PicosatSatSolver::AddLearnedClause ( const Literal & literals)
overridevirtual

Given a clause = {f}, adds a clause (¬f) to the solver.

Parameters
literalsliterals to add as the inverted clause

Implements dlinear::SatSolver.

Definition at line 49 of file PicosatSatSolver.cpp.

◆ AddLearnedClause() [2/2]

void dlinear::PicosatSatSolver::AddLearnedClause ( const LiteralSet & literals)
overridevirtual

Given a clause = {f₁, ..., fₙ}, adds a clause (¬f₁ ∨ ... ∨ ¬ fₙ) to the solver.

Parameters
literalsliterals to add as the inverted clause

Implements dlinear::SatSolver.

Definition at line 45 of file PicosatSatSolver.cpp.

◆ AddLiteral()

void dlinear::PicosatSatSolver::AddLiteral ( const Literal & l,
bool learned )
overridevirtual

Add a literal l to the SAT solver.

If the literal is learned, it is added to the learned clause set and won't be used by the theory solver.

Parameters
lliteral to add
learnedwhether the literal is learned or was in the original formula

Implements dlinear::SatSolver.

Definition at line 54 of file PicosatSatSolver.cpp.

◆ Assume() [1/2]

void dlinear::PicosatSatSolver::Assume ( const Literal & lit)
overridevirtual

Assumption a literals to be fixed for the next iteration.

The lit is temporarily added to the solver with the indicated value.

Note
The solver will not remember the assumption after the next call to CheckSat.
Parameters
litliteral to assume

Implements dlinear::SatSolver.

Definition at line 128 of file PicosatSatSolver.cpp.

◆ Assume() [2/2]

void dlinear::SatSolver::Assume ( const LiteralSet & literals)

Assumption a set of literals to be fixed for the next iteration.

The literals are temporarily added to the solver with the indicated value.

Note
The solver will not remember the assumptions after the next call to CheckSat.
Parameters
literalsset of literals to assume

Definition at line 125 of file SatSolver.cpp.

◆ CheckSat()

std::optional< Model > dlinear::PicosatSatSolver::CheckSat ( )
overridevirtual

Check the satisfiability of the current configuration.

Returns
a witness, satisfying model if the problem is SAT.
empty optional if UNSAT

Implements dlinear::SatSolver.

Definition at line 76 of file PicosatSatSolver.cpp.

◆ FixedTheoryLiterals() [1/2]

LiteralSet dlinear::SatSolver::FixedTheoryLiterals ( )

Get the theory literals that are fixed in the current configuration.

This means that, for the model to be sat, these literals will never change their assignment. This allows for slight optimizations (e.g. their bound can be computed once, at the beginning of the run instead of at each iteration)

Returns
set of literals that are fixed

Definition at line 107 of file SatSolver.cpp.

◆ FixedTheoryLiterals() [2/2]

void dlinear::PicosatSatSolver::FixedTheoryLiterals ( LiteralSet & fixed_literals)
overridevirtual

Get the theory literals that are fixed in the current configuration.

This means that, for the model to be sat, these literals will never change their assignment. This allows for slight optimizations (e.g. their bound can be computed once, at the beginning of the run instead of at each iteration)

Parameters
[out]fixed_literalsset of literals that are fixed

Implements dlinear::SatSolver.

Definition at line 110 of file PicosatSatSolver.cpp.

◆ GetMainActiveLiterals()

std::set< int > dlinear::PicosatSatSolver::GetMainActiveLiterals ( )
nodiscardoverrideprivatevirtual

Get a set of the currently active literals in the clauses, ignoring those required by learned clauses.

Here literals are expressed as integers, where the sign indicates whether the literal is negated or not.

Returns
set of literals

Implements dlinear::SatSolver.

Definition at line 64 of file PicosatSatSolver.cpp.

◆ MakeSatVar()

void dlinear::PicosatSatSolver::MakeSatVar ( const Variable & var)
overridevirtual

Add a variable to the internal SAT solver.

Also update the two mapping between each symbolic Variable and the internal SAT solver's variable (var_to_sat_) and the other way around (sat_to_var_). If the variable had already been mapped, this function does nothing.

Parameters
varvariable to add

Implements dlinear::SatSolver.

Definition at line 33 of file PicosatSatSolver.cpp.


The documentation for this class was generated from the following files: