Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
ClauseDatabaseSingleBuffer.hpp
1#pragma once
2
3#include "containers/ClauseBuffer.hpp"
4#include "containers/ClauseDatabase.hpp"
5#include <algorithm>
6#include <random>
7
19{
20 private:
22 ClauseBuffer buffer;
23
24 public:
29
30 ClauseDatabaseSingleBuffer(size_t bufferSize)
31 : buffer(bufferSize)
32 {
33 }
34
38 ~ClauseDatabaseSingleBuffer() override = default;
39
45 bool addClause(ClauseExchangePtr clause) override { return buffer.addClause(std::move(clause)); }
46
56 size_t giveSelection(std::vector<ClauseExchangePtr>& selectedCls, unsigned int literalCountLimit) override
57 {
58 size_t selectedLiterals = 0;
59 ClauseExchangePtr clause;
60
61 while (buffer.getClause(clause)) {
62 if (selectedLiterals + clause->size <= literalCountLimit) {
63 selectedCls.push_back(clause);
64 selectedLiterals += clause->size;
65 } else {
66 // If this clause would exceed the limit, put it back and stop
67 buffer.addClause(clause);
68 break;
69 }
70 }
71
72 return selectedLiterals;
73 }
74
79 void getClauses(std::vector<ClauseExchangePtr>& v_cls) override { buffer.getClauses(v_cls); }
80
86 bool getOneClause(ClauseExchangePtr& cls) override { return buffer.getClause(cls); }
87
92 size_t getSize() const override { return buffer.size(); }
93
102 size_t shrinkDatabase() override
103 {
104 LOGDEBUG3("This does nothing!");
105 return (size_t)-1;
106 };
107
111 void clearDatabase() override { buffer.clear(); }
112};
#define LOGDEBUG3(...)
Log a debug message with verbosity level 4 and magenta color.
Definition Logger.hpp:229
Wrapper for boost::lockfree::queue to manage ClauseExchange objects.
Definition ClauseBuffer.hpp:26
void getClauses(std::vector< ClauseExchangePtr > &clauses)
Retrieves all available clauses from the buffer.
Definition ClauseBuffer.hpp:174
bool addClause(ClauseExchangePtr clause)
Adds a single clause to the buffer.
Definition ClauseBuffer.hpp:82
size_t size() const
Returns the current number of clauses in the buffer.
Definition ClauseBuffer.hpp:187
void clear()
Clears all clauses from the buffer.
Definition ClauseBuffer.hpp:192
bool getClause(ClauseExchangePtr &clause)
Retrieves a single clause from the buffer.
Definition ClauseBuffer.hpp:158
This is just a ClauseDatabase wrapper around a ClauseBuufer.
Definition ClauseDatabaseSingleBuffer.hpp:19
bool addClause(ClauseExchangePtr clause) override
Adds a clause to the database.
Definition ClauseDatabaseSingleBuffer.hpp:45
size_t getSize() const override
Returns the current number of clauses in the database.
Definition ClauseDatabaseSingleBuffer.hpp:92
bool getOneClause(ClauseExchangePtr &cls) override
Retrieves a single clause from the database.
Definition ClauseDatabaseSingleBuffer.hpp:86
ClauseDatabaseSingleBuffer()=delete
Default Constructor deleted to enforce parameterized constructor.
~ClauseDatabaseSingleBuffer() override=default
Virtual destructor.
size_t shrinkDatabase() override
Shrinks the database by clearing all clauses.
Definition ClauseDatabaseSingleBuffer.hpp:102
void clearDatabase() override
Clears all clauses from the database.
Definition ClauseDatabaseSingleBuffer.hpp:111
void getClauses(std::vector< ClauseExchangePtr > &v_cls) override
Retrieves all clauses from the database.
Definition ClauseDatabaseSingleBuffer.hpp:79
size_t giveSelection(std::vector< ClauseExchangePtr > &selectedCls, unsigned int literalCountLimit) override
Selects clauses up to the specified total size.
Definition ClauseDatabaseSingleBuffer.hpp:56
Abstract base class defining the interface for clause storage and management.
Definition ClauseDatabase.hpp:27