6#include <Eigen/SparseCore>
8#include "preprocessors/PreprocessorInterface.hpp"
17 unsigned int occurencesCount;
47 : func(decreasingOrder)
51 bool operator()(
const queuePair& lhs,
const queuePair& rhs)
const {
return func(lhs, rhs); }
59#define REAL_LIT_COUNT(LIT) \
60 ((unsigned int)this->litToClause[LIT_IDX(LIT)].size() + this->litCountAdjustement[LIT_IDX(LIT)])
63#define MATRIX_VAR_TO_IDX(LIT) (LIT - 1)
64#define MATRIX_LIT_TO_IDX(LIT) (LIT > 0 ? LIT - 1 : -LIT - 1)
65#define MATRIX_IDX_TO_VAR(IDX) (IDX + 1)
68enum class SBVATieBreak
80 std::vector<int> lits;
97 StructuredBVA(
int _id,
unsigned long maxReplacements,
bool shuffleTies);
110 void addInitialClauses(
const std::vector<simpleClause>& clauses,
unsigned int nbVariables)
override;
120 return { (uint)this->clauses.size() - this->adjacencyDeleted, this->adjacencyDeleted, 0, this->replacementsCount, 0 };
127 void addClauses(
const std::vector<ClauseExchangePtr>& clauses) {
return; }
135 void updateAdjacencyMatrix(
int var);
137 unsigned int getThreeHopHeuristic(
int lit1,
int lit2);
140 int leastFrequentLiteral(simpleClause& clause,
int lit);
142 void setTieBreakHeuristic(SBVATieBreak tieBreak);
146 this->tempTieHeuristicCache.clear();
147 this->litCountAdjustement.clear();
148 this->adjacencyMatrix.clear();
149 this->isClauseDeleted.clear();
150 this->litToClause.clear();
151 this->clauses.clear();
154 this->litCountAdjustement.shrink_to_fit();
155 this->adjacencyMatrix.shrink_to_fit();
156 this->isClauseDeleted.shrink_to_fit();
157 this->litToClause.shrink_to_fit();
158 this->clauses.shrink_to_fit();
159 this->proof.shrink_to_fit();
166 void restoreModel(std::vector<int>& model)
override { model.resize(this->varCount - this->replacementsCount); }
169 inline int threeHopTieBreak(
const std::vector<int>& ties,
const int currentLit)
173 unsigned int maxHeuristicVal = 0;
174 for (
int tie : ties) {
175 unsigned int temp = this->getThreeHopHeuristic(currentLit, tie);
176 if (temp > maxHeuristicVal) {
177 maxHeuristicVal = temp;
184 inline int mostOccurTieBreak(
const std::vector<int>& ties,
const int currentLit)
188 unsigned int maxHeuristicVal = 0;
189 for (
int tie : ties) {
190 unsigned int temp = REAL_LIT_COUNT(tie);
191 if (temp > maxHeuristicVal) {
192 maxHeuristicVal = temp;
199 inline int leastOccurTieBreak(
const std::vector<int>& ties,
const int currentLit)
203 unsigned int maxHeuristicVal = UINT32_MAX;
204 for (
int tie : ties) {
205 unsigned int temp = REAL_LIT_COUNT(tie);
206 if (temp < maxHeuristicVal) {
207 maxHeuristicVal = temp;
214 inline int randomTieBreak(
const std::vector<int>& ties,
const int currentLit)
216 std::srand(currentLit);
217 return ties[std::rand() % ties.size()];
222 LOGWARN(
"BVA cannot solve a formula");
227 void printParameters();
230 std::atomic<bool> stopPreprocessing;
233 std::vector<simpleClause> clauses;
236 std::vector<bool> isClauseDeleted;
239 std::vector<std::vector<unsigned int>> litToClause;
242 std::vector<int> litCountAdjustement;
245 unsigned int adjacencyMatrixWidth;
248 std::vector<Eigen::SparseVector<int>> adjacencyMatrix;
251 std::map<int, int> tempTieHeuristicCache;
254 std::vector<ProofClause> proof;
260 bool preserveModelCount;
266 SBVATieBreak tieBreakHeuristic;
268 unsigned int maxReplacements;
270 std::function<int(
const std::vector<int>&,
const int)> breakTie;
274 unsigned int varCount;
276 unsigned int adjacencyDeleted;
278 unsigned int replacementsCount;
280 unsigned int originalClauseCount;
297 SBVAInit(std::vector<std::vector<unsigned int>>& litToClause, std::vector<bool>& isClauseDeleted)
298 : m_litToClause(litToClause)
299 , m_isClauseDeleted(isClauseDeleted)
303 bool initMembers(
unsigned int varCount,
unsigned int clauseCount);
307 std::vector<std::vector<unsigned int>>& m_litToClause;
308 std::vector<bool>& m_isClauseDeleted;
#define LOGWARN(...)
Log a warning message.
Definition Logger.hpp:137
Defines classes and functions for parsing CNF formulas and processing clauses.
Abstract base class for clause processors.
Definition Parsers.hpp:27
A filter for Structured BVA (Binary Variable Addition)
Definition StructuredBva.hpp:295
bool operator()(simpleClause &clause) override
Process a clause.
bool initMembers(unsigned int varCount, unsigned int clauseCount)
Initialize the processor with problem parameters.
Interface for preprocessor algorithms in SAT solving.
Definition PreprocessorInterface.hpp:40
Interface for a SAT solver with standard features.
Definition SolverInterface.hpp:62
unsigned int getSolverId()
Get the solver ID.
Definition SolverInterface.hpp:178
Structured Binary Variable Addition (SBVA) preprocessing algorithm.
Definition StructuredBva.hpp:94
void restoreModel(std::vector< int > &model) override
Restore the model by removing added clauses.
Definition StructuredBva.hpp:166
void addClause(ClauseExchangePtr clause)
Add a permanent clause to the formula.
Definition StructuredBva.hpp:125
int getDivisionVariable()
Get a variable suitable for search splitting.
Definition StructuredBva.hpp:123
void unsetSolverInterrupt() override
Remove the SAT solving interrupt request.
SatResult solve(const std::vector< int > &cube={}) override
Solve the formula with a given cube.
unsigned int getVariablesCount() override
Get the current number of variables.
void addClauses(const std::vector< ClauseExchangePtr > &clauses)
Add a list of permanent clauses to the formula.
Definition StructuredBva.hpp:127
void releaseMemory()
Release memory used by the preprocessor.
Definition StructuredBva.hpp:144
void addInitialClauses(const std::vector< simpleClause > &clauses, unsigned int nbVariables) override
Add a list of initial clauses to the formula.
void diversify(const SeedGenerator &getSeed=[](SolverInterface *s) { return s->getSolverId();})
Diversify the preprocessor's behavior.
PreprocessorStats getPreprocessorStatistics()
Get statistics about the preprocessing.
Definition StructuredBva.hpp:118
StructuredBVA(int _id, unsigned long maxReplacements, bool shuffleTies)
Constructor.
void setSolverInterrupt() override
Interrupt resolution, solving cannot continue until interrupt is unset.
std::vector< int > getModel() override
Return the model in case of SAT result.
Definition StructuredBva.hpp:220
void printStatistics() override
Print solver statistics.
void loadFormula(const char *filename) override
Load formula from a given dimacs file.
std::vector< simpleClause > getSimplifiedFormula() override
Get the simplified formula after preprocessing.
~StructuredBVA()
Destructor.
SatResult
Enumeration for SAT solver results.
Definition SolverInterface.hpp:39
A set of helper functions for CNF file parsing.
Definition StructuredBva.hpp:286
Functor for the priority queue used in solve()
Definition StructuredBva.hpp:38
Preperocessing technique statistics.
Definition PreprocessorInterface.hpp:14
Definition StructuredBva.hpp:79
queuePair struct used for the priorityQueue in solve
Definition StructuredBva.hpp:15