Skip to content

Commit b2a8e7c

Browse files
committed
Revert "fixed SATSolver#add: Ensure all variables are added to the internal solver"
This reverts commit 5cdab69.
1 parent 87da23b commit b2a8e7c

File tree

7 files changed

+16
-79
lines changed

7 files changed

+16
-79
lines changed

src/main/java/org/logicng/solvers/MiniSat.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767

6868
/**
6969
* Wrapper for the MiniSAT-style SAT solvers.
70-
* @version 2.4.2
70+
* @version 2.4.0
7171
* @since 1.0
7272
*/
7373
public class MiniSat extends SATSolver {
@@ -271,18 +271,6 @@ public void add(final Formula formula, final Proposition proposition) {
271271
} else {
272272
addFormulaAsCNF(formula, proposition);
273273
}
274-
addAllOriginalVariables(formula);
275-
}
276-
277-
/**
278-
* Adds all variables of the given formula to the solver if not already present.
279-
* This method can be used to ensure that the internal solver knows the given variables.
280-
* @param originalFormula the original formula
281-
*/
282-
private void addAllOriginalVariables(final Formula originalFormula) {
283-
for (final Variable var : originalFormula.variables()) {
284-
getOrAddIndex(var);
285-
}
286274
}
287275

288276
protected void addFormulaAsCNF(final Formula formula, final Proposition proposition) {

src/test/java/org/logicng/cardinalityconstraints/CCALKTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
/**
4848
* Unit tests for the at-least-k configs.
49-
* @version 2.4.2
49+
* @version 2.0.0
5050
* @since 1.0
5151
*/
5252
public class CCALKTest implements LogicNGTest {
@@ -66,7 +66,7 @@ public void testALK() {
6666
int counter = 0;
6767
for (final CCConfig config : this.configs) {
6868
f.putConfiguration(config);
69-
testCC(10, 0, 1024, f);
69+
testCC(10, 0, 1, f);
7070
testCC(10, 1, 1023, f);
7171
testCC(10, 2, 1013, f);
7272
testCC(10, 3, 968, f);

src/test/java/org/logicng/cardinalityconstraints/CCAMKTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
/**
4545
* Unit tests for the at-most-k encoders.
46-
* @version 2.4.2
46+
* @version 2.0.0
4747
* @since 1.0
4848
*/
4949
public class CCAMKTest implements LogicNGTest {
@@ -73,8 +73,8 @@ public void testAMK() {
7373
testCC(10, 7, 968, f, false);
7474
testCC(10, 8, 1013, f, false);
7575
testCC(10, 9, 1023, f, false);
76-
testCC(10, 10, 1024, f, false);
77-
testCC(10, 15, 1024, f, false);
76+
testCC(10, 10, 1, f, false);
77+
testCC(10, 15, 1, f, false);
7878
assertThat(f.newCCVariable().name()).endsWith("_" + counter++);
7979
}
8080
}
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
package org.logicng.solvers.functions;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.logicng.util.FormulaHelper.variables;
54

65
import org.junit.jupiter.api.Test;
76
import org.logicng.datastructures.Assignment;
8-
import org.logicng.formulas.Formula;
97
import org.logicng.formulas.FormulaFactory;
10-
import org.logicng.formulas.FormulaFactoryConfig;
11-
import org.logicng.formulas.Variable;
128
import org.logicng.io.parsers.ParserException;
139
import org.logicng.solvers.MiniSat;
1410
import org.logicng.solvers.SATSolver;
15-
import org.logicng.solvers.sat.MiniSatConfig;
1611

1712
import java.util.List;
1813

1914
/**
2015
* Units tests for {@link ModelEnumerationFunction}.
21-
* @version 2.4.2
16+
* @version 2.3.0
2217
* @since 2.3.0
2318
*/
2419
public class ModelEnumerationFunctionTest {
@@ -52,29 +47,4 @@ public void testFastEvaluable() throws ParserException {
5247
models = solver.execute(ModelEnumerationFunction.builder().fastEvaluable(true).build());
5348
assertThat(models).extracting(Assignment::fastEvaluable).containsOnly(true);
5449
}
55-
56-
@Test
57-
public void testVariableRemovedBySimplificationOccursInModels() throws ParserException {
58-
final FormulaFactory f = new FormulaFactory(FormulaFactoryConfig.builder().simplifyComplementaryOperands(true).build());
59-
final SATSolver solver = MiniSat.miniSat(this.f, MiniSatConfig.builder().cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
60-
final Variable a = f.variable("A");
61-
final Variable b = f.variable("B");
62-
final Formula formula = this.f.parse("A & B => A");
63-
solver.add(formula); // during NNF conversion, used by the PG transformation, the formula simplifies to verum when added to the solver
64-
final List<Assignment> models = solver.execute(ModelEnumerationFunction.builder().variables(formula.variables()).build());
65-
assertThat(models).hasSize(4);
66-
for (final Assignment model : models) {
67-
assertThat(variables(model.literals())).containsExactlyInAnyOrder(a, b);
68-
}
69-
}
70-
71-
@Test
72-
public void testUnknownVariableNotOccurringInModel() {
73-
final SATSolver solver = MiniSat.miniSat(this.f);
74-
final Variable a = this.f.variable("A");
75-
solver.add(a);
76-
final List<Assignment> models = solver.execute(ModelEnumerationFunction.builder().variables(this.f.variables("A", "X")).build());
77-
assertThat(models).hasSize(1);
78-
assertThat(models.get(0).literals()).containsExactly(a);
79-
}
8050
}

src/test/java/org/logicng/solvers/sat/SATTest.java

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import static org.logicng.datastructures.Tristate.UNDEF;
3434
import static org.logicng.solvers.sat.MiniSatConfig.ClauseMinimization.BASIC;
3535
import static org.logicng.solvers.sat.MiniSatConfig.ClauseMinimization.NONE;
36-
import static org.logicng.util.FormulaHelper.variables;
3736

3837
import org.junit.jupiter.api.Test;
3938
import org.logicng.LogicNGTest;
@@ -44,7 +43,6 @@
4443
import org.logicng.formulas.CType;
4544
import org.logicng.formulas.Formula;
4645
import org.logicng.formulas.FormulaFactory;
47-
import org.logicng.formulas.FormulaFactoryConfig;
4846
import org.logicng.formulas.Literal;
4947
import org.logicng.formulas.Variable;
5048
import org.logicng.handlers.ModelEnumerationHandler;
@@ -63,6 +61,7 @@
6361
import org.logicng.solvers.functions.ModelEnumerationFunction;
6462
import org.logicng.solvers.functions.UpZeroLiteralsFunction;
6563
import org.logicng.testutils.PigeonHoleGenerator;
64+
import org.logicng.util.FormulaHelper;
6665

6766
import java.io.BufferedReader;
6867
import java.io.File;
@@ -82,7 +81,7 @@
8281

8382
/**
8483
* Unit tests for the SAT solvers.
85-
* @version 2.4.1
84+
* @version 1.6
8685
* @since 1.0
8786
*/
8887
public class SATTest extends TestWithExampleFormulas implements LogicNGTest {
@@ -297,28 +296,6 @@ public void testPartialModel() {
297296
}
298297
}
299298

300-
@Test
301-
public void testVariableRemovedBySimplificationOccursInModel() throws ParserException {
302-
final FormulaFactory f = new FormulaFactory(FormulaFactoryConfig.builder().simplifyComplementaryOperands(true).build());
303-
final SATSolver solver = MiniSat.miniSat(f, MiniSatConfig.builder().cnfMethod(MiniSatConfig.CNFMethod.PG_ON_SOLVER).build());
304-
final Variable a = f.variable("A");
305-
final Variable b = f.variable("B");
306-
final Formula formula = this.f.parse("A & B => A");
307-
solver.add(formula); // during NNF conversion, used by the PG transformation, the formula simplifies to verum when added to the solver
308-
assertThat(solver.sat()).isEqualTo(Tristate.TRUE);
309-
assertThat(solver.knownVariables()).containsExactlyInAnyOrder(a, b);
310-
assertThat(variables(solver.model().literals())).containsExactlyInAnyOrder(a, b);
311-
}
312-
313-
@Test
314-
public void testUnknownVariableNotOccurringInModel() {
315-
final SATSolver solver = MiniSat.miniSat(this.f);
316-
final Variable a = this.f.variable("A");
317-
solver.add(a);
318-
assertThat(solver.sat()).isEqualTo(Tristate.TRUE);
319-
assertThat(solver.model(this.f.variables("A", "X")).literals()).containsExactly(a);
320-
}
321-
322299
@Test
323300
public void testModelEnumerationHandler() {
324301
for (final SATSolver s : this.solvers) {
@@ -364,6 +341,7 @@ public boolean foundModel(final Assignment assignment) {
364341
}
365342

366343
@Test
344+
@SuppressWarnings("deprecation")
367345
public void testWithRelaxation() throws ParserException {
368346
final PropositionalParser parser = new PropositionalParser(this.f);
369347
final Formula one = parser.parse("a & b & (c | ~d)");
@@ -844,6 +822,7 @@ public void testKnownVariables() throws ParserException {
844822
}
845823

846824
@Test
825+
@SuppressWarnings("deprecation")
847826
public void testAddWithoutUnknown() throws ParserException {
848827
final PropositionalParser parser = new PropositionalParser(this.f);
849828
final Formula phi = parser.parse("x1 & (~x2 | x3) & (x4 | ~x5)");
@@ -1107,7 +1086,7 @@ public void testDimacsFilesWithSelectionOrder() throws IOException {
11071086
if (fileName.endsWith(".cnf")) {
11081087
readCNF(solver, file);
11091088
final List<Literal> selectionOrder = new ArrayList<>();
1110-
for (final Variable var : variables(solver.execute(FormulaOnSolverFunction.get()))) {
1089+
for (final Variable var : FormulaHelper.variables(solver.execute(FormulaOnSolverFunction.get()))) {
11111090
if (selectionOrder.size() < 10) {
11121091
selectionOrder.add(var.negate());
11131092
}

src/test/java/org/logicng/transformations/cnf/BDDCNFTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
/**
4444
* Unit Tests for {@link BDDCNFTransformation}.
45-
* @version 2.4.2
45+
* @version 2.3.0
4646
* @since 1.4.0
4747
*/
4848
public class BDDCNFTest extends TestWithExampleFormulas {
@@ -160,7 +160,7 @@ public void testNot() throws ParserException {
160160
@Test
161161
public void testCC() throws ParserException {
162162
final PseudoBooleanParser p = new PseudoBooleanParser(this.f);
163-
final Formula f1 = p.parse("a <=> (1 * b <= 0)");
163+
final Formula f1 = p.parse("a <=> (1 * b <= 1)");
164164
final Formula f2 = p.parse("~(1 * b <= 1)");
165165
final Formula f3 = p.parse("(1 * b + 1 * c + 1 * d <= 1)");
166166
final Formula f4 = p.parse("~(1 * b + 1 * c + 1 * d <= 1)");

src/test/java/org/logicng/transformations/dnf/BDDDNFTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
/**
4545
* Unit Tests for {@link BDDDNFTransformation}.
46-
* @version 2.4.2
46+
* @version 2.3.0
4747
* @since 2.3.0
4848
*/
4949
public class BDDDNFTest extends TestWithExampleFormulas {
@@ -162,7 +162,7 @@ public void testNot() throws ParserException {
162162
@Test
163163
public void testCC() throws ParserException {
164164
final PseudoBooleanParser p = new PseudoBooleanParser(this.f);
165-
final Formula f1 = p.parse("a <=> (1 * b <= 0)");
165+
final Formula f1 = p.parse("a <=> (1 * b <= 1)");
166166
final Formula f2 = p.parse("~(1 * b <= 1)");
167167
final Formula f3 = p.parse("(1 * b + 1 * c + 1 * d <= 1)");
168168
final Formula f4 = p.parse("~(1 * b + 1 * c + 1 * d <= 1)");

0 commit comments

Comments
 (0)