1 |
|
package org.sat4j.minisat.datatype; |
2 |
|
|
3 |
|
import junit.framework.TestCase; |
4 |
|
|
5 |
|
import org.sat4j.core.VecInt; |
6 |
|
import org.sat4j.minisat.SolverFactory; |
7 |
|
import org.sat4j.reader.InstanceReader; |
8 |
|
import org.sat4j.specs.ContradictionException; |
9 |
|
import org.sat4j.specs.ISolver; |
10 |
|
import org.sat4j.specs.IVecInt; |
11 |
|
import org.sat4j.specs.TimeoutException; |
12 |
|
|
|
|
| 0% |
Uncovered Elements: 113 (113) |
Complexity: 10 |
Complexity Density: 0,2 |
|
13 |
|
public class TestAtMost extends TestCase { |
14 |
|
|
15 |
|
private static final String PREFIX = System.getProperty("test.prefix"); |
16 |
|
|
17 |
|
private ISolver solver; |
18 |
|
|
19 |
|
private InstanceReader reader; |
20 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
21 |
0
|
public TestAtMost(String s) {... |
22 |
0
|
super(s); |
23 |
|
} |
24 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
25 |
0
|
@Override... |
26 |
|
protected void setUp() { |
27 |
0
|
solver = SolverFactory.newMiniSAT(); |
28 |
0
|
reader = new InstanceReader(solver); |
29 |
|
} |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0,13 |
4
-
|
|
31 |
0
|
public void testUnEssaiSat() throws TimeoutException {... |
32 |
0
|
try { |
33 |
0
|
solver.reset(); |
34 |
|
|
35 |
0
|
solver.newVar(3); |
36 |
|
|
37 |
|
|
38 |
0
|
IVecInt vec = new VecInt(); |
39 |
0
|
vec.push(1); |
40 |
0
|
vec.push(2); |
41 |
0
|
vec.push(3); |
42 |
0
|
solver.addAtLeast(vec, 2); |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
0
|
vec = new VecInt(); |
47 |
0
|
vec.push(1); |
48 |
0
|
vec.push(-2); |
49 |
0
|
solver.addAtLeast(vec, 2); |
50 |
|
|
51 |
0
|
boolean isSat = solver.isSatisfiable(); |
52 |
|
|
53 |
0
|
assertTrue(isSat); |
54 |
|
} catch (ContradictionException e) { |
55 |
0
|
assertTrue(false); |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
@param |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
62 |
0
|
private void affichageResultat(boolean isSat) {... |
63 |
0
|
if (isSat) { |
64 |
0
|
System.out.println("s SATISFIABLE"); |
65 |
0
|
int[] model = solver.model(); |
66 |
0
|
StringBuffer stb = new StringBuffer(); |
67 |
0
|
stb.append("v "); |
68 |
0
|
for (int i = 0; i < model.length; i++) { |
69 |
0
|
stb.append(model[i]); |
70 |
0
|
stb.append(" "); |
71 |
|
} |
72 |
0
|
stb.append(" 0"); |
73 |
0
|
System.out.println(stb); |
74 |
|
} else |
75 |
0
|
System.out.println("s UNSATISFIABLE"); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0,12 |
4
-
|
|
78 |
0
|
public void testUnEssaiUnsat() throws TimeoutException {... |
79 |
0
|
try { |
80 |
0
|
solver.reset(); |
81 |
|
|
82 |
0
|
solver.newVar(2); |
83 |
|
|
84 |
|
|
85 |
0
|
IVecInt vecLit = new VecInt(); |
86 |
0
|
vecLit.push(1); |
87 |
0
|
vecLit.push(-2); |
88 |
0
|
solver.addAtLeast(vecLit, 1); |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
0
|
vecLit = new VecInt(); |
93 |
0
|
vecLit.push(-1); |
94 |
0
|
solver.addAtLeast(vecLit, 1); |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
0
|
vecLit = new VecInt(); |
99 |
0
|
vecLit.push(2); |
100 |
0
|
solver.addAtLeast(vecLit, 1); |
101 |
|
|
102 |
0
|
boolean isSat = solver.isSatisfiable(); |
103 |
|
|
104 |
0
|
assertFalse(isSat); |
105 |
|
} catch (ContradictionException e) { |
106 |
0
|
assertTrue(false); |
107 |
|
} |
108 |
|
|
109 |
|
} |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
4
-
|
|
111 |
0
|
public void test2Sat() throws TimeoutException {... |
112 |
0
|
try { |
113 |
0
|
solver.reset(); |
114 |
|
|
115 |
0
|
solver.newVar(2); |
116 |
|
|
117 |
|
|
118 |
0
|
IVecInt vecLit = new VecInt(); |
119 |
0
|
vecLit.push(1); |
120 |
0
|
vecLit.push(-2); |
121 |
0
|
solver.addAtMost(vecLit, 3); |
122 |
|
|
123 |
0
|
boolean isSat = solver.isSatisfiable(); |
124 |
|
|
125 |
0
|
assertTrue(isSat); |
126 |
|
} catch (ContradictionException e) { |
127 |
0
|
assertTrue(false); |
128 |
|
} |
129 |
|
} |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0,22 |
4
-
|
|
131 |
0
|
public void test4Unsat() throws TimeoutException {... |
132 |
0
|
try { |
133 |
0
|
solver.reset(); |
134 |
|
|
135 |
0
|
solver.newVar(2); |
136 |
|
|
137 |
|
|
138 |
0
|
IVecInt vecLit = new VecInt(); |
139 |
0
|
vecLit.push(1); |
140 |
0
|
vecLit.push(-2); |
141 |
|
|
142 |
0
|
solver.addAtLeast(vecLit, 3); |
143 |
|
|
144 |
0
|
solver.isSatisfiable(); |
145 |
|
|
146 |
0
|
fail(); |
147 |
|
} catch (ContradictionException e) { |
148 |
|
} |
149 |
|
} |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 2 |
Complexity Density: 0,13 |
4
-
|
|
151 |
0
|
public void test3Unsat() throws TimeoutException {... |
152 |
0
|
try { |
153 |
0
|
solver.reset(); |
154 |
|
|
155 |
0
|
solver.newVar(2); |
156 |
|
|
157 |
|
|
158 |
0
|
IVecInt vecLit = new VecInt(); |
159 |
0
|
vecLit.push(1); |
160 |
0
|
solver.addAtLeast(vecLit, 1); |
161 |
|
|
162 |
|
|
163 |
0
|
vecLit = new VecInt(); |
164 |
0
|
vecLit.push(2); |
165 |
0
|
solver.addAtLeast(vecLit, 1); |
166 |
|
|
167 |
|
|
168 |
0
|
vecLit = new VecInt(); |
169 |
0
|
vecLit.push(1); |
170 |
0
|
vecLit.push(2); |
171 |
0
|
solver.addAtMost(vecLit, 1); |
172 |
|
|
173 |
0
|
solver.isSatisfiable(); |
174 |
|
|
175 |
0
|
fail(); |
176 |
|
} catch (ContradictionException e) { |
177 |
|
} |
178 |
|
|
179 |
|
} |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0,2 |
4
-
|
|
181 |
0
|
public void test5Sat() throws TimeoutException {... |
182 |
0
|
try { |
183 |
0
|
solver.reset(); |
184 |
|
|
185 |
0
|
solver.newVar(2); |
186 |
|
|
187 |
|
|
188 |
0
|
IVecInt vecLit = new VecInt(); |
189 |
0
|
vecLit.push(1); |
190 |
0
|
vecLit.push(-2); |
191 |
|
|
192 |
0
|
solver.addAtMost(vecLit, 0); |
193 |
|
|
194 |
0
|
boolean isSat = solver.isSatisfiable(); |
195 |
|
|
196 |
0
|
assertTrue(isSat); |
197 |
|
} catch (ContradictionException e) { |
198 |
0
|
assertTrue(false); |
199 |
|
} |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0,25 |
4
-
|
|
219 |
0
|
public void testDimacs1() throws TimeoutException {... |
220 |
0
|
solver.reset(); |
221 |
0
|
try { |
222 |
0
|
reader.parseInstance(PREFIX + "test1bis.dimacs"); |
223 |
|
} catch (Exception e) { |
224 |
0
|
System.out.println(e.getMessage()); |
225 |
0
|
e.printStackTrace(); |
226 |
0
|
fail(); |
227 |
|
} |
228 |
0
|
System.out.println("fin Dimacs 1"); |
229 |
0
|
assertTrue(solver.isSatisfiable()); |
230 |
|
} |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
232 |
0
|
public static void main(String[] args) {... |
233 |
0
|
junit.swingui.TestRunner.run(TestAtMost.class); |
234 |
|
} |
235 |
|
|
236 |
|
} |