-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathBufferedSolver.hpp
120 lines (95 loc) · 3.38 KB
/
BufferedSolver.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* This file is part of the source code of the software program
* Vampire. It is protected by applicable
* copyright laws.
*
* This source code is distributed under the licence found here
* https://vprover.github.io/license.html
* and in the source directory
*/
/**
* @file BufferedSolver.hpp
* Defines class BufferedSolver.
*
* The idea is to buffer clauses that are true, or can be made true, by the ground model
*
* @author Giles
*/
#ifndef __BufferedSolver__
#define __BufferedSolver__
#include "Forwards.hpp"
#include "Lib/DArray.hpp"
#include "Lib/DHMap.hpp"
#include "Lib/DHSet.hpp"
#include "Lib/ScopedPtr.hpp"
#include "Lib/Stack.hpp"
#include "SATSolver.hpp"
namespace SAT {
using namespace Lib;
class BufferedSolver : public SATSolver {
public:
BufferedSolver(SATSolver* inner);
virtual SATClause* getRefutation() override { return _inner->getRefutation(); }
virtual SATClauseList* getRefutationPremiseList() override {
return _inner->getRefutationPremiseList();
}
virtual void randomizeForNextAssignment(unsigned maxVar) override {
_inner->randomizeForNextAssignment(maxVar);
// This is not ideal, but we can't wait till solve, because
// BufferedSolver would not be forced to consult inner if it already "has an assignment in mind"
flushUnadded();
_lastStatus = _inner->solve();
}
virtual void addClause(SATClause* cl) override;
virtual Status solve(unsigned conflictCountLimit) override;
virtual VarAssignment getAssignment(unsigned var) override;
virtual bool isZeroImplied(unsigned var) override {
ASS_G(var,0); ASS_LE(var,_varCnt);
// alternatively, we could directly refer to _inner, it must handle variables up to _varCnt as well
return (var > _varCntInnerOld) ? false : _inner->isZeroImplied(var);
}
virtual void collectZeroImplied(SATLiteralStack& acc) override { _inner->collectZeroImplied(acc); }
virtual SATClause* getZeroImpliedCertificate(unsigned var) override { return _inner->getZeroImpliedCertificate(var); }
virtual void ensureVarCount(unsigned newVarCnt) override { _inner->ensureVarCount(newVarCnt); _varCnt=std::max(_varCnt,newVarCnt); }
virtual unsigned newVar() override {
ALWAYS(_inner->newVar() == ++_varCnt);
return _varCnt;
}
virtual void suggestPolarity(unsigned var,unsigned pol) override { _inner->suggestPolarity(var,pol); }
private:
// check if @cl is implied by current model, and record it
// if we choose not to add it at this point
bool checkAndRecordImplied(SATClause* cl);
// Add any clauses that have been buffered to _inner and solve.
void flushUnadded();
ScopedPtr<SATSolver> _inner;
/**
* A buffer for new literals that do not yet appear in the solver
*/
DHMap<unsigned, bool> _literalBuffer;
/**
* Clauses that have not been added to _inner as they are either implied by the assignment of _inner
* or the variables implicitly set in _literalBuffer
*/
SATClauseStack _unadded;
/**
* Index (to _unadded) of the least clause not yet checked wrt the current model.
*/
unsigned _checkedIdx;
/**
* Remember the last status returned by solve.
*/
Status _lastStatus;
/**
* Our current varCnt and (of _inner as well).
*/
unsigned _varCnt;
/**
* varCnt of _inner at the time of the last flush.
*
* Variables larger than this are handled by Buffered
*/
unsigned _varCntInnerOld;
};
}
#endif // __BufferedSolver__