Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
Cadical.hpp
1#pragma once
2
3#include "containers/ClauseBuffer.hpp"
4#include "containers/ClauseUtils.hpp"
5
6#include "utils/Threading.hpp"
7
8#include <fstream>
9#include <iostream>
10#include <unordered_map>
11
12#include "SolverCdclInterface.hpp"
13
14#define CADICAL_
15
16// Cadical includes
17#include "cadical/src/cadical.hpp"
18
19/*---------------------Main Class----------------------*/
20
26 : public SolverCdclInterface
27 , public CaDiCaL::Learner
28 , public CaDiCaL::Terminator
29{
30 public:
32 Cadical(int id, const std::shared_ptr<ClauseDatabase>& clauseDB);
33
35 virtual ~Cadical();
36
37 /* Execution */
38
40 SatResult solve(const std::vector<int>& cube) override;
41
43 void setSolverInterrupt() override;
44
46 void unsetSolverInterrupt() override;
47
50
52 void diversify(const SeedGenerator& getSeed) override;
53
54 /* Clause Management */
55
57 void loadFormula(const char* filename) override;
58
60 void addInitialClauses(const std::vector<simpleClause>& clauses, unsigned int nbVars) override;
61
63 void addClause(ClauseExchangePtr clause) override;
64
66 void addClauses(const std::vector<ClauseExchangePtr>& clauses) override;
67
68 // /// Set clauseToImport Database
69 // void setClausesToImportDatabase(std::unique_ptr<ClauseDatabase>&& db) { this->clausesToImport = std::move(db); }
70
71 /* Sharing */
72
74 bool importClause(const ClauseExchangePtr& clause) override;
75
77 void importClauses(const std::vector<ClauseExchangePtr>& clauses) override;
78
79 /* Variable Management */
80
82 unsigned int getVariablesCount() override;
83
85 int getDivisionVariable() override;
86
88 void setPhase(const unsigned int var, const bool phase) override;
89
91 void bumpVariableActivity(const int var, const int times) override;
92
93 /* Statistics And More */
94
96 void printStatistics() override;
97
98 void printWinningLog() override;
99
100 std::vector<int> getFinalAnalysis() override;
101
102 std::vector<int> getSatAssumptions() override;
103
105 std::vector<int> getModel() override;
106
108 std::unordered_map<std::string, int> cadicalOptions;
109
110 protected:
112 std::unique_ptr<CaDiCaL::Solver> solver;
113
116
118 std::atomic<bool> stopSolver;
119
120 /*----------------------Learner------------------------*/
122 public:
123 /* Export */
128 bool learning(int size, int glue) override;
129
134 void learn(int lit) override;
135
136 /* Import */
141 bool hasClauseToImport() override;
142
148 void getClauseToImport(std::vector<int>& clause, int& glue) override;
149
150 private:
152 simpleClause tempClause;
153
155 int lbd;
156
158 ClauseExchangePtr tempClauseToImport;
159
160 /*-----------------------Terminator----------------------*/
165 bool terminate() { return this->stopSolver; }
166};
Implements the different interfaces to interact with the Cadical CDCL solver.
Definition Cadical.hpp:29
ClauseBuffer clausesToAdd
Buffer used to add permanent clauses.
Definition Cadical.hpp:115
void setSolverInterrupt() override
Interrupt resolution, solving cannot continue until interrupt is unset.
std::unique_ptr< CaDiCaL::Solver > solver
Pointer to a Cadical solver.
Definition Cadical.hpp:112
bool importClause(const ClauseExchangePtr &clause) override
Add a learned clause to the formula.
std::atomic< bool > stopSolver
Used to stop or continue the resolution.
Definition Cadical.hpp:118
void initCadicalOptions()
Initializes the map CadicalOptions with the default configuration.
void addClause(ClauseExchangePtr clause) override
Add a permanent clause to the formula.
void printWinningLog() override
Print the winning log.
int getDivisionVariable() override
Get a variable suitable for search splitting.
void addInitialClauses(const std::vector< simpleClause > &clauses, unsigned int nbVars) override
Add a list of initial clauses to the formula.
void diversify(const SeedGenerator &getSeed) override
Native diversification.
void unsetSolverInterrupt() override
Remove the SAT solving interrupt request.
SatResult solve(const std::vector< int > &cube) override
Solve the formula with a given cube.
void addClauses(const std::vector< ClauseExchangePtr > &clauses) override
Add a list of permanent clauses to the formula.
void setPhase(const unsigned int var, const bool phase) override
Set initial phase for a given variable.
unsigned int getVariablesCount() override
Get the number of variables of the current resolution.
void getClauseToImport(std::vector< int > &clause, int &glue) override
Loads the clause to import data in the parameters.
Cadical(int id, const std::shared_ptr< ClauseDatabase > &clauseDB)
Constructor.
virtual ~Cadical()
Destructor.
bool learning(int size, int glue) override
Tells if CaDiCaL should export a clause.
std::vector< int > getSatAssumptions() override
Get current assumptions.
void bumpVariableActivity(const int var, const int times) override
Bump activity of a given variable.
std::vector< int > getFinalAnalysis() override
Get the final analysis in case of UNSAT result.
std::unordered_map< std::string, int > cadicalOptions
A map mapping a Cadical option name to its value.
Definition Cadical.hpp:108
void importClauses(const std::vector< ClauseExchangePtr > &clauses) override
Add a list of learned clauses to the formula.
void learn(int lit) override
Used by the base solver to export a clause.
void printStatistics() override
Get solver statistics.
void loadFormula(const char *filename) override
Load formula from a given dimacs file, return false if failed.
std::vector< int > getModel() override
Return the model in case of SAT result.
bool hasClauseToImport() override
Tells if CaDiCaL has a clause to import.
Wrapper for boost::lockfree::queue to manage ClauseExchange objects.
Definition ClauseBuffer.hpp:26
Interface for CDCL (Conflict-Driven Clause Learning) solvers This class provides a common interface f...
Definition SolverCdclInterface.hpp:58
SatResult
Enumeration for SAT solver results.
Definition SolverInterface.hpp:39