Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
Kissat.hpp
1#pragma once
2
3#include "containers/ClauseBuffer.hpp"
4#include "containers/ClauseDatabase.hpp"
5#include "containers/ClauseUtils.hpp"
6#include "utils/Threading.hpp"
7#include <fstream>
8#include <iostream>
9#include <unordered_map>
10
11#include "KissatFamily.hpp"
12#include "SolverCdclInterface.hpp"
13
14#define KISSAT_
15
16// Kissat includes
17extern "C"
18{
19#include "kissat/src/kissat.h"
20}
21
25{
26 public:
28 Kissat(int id, const std::shared_ptr<ClauseDatabase>& clauseDB);
29
31 virtual ~Kissat();
32
33 /* Execution */
34
36 SatResult solve(const std::vector<int>& cube) override;
37
39 void setSolverInterrupt() override;
40
42 void unsetSolverInterrupt() override;
43
46
48 void diversify(const SeedGenerator& getSeed) override;
49
50 /* Clause Management */
51
53 void loadFormula(const char* filename) override;
54
56 void addInitialClauses(const std::vector<simpleClause>& clauses, unsigned int nbVars) override;
57
59 void addClause(ClauseExchangePtr clause) override;
60
62 void addClauses(const std::vector<ClauseExchangePtr>& clauses) override;
63
64 /* Sharing */
65
67 bool importClause(const ClauseExchangePtr& clause) override;
68
70 void importClauses(const std::vector<ClauseExchangePtr>& clauses) override;
71
72 /* Variable Management */
73
75 unsigned int getVariablesCount() override;
76
78 int getDivisionVariable() override;
79
81 void setPhase(const unsigned int var, const bool phase) override;
82
84 void bumpVariableActivity(const int var, const int times) override;
85
86 /* Statistics And More */
87
89 void printStatistics() override;
90
91 void printWinningLog() override;
92
93 std::vector<int> getFinalAnalysis() override;
94
95 std::vector<int> getSatAssumptions() override;
96
98 std::vector<int> getModel() override;
99
101 std::unordered_map<std::string, int> kissatOptions;
102
104 void setFamily(KissatFamily family) { this->family = family; };
105
106
107 protected:
110
111 protected:
113 kissat* solver;
114
117
119 std::atomic<bool> stopSolver;
120
121 KissatFamily family;
122
123 unsigned int originalVars;
124
126 friend int kissatTerminate(void* solverPtr);
127
129 /* Decided to not use pointers to move because of c++ stl (cannot move an array into a vector, sharedPtr
130 * destruction) */
131 friend char kissatImportClause(void*, kissat*);
132 friend char kissatExportClause(void*, kissat*);
133};
Wrapper for boost::lockfree::queue to manage ClauseExchange objects.
Definition ClauseBuffer.hpp:26
Instance of a Kissat solver.
Definition Kissat.hpp:25
std::vector< int > getModel() override
Return the model in case of SAT result.
ClauseBuffer clausesToAdd
Buffer used to add permanent clauses.
Definition Kissat.hpp:116
void bumpVariableActivity(const int var, const int times) override
Bump activity of a given variable.
std::unordered_map< std::string, int > kissatOptions
A map mapping a kissat option name to its value.
Definition Kissat.hpp:101
kissat * solver
Pointer to a Kissat solver.
Definition Kissat.hpp:113
void diversify(const SeedGenerator &getSeed) override
Native diversification.
void printWinningLog() override
Print the winning log.
std::atomic< bool > stopSolver
Used to stop or continue the resolution.
Definition Kissat.hpp:119
void addInitialClauses(const std::vector< simpleClause > &clauses, unsigned int nbVars) override
Add a list of initial clauses to the formula.
Kissat(int id, const std::shared_ptr< ClauseDatabase > &clauseDB)
Constructor.
void initKissatOptions()
Initializes the map KissatOptions with the default configuration.
bool importClause(const ClauseExchangePtr &clause) override
Add a learned clause to the formula.
void importClauses(const std::vector< ClauseExchangePtr > &clauses) override
Add a list of learned clauses to the formula.
int getDivisionVariable() override
Get a variable suitable for search splitting.
void computeFamily()
Compute kissat family for diversification.
void unsetSolverInterrupt() override
Remove the SAT solving interrupt request.
friend int kissatTerminate(void *solverPtr)
Termination callback.
std::vector< int > getSatAssumptions() override
Get current assumptions.
std::vector< int > getFinalAnalysis() override
Get the final analysis in case of UNSAT result.
virtual ~Kissat()
Destructor.
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.
void printStatistics() override
Get solver statistics.
friend char kissatImportClause(void *, kissat *)
Callback to export/import clauses used by real kissat.
void loadFormula(const char *filename) override
Load formula from a given dimacs file, return false if failed.
void addClause(ClauseExchangePtr clause) override
Add a permanent clause to the formula.
unsigned int getVariablesCount() override
Get the number of variables of the current resolution.
void setFamily(KissatFamily family)
Set family from working strategy.
Definition Kissat.hpp:104
void setSolverInterrupt() override
Interrupt resolution, solving cannot continue until interrupt is unset.
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