Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
Formula.hpp
1
2#include "vector2D.hpp"
3#include <unordered_set>
4
5using namespace painless;
6
7// Macros for literal representation conversion
8#define PLIT_IDX(LIT) (LIT * 2 - 2)
9#define NLIT_IDX(LIT) (-LIT * 2 - 1)
10#define LIT_IDX(LIT) (LIT > 0 ? PLIT_IDX(LIT) : NLIT_IDX(LIT))
11#define IDX_LIT(IDX) (((IDX)&1) ? -(((IDX) + 1) >> 1) : (((IDX) >> 1) + 1))
12
20{
21 public:
27 bool push_clause(const std::vector<int>& clause);
28
34 bool emplace_clause(std::initializer_list<int> clause);
35
41 bool insert_unit(int lit);
42
47 void delete_nonUnit(unsigned int index);
48
55 bool delete_lit_nonUnit(unsigned int index, int lit);
56
63 bool delete_nonUnit_occurence(int lit, unsigned int index);
64
69 void delete_unit(int lit) { units.erase(lit); }
70
75 void setVarCount(unsigned int varCount) { this->varCount = varCount; }
76
81 unsigned int getVarCount() { return this->varCount; }
82
88 skipzero_span<const int> getNonUnit(unsigned int i) const { return nonUnits[i]; }
89
95 unsigned int getNonUnitEfficientSize(unsigned int i) const { return nonUnits.getRowSize(i); }
96
101 const std::unordered_set<int>& getUnits() const { return this->units; }
102
107 std::unordered_set<int>& getUnits() { return this->units; }
108
115 {
116 return skipzero_span<unsigned int>(this->occurenceLists.at(LIT_IDX(lit)));
117 }
118
123 unsigned int getUnitCount() { return this->units.size(); }
124
129 unsigned int getNonUnitsCount() { return this->nonUnits.getRowsCount() - this->deletedClausesCount; }
130
135 unsigned int getAllClauseCount() { return this->getUnitCount() + this->getNonUnitsCount(); }
136
141
142 private:
143 std::unordered_set<int> units;
144 vector2D<int> nonUnits;
145 std::vector<std::vector<unsigned int>> occurenceLists;
146 unsigned int varCount = 0;
147 unsigned int deletedClausesCount = 0;
148};
Represents a SAT formula with unit and non-unit clauses.
Definition Formula.hpp:20
skipzero_span< unsigned int > getOccurenceList(int lit)
Gets the occurrence list of a literal.
Definition Formula.hpp:114
void delete_unit(int lit)
Deletes a unit clause from the formula.
Definition Formula.hpp:69
std::unordered_set< int > & getUnits()
Gets a modifiable reference to the set of unit clauses.
Definition Formula.hpp:107
unsigned int getNonUnitsCount()
Gets the number of non-unit clauses in the formula.
Definition Formula.hpp:129
void setVarCount(unsigned int varCount)
Sets the number of variables in the formula.
Definition Formula.hpp:75
unsigned int getVarCount()
Gets the number of variables in the formula.
Definition Formula.hpp:81
bool push_clause(const std::vector< int > &clause)
Adds a new clause to the formula.
skipzero_span< const int > getNonUnit(unsigned int i) const
Gets a non-unit clause from the formula.
Definition Formula.hpp:88
bool delete_nonUnit_occurence(int lit, unsigned int index)
Deletes a clause occurrence from a literal's occurrence list.
void delete_nonUnit(unsigned int index)
Deletes a non-unit clause from the formula.
bool emplace_clause(std::initializer_list< int > clause)
Adds a new clause to the formula using an initializer list.
void shrink_structures()
Shrinks the internal data structures to save memory.
unsigned int getAllClauseCount()
Gets the total number of clauses (unit and non-unit) in the formula.
Definition Formula.hpp:135
unsigned int getNonUnitEfficientSize(unsigned int i) const
Gets the number of non-zero literals in a non-unit clause.
Definition Formula.hpp:95
bool insert_unit(int lit)
Inserts a unit clause into the formula.
bool delete_lit_nonUnit(unsigned int index, int lit)
Deletes a literal from a non-unit clause.
const std::unordered_set< int > & getUnits() const
Gets the set of unit clauses.
Definition Formula.hpp:101
unsigned int getUnitCount()
Gets the number of unit clauses in the formula.
Definition Formula.hpp:123
A span-like container that skips zero elements when iterating.
Definition vector2D.hpp:27
A 2D vector implementation optimized for sparse data.
Definition vector2D.hpp:175
row_size_t getRowsCount() const
Gets the number of rows in the 2D vector.
Definition vector2D.hpp:232
row_size_t getRowSize(row_id_t id) const
Gets the size of a specific row.
Definition vector2D.hpp:329