Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
ClauseDatabaseMallob.hpp
1#pragma once
2
3#include "containers/ClauseBuffer.hpp"
4#include "containers/ClauseDatabase.hpp"
5#include <atomic>
6#include <shared_mutex>
7#include <unordered_map>
8#include <vector>
9
10#define MIN_LBD 2
11#define UNIT_SIZE 1
12
33{
34 public:
35 ClauseDatabaseMallob() = delete;
36
47 explicit ClauseDatabaseMallob(int maxClauseSize, int maxPartitioningLbd, size_t maxCapacity, int maxFreeSize);
48
53
64 bool addClause(ClauseExchangePtr clause) override;
65
76 size_t giveSelection(std::vector<ClauseExchangePtr>& selectedCls, unsigned int literalCountLimit) override;
77
83 void getClauses(std::vector<ClauseExchangePtr>& v_cls) override;
84
93 bool getOneClause(ClauseExchangePtr& cls) override;
94
100 size_t getSize() const override;
101
111 size_t shrinkDatabase() override;
112
116 void clearDatabase() override;
117
118 protected:
143 inline unsigned getIndex(int size, int lbd) const
144 {
145 if (size < UNIT_SIZE || lbd < MIN_LBD)
146 throw std::invalid_argument("size is less than 1 or lbd is less than 2");
147 return (size - 1) * m_maxPartitioningLbd + std::min(lbd - MIN_LBD, m_maxPartitioningLbd - 1);
148 }
149
156 inline int getSizeFromIndex(unsigned index) const { return (index == 0) ? 1 : (index / m_maxPartitioningLbd) + 1; }
157
164 inline int getLbdPartitionFromIndex(unsigned index) const { return (index % m_maxPartitioningLbd) + MIN_LBD; }
165
168 const int m_maxClauseSize;
169 const int m_freeMaxSize;
170
171 std::vector<std::unique_ptr<ClauseBuffer>> m_clauses;
172 std::atomic<long> m_currentLiteralSize;
173 std::atomic<int> m_currentWorstIndex;
174 mutable std::shared_mutex m_shrinkMutex;
175 ClauseBuffer m_missedAdditionsBfr;
176};
Wrapper for boost::lockfree::queue to manage ClauseExchange objects.
Definition ClauseBuffer.hpp:26
A clause database implementation attempting to naively mimic the Simplified Adaptive Database from Ma...
Definition ClauseDatabaseMallob.hpp:33
size_t getSize() const override
Gets the total number of clauses in the database.
size_t shrinkDatabase() override
Shrinks the database by removing clauses to maintain the size within capacity.
void getClauses(std::vector< ClauseExchangePtr > &v_cls) override
Fills a buffer with all clauses in the database.
int getLbdPartitionFromIndex(unsigned index) const
Calculates the LBD partition from an index.
Definition ClauseDatabaseMallob.hpp:164
std::shared_mutex m_shrinkMutex
Mutex used to coordinate shrinking and clause addition.
Definition ClauseDatabaseMallob.hpp:174
~ClauseDatabaseMallob() override
Virtual destructor.
const int m_maxPartitioningLbd
Maximum LBD value for separate partitioning.
Definition ClauseDatabaseMallob.hpp:167
bool addClause(ClauseExchangePtr clause) override
Adds a clause to the database.
unsigned getIndex(int size, int lbd) const
Calculates the index for a clause based on its size and LBD.
Definition ClauseDatabaseMallob.hpp:143
int getSizeFromIndex(unsigned index) const
Calculates the size of a clause from its index.
Definition ClauseDatabaseMallob.hpp:156
std::vector< std::unique_ptr< ClauseBuffer > > m_clauses
Vector of clause buffers, indexed by size and LBD.
Definition ClauseDatabaseMallob.hpp:171
const size_t m_totalLiteralCapacity
Maximum total literal capacity of the database.
Definition ClauseDatabaseMallob.hpp:166
const int m_maxClauseSize
Maximum size of clauses to be stored.
Definition ClauseDatabaseMallob.hpp:168
bool getOneClause(ClauseExchangePtr &cls) override
Retrieves a single clause from the best (smallest index) buffer possible.
const int m_freeMaxSize
Maximum size for which giveSelection does not count in while filling exportBuffer.
Definition ClauseDatabaseMallob.hpp:169
ClauseDatabaseMallob(int maxClauseSize, int maxPartitioningLbd, size_t maxCapacity, int maxFreeSize)
Constructs a new ClauseDatabaseMallob object.
size_t giveSelection(std::vector< ClauseExchangePtr > &selectedCls, unsigned int literalCountLimit) override
Fills a buffer with selected clauses up to a given size limit.
std::atomic< long > m_currentLiteralSize
Current number of literals in the database (excluding unit clauses).
Definition ClauseDatabaseMallob.hpp:172
std::atomic< int > m_currentWorstIndex
Index of the current worst clause in the database.
Definition ClauseDatabaseMallob.hpp:173
void clearDatabase() override
Clears all clauses from the database and resets internal counters.
Abstract base class defining the interface for clause storage and management.
Definition ClauseDatabase.hpp:27