Skip to content

Commit 9623979

Browse files
committed
ALLSAT computation: add detection of invalid model iteration during our ALLSAT loop.
A model should never appear twice, because we give its negation into the prover. In current case, CVC5 reports an invalid model and its negation does not provide any further information, i.e., it would cause an endless loop.
1 parent d345274 commit 9623979

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/org/sosy_lab/java_smt/basicimpl/AbstractProverWithAllSat.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.common.collect.ImmutableList;
1313
import java.util.ArrayDeque;
1414
import java.util.Deque;
15+
import java.util.LinkedHashSet;
1516
import java.util.List;
1617
import java.util.Set;
1718
import org.sosy_lab.common.ShutdownNotifier;
@@ -67,6 +68,7 @@ public <R> R allSat(AllSatCallback<R> callback, List<BooleanFormula> importantPr
6768
private <R> void iterateOverAllModels(
6869
AllSatCallback<R> callback, List<BooleanFormula> importantPredicates)
6970
throws SolverException, InterruptedException {
71+
final Set<ImmutableList<BooleanFormula>> modelEvaluations = new LinkedHashSet<>();
7072
while (!isUnsat()) {
7173
shutdownNotifier.shutdownIfNecessary();
7274

@@ -87,6 +89,11 @@ private <R> void iterateOverAllModels(
8789
}
8890

8991
final ImmutableList<BooleanFormula> values = valuesOfModel.build();
92+
// avoid endless loops in case of repeated models.
93+
Preconditions.checkState(
94+
modelEvaluations.add(values),
95+
"The model evaluation %s was found before. ALLSAT computation did not make progress.",
96+
values);
9097
callback.apply(values);
9198
shutdownNotifier.shutdownIfNecessary();
9299

src/org/sosy_lab/java_smt/test/SolverAllSatTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,13 @@ public void apply(List<BooleanFormula> pModel) {
149149
assertThat(env.allSat(callback, ImmutableList.of(v1, v2))).isEqualTo(EXPECTED_RESULT);
150150
}
151151

152-
@Test
152+
@Test(timeout = 5_000)
153153
public void allSatTest_xor() throws SolverException, InterruptedException {
154154
requireIntegers();
155155

156+
// We have the following constraint: '(i=1) XOR (i=2)'
157+
// with the predicates b1 and b2 defined as: '(i=1) <=> b1' and '(i=2) <=> b2'.
158+
// We expect exactly two models from ALLSAT: {b1,-b2} and {-b1, b2}.
156159
IntegerFormula a = imgr.makeVariable("i");
157160
IntegerFormula n1 = imgr.makeNumber(1);
158161
IntegerFormula n2 = imgr.makeNumber(2);
@@ -168,9 +171,6 @@ public void allSatTest_xor() throws SolverException, InterruptedException {
168171
env.push(bmgr.equivalence(v1, cond1));
169172
env.push(bmgr.equivalence(v2, cond2));
170173

171-
// ((i=1) XOR (i=2)) & b1 <=> (i=1) & b2 <=> (i=2)
172-
// query ALLSAT for predicates [b1, b2] --> {[b1,-b2], [-b1,b2]}
173-
174174
TestAllSatCallback callback = new TestAllSatCallback();
175175

176176
assertThat(env.allSat(callback, ImmutableList.of(v1, v2))).isEqualTo(EXPECTED_RESULT);

0 commit comments

Comments
 (0)