Skip to content

Commit c9834f2

Browse files
committed
Split simplifyFormulas to another parametrized function
1 parent 317f229 commit c9834f2

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
@@ -214,67 +214,86 @@ Lit MainSolver::giveAnyDecisionPreferenceToSMTSolver(PTRef pref, FrameId frameId
214214
sstat MainSolver::simplifyFormulas() {
215215
status = s_Undef;
216216
for (std::size_t i = firstNotSimplifiedFrame; i < frames.frameCount() && status != s_False; i++) {
217+
auto & frame = frames[i];
218+
FrameId const frameId = frame.getId();
217219
PreprocessingContext context{.frameCount = i, .perPartition = trackPartitions()};
218220
preprocessor.prepareForProcessingFrame(i);
219221
firstNotSimplifiedFrame = i + 1;
220-
if (context.perPartition) {
221-
vec<PTRef> frameFormulas;
222-
for (PTRef fla : frames[i].formulas) {
223-
PTRef processed = theory->preprocessAfterSubstitutions(fla, context);
224-
pmanager.transferPartitionMembership(fla, processed);
225-
frameFormulas.push(processed);
226-
preprocessor.addPreprocessedFormula(processed);
227-
}
228-
if (frameFormulas.size() == 0 or std::all_of(frameFormulas.begin(), frameFormulas.end(),
229-
[&](PTRef fla) { return fla == logic.getTerm_true(); })) {
230-
continue;
231-
}
232-
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
233-
assert(frameFormulas.size() == frames[i].formulas.size());
234-
for (PTRef & fla : frameFormulas) {
235-
if (fla == logic.getTerm_true()) { continue; }
236-
assert(pmanager.getPartitionIndex(fla) != -1);
237-
// Optimize the dag for cnfization
238-
if (logic.isBooleanOperator(fla)) {
239-
PTRef old = fla;
240-
fla = rewriteMaxArity(fla);
241-
pmanager.transferPartitionMembership(old, fla);
242-
}
243-
assert(pmanager.getPartitionIndex(fla) != -1);
244-
pmanager.propagatePartitionMask(fla);
245-
status = giveToSolver(fla, frames[i].getId());
246-
if (status == s_False) { break; }
247-
}
248-
} else {
249-
PTRef frameFormula = logic.mkAnd(frames[i].formulas);
250-
if (context.frameCount > 0) { frameFormula = applyLearntSubstitutions(frameFormula); }
251-
frameFormula = theory->preprocessBeforeSubstitutions(frameFormula, context);
252-
frameFormula = substitutionPass(frameFormula, context);
253-
frameFormula = theory->preprocessAfterSubstitutions(frameFormula, context);
254-
255-
if (logic.isFalse(frameFormula)) {
256-
giveToSolver(logic.getTerm_false(), frames[i].getId());
257-
status = s_False;
258-
break;
259-
}
260-
preprocessor.addPreprocessedFormula(frameFormula);
261-
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
262-
// Optimize the dag for cnfization
263-
if (logic.isBooleanOperator(frameFormula)) { frameFormula = rewriteMaxArity(frameFormula); }
264-
status = giveToSolver(frameFormula, frames[i].getId());
265-
}
222+
simplifyFormulas(frame.formulas, frameId, context);
223+
if (status == s_False) { break; }
266224

267225
for (PTRef pref : decisionPreferences.scope(i)) {
268-
giveDecisionPreferenceToSMTSolver(pref, frames[i].getId());
226+
giveDecisionPreferenceToSMTSolver(pref, frameId);
269227
}
270228
}
229+
271230
if (status == s_False) {
272231
assert(firstNotSimplifiedFrame > 0);
273232
rememberUnsatFrame(firstNotSimplifiedFrame - 1);
274233
}
234+
275235
return status;
276236
}
277237

238+
void MainSolver::simplifyFormulas(vec<PTRef> const & frameFormulas, FrameId frameId,
239+
PreprocessingContext const & context) {
240+
if (frameFormulas.size() == 0) { return; }
241+
242+
if (not context.perPartition) {
243+
PTRef frameFormula = logic.mkAnd(frameFormulas);
244+
if (context.frameCount > 0) { frameFormula = applyLearntSubstitutions(frameFormula); }
245+
frameFormula = theory->preprocessBeforeSubstitutions(frameFormula, context);
246+
frameFormula = substitutionPass(frameFormula, context);
247+
frameFormula = theory->preprocessAfterSubstitutions(frameFormula, context);
248+
249+
if (logic.isFalse(frameFormula)) {
250+
giveToSolver(logic.getTerm_false(), frameId);
251+
status = s_False;
252+
return;
253+
}
254+
255+
preprocessor.addPreprocessedFormula(frameFormula);
256+
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
257+
// Optimize the dag for cnfization
258+
if (logic.isBooleanOperator(frameFormula)) { frameFormula = rewriteMaxArity(frameFormula); }
259+
status = giveToSolver(frameFormula, frameId);
260+
return;
261+
}
262+
263+
vec<PTRef> processedFormulas;
264+
for (PTRef fla : frameFormulas) {
265+
PTRef processed = theory->preprocessAfterSubstitutions(fla, context);
266+
pmanager.transferPartitionMembership(fla, processed);
267+
processedFormulas.push(processed);
268+
preprocessor.addPreprocessedFormula(processed);
269+
}
270+
271+
assert(processedFormulas.size() == frameFormulas.size());
272+
assert(processedFormulas.size() > 0);
273+
if (std::all_of(processedFormulas.begin(), processedFormulas.end(),
274+
[&](PTRef fla) { return fla == logic.getTerm_true(); })) {
275+
return;
276+
}
277+
278+
theory->afterPreprocessing(preprocessor.getPreprocessedFormulas());
279+
for (PTRef & fla : processedFormulas) {
280+
if (fla == logic.getTerm_true()) { continue; }
281+
assert(pmanager.getPartitionIndex(fla) != -1);
282+
// Optimize the dag for cnfization
283+
if (logic.isBooleanOperator(fla)) {
284+
PTRef old = fla;
285+
fla = rewriteMaxArity(fla);
286+
pmanager.transferPartitionMembership(old, fla);
287+
}
288+
assert(pmanager.getPartitionIndex(fla) != -1);
289+
pmanager.propagatePartitionMask(fla);
290+
status = giveToSolver(fla, frameId);
291+
if (status == s_False) { return; }
292+
}
293+
294+
// if needed, return processedFormulas
295+
}
296+
278297
vec<PTRef> MainSolver::getCurrentAssertions() const {
279298
vec<PTRef> assertions;
280299
size_t const cnt = frames.frameCount();

src/api/MainSolver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ class MainSolver {
300300
Lit giveBoolVarDecisionPreferenceToSMTSolver(PTRef);
301301
Lit giveAnyDecisionPreferenceToSMTSolver(PTRef, FrameId);
302302

303+
void simplifyFormulas(vec<PTRef> const & frameFormulas, FrameId, PreprocessingContext const &);
304+
303305
PTRef rewriteMaxArity(PTRef root);
304306

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

0 commit comments

Comments
 (0)