Skip to content

Commit 0e58322

Browse files
committed
Split simplifyFormulas to another parametrized function
1 parent 86a8217 commit 0e58322

File tree

2 files changed

+68
-47
lines changed

2 files changed

+68
-47
lines changed

src/api/MainSolver.cc

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -196,67 +196,86 @@ void MainSolver::propagateDecisionPreferenceToSMTSolver(PTRef pref, FrameId fram
196196
sstat MainSolver::simplifyFormulas() {
197197
status = s_Undef;
198198
for (std::size_t i = firstNotSimplifiedFrame; i < frames.frameCount() && status != s_False; i++) {
199+
auto & frame = frames[i];
200+
FrameId const frameId = frame.getId();
199201
PreprocessingContext context{.frameCount = i, .perPartition = trackPartitions()};
200202
preprocessor.prepareForProcessingFrame(i);
201203
firstNotSimplifiedFrame = i + 1;
202-
if (context.perPartition) {
203-
vec<PTRef> frameFormulas;
204-
for (PTRef fla : frames[i].formulas) {
205-
PTRef processed = theory->preprocessAfterSubstitutions(fla, context);
206-
pmanager.transferPartitionMembership(fla, processed);
207-
frameFormulas.push(processed);
208-
preprocessor.addPreprocessedFormula(processed);
209-
}
210-
if (frameFormulas.size() == 0 or std::all_of(frameFormulas.begin(), frameFormulas.end(),
211-
[&](PTRef fla) { return fla == logic.getTerm_true(); })) {
212-
continue;
213-
}
214-
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
215-
assert(frameFormulas.size() == frames[i].formulas.size());
216-
for (PTRef & fla : frameFormulas) {
217-
if (fla == logic.getTerm_true()) { continue; }
218-
assert(pmanager.getPartitionIndex(fla) != -1);
219-
// Optimize the dag for cnfization
220-
if (logic.isBooleanOperator(fla)) {
221-
PTRef old = fla;
222-
fla = rewriteMaxArity(fla);
223-
pmanager.transferPartitionMembership(old, fla);
224-
}
225-
assert(pmanager.getPartitionIndex(fla) != -1);
226-
pmanager.propagatePartitionMask(fla);
227-
status = giveToSolver(fla, frames[i].getId());
228-
if (status == s_False) { break; }
229-
}
230-
} else {
231-
PTRef frameFormula = logic.mkAnd(frames[i].formulas);
232-
if (context.frameCount > 0) { frameFormula = applyLearntSubstitutions(frameFormula); }
233-
frameFormula = theory->preprocessBeforeSubstitutions(frameFormula, context);
234-
frameFormula = substitutionPass(frameFormula, context);
235-
frameFormula = theory->preprocessAfterSubstitutions(frameFormula, context);
236-
237-
if (logic.isFalse(frameFormula)) {
238-
giveToSolver(logic.getTerm_false(), frames[i].getId());
239-
status = s_False;
240-
break;
241-
}
242-
preprocessor.addPreprocessedFormula(frameFormula);
243-
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
244-
// Optimize the dag for cnfization
245-
if (logic.isBooleanOperator(frameFormula)) { frameFormula = rewriteMaxArity(frameFormula); }
246-
status = giveToSolver(frameFormula, frames[i].getId());
247-
}
204+
simplifyFormulas(frame.formulas, frameId, context);
205+
if (status == s_False) { break; }
248206

249207
for (PTRef pref : decisionPreferences.scope(i)) {
250-
propagateDecisionPreferenceToSMTSolver(pref, frames[i].getId());
208+
propagateDecisionPreferenceToSMTSolver(pref, frameId);
251209
}
252210
}
211+
253212
if (status == s_False) {
254213
assert(firstNotSimplifiedFrame > 0);
255214
rememberUnsatFrame(firstNotSimplifiedFrame - 1);
256215
}
216+
257217
return status;
258218
}
259219

220+
void MainSolver::simplifyFormulas(vec<PTRef> const & frameFormulas, FrameId frameId,
221+
PreprocessingContext const & context) {
222+
if (frameFormulas.size() == 0) { return; }
223+
224+
if (not context.perPartition) {
225+
PTRef frameFormula = logic.mkAnd(frameFormulas);
226+
if (context.frameCount > 0) { frameFormula = applyLearntSubstitutions(frameFormula); }
227+
frameFormula = theory->preprocessBeforeSubstitutions(frameFormula, context);
228+
frameFormula = substitutionPass(frameFormula, context);
229+
frameFormula = theory->preprocessAfterSubstitutions(frameFormula, context);
230+
231+
if (logic.isFalse(frameFormula)) {
232+
giveToSolver(logic.getTerm_false(), frameId);
233+
status = s_False;
234+
return;
235+
}
236+
237+
preprocessor.addPreprocessedFormula(frameFormula);
238+
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
239+
// Optimize the dag for cnfization
240+
if (logic.isBooleanOperator(frameFormula)) { frameFormula = rewriteMaxArity(frameFormula); }
241+
status = giveToSolver(frameFormula, frameId);
242+
return;
243+
}
244+
245+
vec<PTRef> processedFormulas;
246+
for (PTRef fla : frameFormulas) {
247+
PTRef processed = theory->preprocessAfterSubstitutions(fla, context);
248+
pmanager.transferPartitionMembership(fla, processed);
249+
processedFormulas.push(processed);
250+
preprocessor.addPreprocessedFormula(processed);
251+
}
252+
253+
assert(processedFormulas.size() == frameFormulas.size());
254+
assert(processedFormulas.size() > 0);
255+
if (std::all_of(processedFormulas.begin(), processedFormulas.end(),
256+
[&](PTRef fla) { return fla == logic.getTerm_true(); })) {
257+
return;
258+
}
259+
260+
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
261+
for (PTRef & fla : processedFormulas) {
262+
if (fla == logic.getTerm_true()) { continue; }
263+
assert(pmanager.getPartitionIndex(fla) != -1);
264+
// Optimize the dag for cnfization
265+
if (logic.isBooleanOperator(fla)) {
266+
PTRef old = fla;
267+
fla = rewriteMaxArity(fla);
268+
pmanager.transferPartitionMembership(old, fla);
269+
}
270+
assert(pmanager.getPartitionIndex(fla) != -1);
271+
pmanager.propagatePartitionMask(fla);
272+
status = giveToSolver(fla, frameId);
273+
if (status == s_False) { return; }
274+
}
275+
276+
// if needed, return processedFormulas
277+
}
278+
260279
vec<PTRef> MainSolver::getCurrentAssertions() const {
261280
vec<PTRef> assertions;
262281
size_t const cnt = frames.frameCount();

src/api/MainSolver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ class MainSolver {
297297

298298
void propagateDecisionPreferenceToSMTSolver(PTRef, FrameId);
299299

300+
void simplifyFormulas(vec<PTRef> const & frameFormulas, FrameId, PreprocessingContext const &);
301+
300302
PTRef rewriteMaxArity(PTRef root);
301303

302304
virtual sstat solve_(vec<FrameId> const & enabledFrames);

0 commit comments

Comments
 (0)