ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SatSolvers.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File SatSolvers.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
61/*--------------------------------------------------------------------------*/
62/*----------------------------- DEFINITIONS --------------------------------*/
63/*--------------------------------------------------------------------------*/
64
65#ifndef __ADS_SatSolvers
66 #define __ADS_SatSolvers
67/* self-identification: #endif constant */
68
69/*--------------------------------------------------------------------------*/
70/*------------------------------ INCLUDES ----------------------------------*/
71/*--------------------------------------------------------------------------*/
72
73#include "ADS/Contract.h"
75
76#include <algorithm>
77#include <cstdlib>
78#include <optional>
79#include <queue>
80#include <utility>
81#include <vector>
82
83/*--------------------------------------------------------------------------*/
84/*--------------------------- NAMESPACE ------------------------------------*/
85/*--------------------------------------------------------------------------*/
86
87namespace ADS
88{
89
124inline std::optional< std::vector< bool > > dpll( const Cnf & F , int n );
125
126/*--------------------------------------------------------------------------*/
127/*---------------------------- CLASS BasicCdcl -----------------------------*/
128/*--------------------------------------------------------------------------*/
129
136template< class Heap = std::priority_queue< std::pair< double , int > > >
138{
139
140/*--------------------------------------------------------------------------*/
141 public:
143 enum class Result {
147 };
148
154 BasicCdcl( const Cnf & F , int n );
155
226 Result solve( long maxConflicts = -1 );
227
229 [[nodiscard]] const std::vector< bool > & model( void ) const;
230
232 [[nodiscard]] long conflicts( void ) const { return( f_conflicts ); }
233
235 [[nodiscard]] long decisions( void ) const { return( f_decisions ); }
236
237/*--------------------------------------------------------------------------*/
238 private:
240 static int code( int lit ) {
241 return( 2 * ( std::abs( lit ) - 1 ) + ( lit < 0 ) );
242 }
243
245 [[nodiscard]] int value( int c ) const;
246
247 void enqueue( int c , int reason );
248 [[nodiscard]] int propagate( void );
249 void analyze( int confl , std::vector< int > & learnt , int & back );
250 void cancelUntil( int level );
251 void bump( int v );
252 [[nodiscard]] int pickBranch( void );
253 [[nodiscard]] int level( void ) const { return( int( f_trailLim.size() ) ); }
254 int addClause( std::vector< int > c );
255
256 Cnf f_F;
257 int f_n;
258 bool f_empty = false;
260 std::vector< std::vector< int > > f_C;
261 std::vector< std::vector< int > > f_watch;
262 std::vector< int > f_assign , f_level , f_reason;
263 std::vector< bool > f_phase , f_seen , f_model;
264 std::vector< int > f_trail , f_trailLim;
265 std::size_t f_qhead = 0;
266 std::vector< double > f_act;
267 double f_inc = 1;
268 Heap f_heap;
269 long f_conflicts = 0 , f_decisions = 0;
270
271 }; // end( class BasicCdcl )
272
275
276/*--------------------------------------------------------------------------*/
277
278} // end( namespace ADS )
279
280/*--------------------------------------------------------------------------*/
281/*-------------------------- IMPLEMENTATION --------------------------------*/
282/*--------------------------------------------------------------------------*/
283
284#include "ADS/backtrack/impl/SatSolvers.tpp"
285
286/*--------------------------------------------------------------------------*/
287
288#endif /* SatSolvers.h included */
289
290/*--------------------------------------------------------------------------*/
291/*------------------------- End File SatSolvers.h --------------------------*/
292/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The problems in NP of chapter 18, each with its polynomial certificate, which checks a proposed solut...
conflict-driven clause learning with two watched literals, the free variables by activity in a Heap o...
Definition SatSolvers.h:138
long decisions(void) const
the decisions taken so far
Definition SatSolvers.h:235
BasicCdcl(const Cnf &F, int n)
the solver of the formula of variables, its clauses with the repeated literals merged and the tauto...
Result
the outcome of solve()
Definition SatSolvers.h:143
@ UNSAT
the formula is unsatisfiable
Definition SatSolvers.h:145
@ SAT
a model found, in model()
Definition SatSolvers.h:144
@ UNKNOWN
the conflicts allowed are over before an answer
Definition SatSolvers.h:146
const std::vector< bool > & model(void) const
the model found by solve()
long conflicts(void) const
the conflicts met so far
Definition SatSolvers.h:232
Result solve(long maxConflicts=-1)
the search, UNKNOWN after maxConflicts conflicts if that is
std::optional< std::vector< bool > > dpll(const Cnf &F, int n)
a model of the formula of variables by DPLL, the variables left free false, or nothing if is unsat...
BasicCdcl<> Cdcl
the clause learning on std::priority_queue
Definition SatSolvers.h:274
Definition ADT.h:96
std::vector< Clause > Cnf
a formula
Definition Problems.h:85