Skip to content

Commit 5d64244

Browse files
committed
Added counters of already preprocessed assertions and possibly skipping those
1 parent fcbdc29 commit 5d64244

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/api/MainSolver.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <tsolvers/RDLTHandler.h>
2424
#include <unsatcores/UnsatCoreBuilder.h>
2525

26+
#include <type_traits>
27+
2628
namespace opensmt {
2729

2830
MainSolver::MainSolver(Logic & logic, SMTConfig & conf, std::string name)
@@ -60,6 +62,7 @@ void MainSolver::initialize() {
6062
frames.push();
6163
frameTerms.push(logic.getTerm_true());
6264
preprocessor.initialize();
65+
preprocessedAssertionsCountPerFrame.push_back(0);
6366
smt_solver->initialize();
6467
pair<CRef, CRef> iorefs{CRef_Undef, CRef_Undef};
6568
smt_solver->addOriginalSMTClause({term_mapper->getOrCreateLit(logic.getTerm_true())}, iorefs);
@@ -74,6 +77,7 @@ void MainSolver::push() {
7477
frames.push();
7578
preprocessor.push();
7679
frameTerms.push(newFrameTerm(frames.last().getId()));
80+
preprocessedAssertionsCountPerFrame.push_back(0);
7781
termNames.pushScope();
7882
if (alreadyUnsat) { rememberLastFrameUnsat(); }
7983
}
@@ -92,7 +96,9 @@ bool MainSolver::pop() {
9296
}
9397
frames.pop();
9498
preprocessor.pop();
99+
preprocessedAssertionsCountPerFrame.pop_back();
95100
termNames.popScope();
101+
// goes back to frames.frameCount()-1 only if a formula is added via addAssertion
96102
firstNotPreprocessedFrame = std::min(firstNotPreprocessedFrame, frames.frameCount());
97103
if (not isLastFrameUnsat()) { getSMTSolver().restoreOK(); }
98104
return true;
@@ -158,9 +164,14 @@ sstat MainSolver::simplifyFormulas() {
158164
bool MainSolver::tryPreprocessFormulasOfFrame(std::size_t i) {
159165
auto & frame = frames[i];
160166
FrameId const frameId = frame.getId();
161-
PreprocessingContext context{.frameCount = i, .perPartition = trackPartitions()};
167+
auto & preprocessedFrameAssertionsCount = preprocessedAssertionsCountPerFrame[i];
168+
assert(frame.formulas.size() == 0 or std::size_t(frame.formulas.size()) > preprocessedFrameAssertionsCount);
169+
PreprocessingContext context{.frameCount = i,
170+
.preprocessedFrameAssertionsCount = preprocessedFrameAssertionsCount,
171+
.perPartition = trackPartitions()};
162172
preprocessor.prepareForProcessingFrame(i);
163173
firstNotPreprocessedFrame = i + 1;
174+
preprocessedFrameAssertionsCount = frame.formulas.size();
164175

165176
assert(status != s_False);
166177

@@ -185,6 +196,7 @@ PTRef MainSolver::preprocessFormulasDefault(vec<PTRef> const & frameFormulas, Pr
185196

186197
if (frameFormulas.size() == 0) { return logic.getTerm_true(); }
187198

199+
// Include even already preprocessed formulas which can still benefit from the new ones
188200
PTRef frameFormula = logic.mkAnd(frameFormulas);
189201
return preprocessFormula(frameFormula, context);
190202
}
@@ -193,16 +205,21 @@ vec<PTRef> MainSolver::preprocessFormulasPerPartition(vec<PTRef> const & frameFo
193205
PreprocessingContext const & context) {
194206
assert(context.perPartition);
195207

196-
if (frameFormulas.size() == 0) { return {}; }
208+
std::size_t const frameFormulasCount = frameFormulas.size();
209+
static_assert(std::is_unsigned_v<decltype(context.preprocessedFrameAssertionsCount)>);
210+
assert(context.preprocessedFrameAssertionsCount <= frameFormulasCount);
211+
std::size_t const formulasCountToProcess = frameFormulasCount - context.preprocessedFrameAssertionsCount;
212+
if (formulasCountToProcess == 0) { return {}; }
197213

198214
vec<PTRef> processedFormulas;
199-
for (PTRef fla : frameFormulas) {
215+
for (std::size_t i = context.preprocessedFrameAssertionsCount; i < frameFormulasCount; ++i) {
216+
PTRef fla = frameFormulas[i];
200217
PTRef processed = preprocessFormulaBeforeFinalTheoryPreprocessing(fla, context);
201218
processedFormulas.push(processed);
202219
}
203220

204-
assert(processedFormulas.size() == frameFormulas.size());
205-
assert(processedFormulas.size() > 0);
221+
assert(std::size_t(processedFormulas.size()) == formulasCountToProcess);
222+
assert(std::size_t(processedFormulas.size()) > 0);
206223
if (std::all_of(processedFormulas.begin(), processedFormulas.end(),
207224
[&](PTRef fla) { return fla == logic.getTerm_true(); })) {
208225
return {};

src/api/MainSolver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ class MainSolver {
336336
vec<PTRef> frameTerms;
337337
std::size_t firstNotPreprocessedFrame = 0;
338338
std::size_t insertedAssertionsCount = 0;
339+
std::vector<std::size_t> preprocessedAssertionsCountPerFrame;
339340
};
340341

341342
bool MainSolver::trackPartitions() const {

src/logics/Theory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace opensmt {
3636

3737
struct PreprocessingContext {
3838
std::size_t frameCount {0};
39+
std::size_t preprocessedFrameAssertionsCount{0};
3940
bool perPartition {false};
4041
};
4142

0 commit comments

Comments
 (0)