1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package org.sat4j.pb;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35
36 import org.junit.Test;
37 import org.sat4j.core.VecInt;
38 import org.sat4j.specs.ContradictionException;
39 import org.sat4j.specs.IVecInt;
40 import org.sat4j.specs.TimeoutException;
41
42
43
44
45
46 public class BugSAT21 {
47
48 @Test
49 public void testAtLeastWithNegativeLiteralsAsText()
50 throws ContradictionException {
51
52 IPBSolver pbSolver = new OPBStringSolver();
53 pbSolver.newVar(2);
54 pbSolver.setExpectedNumberOfClauses(1);
55
56 int[] constr = { -1, 2 };
57
58 pbSolver.addAtLeast(new VecInt(constr), 1);
59 String expected = "* #variable= 2 #constraint= 1 \n\n-1 x1 +1 x2 >= 0 ;\n";
60 assertEquals(expected, pbSolver.toString());
61
62 }
63
64 @Test
65 public void testAtLeastWithNegativeLiterals()
66 throws ContradictionException, TimeoutException {
67
68 IPBSolver pbSolver = SolverFactory.newDefault();
69 pbSolver.newVar(2);
70 pbSolver.setExpectedNumberOfClauses(1);
71
72 int[] constr = { -1, 2 };
73
74 pbSolver.addAtLeast(new VecInt(constr), 1);
75 IVecInt assumps = new VecInt();
76 assumps.push(1).push(-2);
77 assertFalse(pbSolver.isSatisfiable(assumps));
78 assumps.clear();
79 assumps.push(-1).push(-2);
80 assertTrue(pbSolver.isSatisfiable(assumps));
81 assumps.clear();
82 assumps.push(1).push(2);
83 assertTrue(pbSolver.isSatisfiable(assumps));
84 assumps.clear();
85 assumps.push(-1).push(2);
86 assertTrue(pbSolver.isSatisfiable(assumps));
87
88 }
89
90 @Test
91 public void testAlMostWithNegativeLiteralsAsText()
92 throws ContradictionException {
93
94 IPBSolver pbSolver = new OPBStringSolver();
95 pbSolver.newVar(2);
96 pbSolver.setExpectedNumberOfClauses(1);
97
98 int[] constr = { -1, 2 };
99
100 pbSolver.addAtMost(new VecInt(constr), 1);
101 String expected = "* #variable= 2 #constraint= 1 \n\n+1 x1 -1 x2 >= 0 ;\n";
102 assertEquals(expected, pbSolver.toString());
103
104 }
105
106 @Test
107 public void testAtMostWithNegativeLiterals() throws ContradictionException,
108 TimeoutException {
109
110 IPBSolver pbSolver = SolverFactory.newDefault();
111 pbSolver.newVar(2);
112 pbSolver.setExpectedNumberOfClauses(1);
113
114 int[] constr = { -1, 2 };
115
116 pbSolver.addAtMost(new VecInt(constr), 1);
117 IVecInt assumps = new VecInt();
118 assumps.push(1).push(-2);
119 assertTrue(pbSolver.isSatisfiable(assumps));
120 assumps.clear();
121 assumps.push(-1).push(-2);
122 assertTrue(pbSolver.isSatisfiable(assumps));
123 assumps.clear();
124 assumps.push(1).push(2);
125 assertTrue(pbSolver.isSatisfiable(assumps));
126 assumps.clear();
127 assumps.push(-1).push(2);
128 assertFalse(pbSolver.isSatisfiable(assumps));
129
130 }
131
132 }