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 |
|
package org.sat4j.tools; |
26 |
|
|
27 |
|
import org.sat4j.core.VecInt; |
28 |
|
import org.sat4j.specs.ContradictionException; |
29 |
|
import org.sat4j.specs.ISolver; |
30 |
|
import org.sat4j.specs.IVecInt; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@author |
36 |
|
|
37 |
|
|
|
|
| 0% |
Uncovered Elements: 141 (141) |
Complexity: 10 |
Complexity Density: 0,21 |
|
38 |
|
public class GateTranslator extends SolverDecorator { |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
private static final long serialVersionUID = 1L; |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
0
|
public GateTranslator(ISolver solver) {... |
46 |
0
|
super(solver); |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
@throws |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
54 |
0
|
public void gateFalse(int y)... |
55 |
|
throws ContradictionException { |
56 |
0
|
IVecInt clause = new VecInt(1); |
57 |
0
|
clause.push(-y); |
58 |
0
|
processClause(clause); |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
@throws |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
66 |
0
|
public void gateTrue(int y)... |
67 |
|
throws ContradictionException { |
68 |
0
|
IVecInt clause = new VecInt(1); |
69 |
0
|
clause.push(y); |
70 |
0
|
processClause(clause); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@param |
76 |
|
@param |
77 |
|
@param |
78 |
|
@param |
79 |
|
@throws |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 1 |
Complexity Density: 0,06 |
|
81 |
0
|
public void ite(int y, int x1, int x2, int x3) throws ContradictionException {... |
82 |
0
|
IVecInt clause = new VecInt(2); |
83 |
|
|
84 |
|
|
85 |
0
|
clause.push(-y).push(-x1).push(x2); |
86 |
0
|
processClause(clause); |
87 |
0
|
clause.clear(); |
88 |
0
|
clause.push(-y).push(x1).push(x3); |
89 |
0
|
processClause(clause); |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
0
|
clause.clear(); |
98 |
0
|
clause.push(-x1).push(-x2).push(y); |
99 |
0
|
processClause(clause); |
100 |
0
|
clause.clear(); |
101 |
0
|
clause.push(x1).push(-x3).push(y); |
102 |
0
|
processClause(clause); |
103 |
0
|
clause.clear(); |
104 |
0
|
clause.push(-x2).push(-x3).push(y); |
105 |
0
|
processClause(clause); |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
0
|
clause.clear(); |
110 |
0
|
clause.push(y).push(x2).push(x3); |
111 |
0
|
processClause(clause); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@param |
118 |
|
@param |
119 |
|
@throws |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0,27 |
|
121 |
0
|
public void and(int y, IVecInt literals) throws ContradictionException {... |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
0
|
IVecInt clause = new VecInt(literals.size() + 1); |
126 |
0
|
clause.push(y); |
127 |
0
|
for (int i = 0; i < literals.size(); i++) { |
128 |
0
|
clause.push(-literals.get(i)); |
129 |
|
} |
130 |
0
|
processClause(clause); |
131 |
0
|
clause.clear(); |
132 |
0
|
for (int i = 0; i < literals.size(); i++) { |
133 |
|
|
134 |
0
|
clause.clear(); |
135 |
0
|
clause.push(-y); |
136 |
0
|
clause.push(literals.get(i)); |
137 |
0
|
processClause(clause); |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
@param |
145 |
|
@param |
146 |
|
@throws |
147 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 1 |
Complexity Density: 0,08 |
|
148 |
0
|
public void and(int y, int x1, int x2) throws ContradictionException {... |
149 |
0
|
IVecInt clause = new VecInt(); |
150 |
0
|
clause.push(-y); |
151 |
0
|
clause.push(x1); |
152 |
0
|
addClause(clause); |
153 |
0
|
clause.clear(); |
154 |
0
|
clause.push(-y); |
155 |
0
|
clause.push(x2); |
156 |
0
|
addClause(clause); |
157 |
0
|
clause.clear(); |
158 |
0
|
clause.push(y); |
159 |
0
|
clause.push(-x1); |
160 |
0
|
clause.push(-x2); |
161 |
0
|
addClause(clause); |
162 |
|
} |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
@param |
168 |
|
@param |
169 |
|
@throws |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
171 |
0
|
public void or(int y, IVecInt literals) throws ContradictionException {... |
172 |
|
|
173 |
|
|
174 |
0
|
IVecInt clause = new VecInt(literals.size() + 1); |
175 |
0
|
literals.copyTo(clause); |
176 |
0
|
clause.push(-y); |
177 |
0
|
processClause(clause); |
178 |
0
|
clause.clear(); |
179 |
0
|
for (int i = 0; i < literals.size(); i++) { |
180 |
|
|
181 |
0
|
clause.clear(); |
182 |
0
|
clause.push(y); |
183 |
0
|
clause.push(-literals.get(i)); |
184 |
0
|
processClause(clause); |
185 |
|
} |
186 |
|
} |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
188 |
0
|
private void processClause(IVecInt clause) throws ContradictionException {... |
189 |
0
|
addClause(clause); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
@param |
197 |
|
@throws |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
199 |
0
|
public void not(int y, int x) throws ContradictionException {... |
200 |
0
|
IVecInt clause = new VecInt(2); |
201 |
|
|
202 |
|
|
203 |
0
|
clause.push(-y).push(-x); |
204 |
0
|
processClause(clause); |
205 |
|
|
206 |
0
|
clause.clear(); |
207 |
0
|
clause.push(y).push(x); |
208 |
0
|
processClause(clause); |
209 |
|
} |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
@param |
214 |
|
@param |
215 |
|
@throws |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
217 |
0
|
public void xor(int y, IVecInt literals) throws ContradictionException {... |
218 |
0
|
literals.push(-y); |
219 |
0
|
int[] f = new int[literals.size()]; |
220 |
0
|
literals.copyTo(f); |
221 |
0
|
xor2Clause(f, 0, false); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
@param |
227 |
|
@param |
228 |
|
@throws |
229 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
230 |
0
|
public void iff(int y, IVecInt literals) throws ContradictionException {... |
231 |
0
|
literals.push(y); |
232 |
0
|
int[] f = new int[literals.size()]; |
233 |
0
|
literals.copyTo(f); |
234 |
0
|
iff2Clause(f, 0, false); |
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 4 |
Complexity Density: 0,25 |
|
237 |
0
|
private void xor2Clause(int[] f, int prefix, boolean negation)... |
238 |
|
throws ContradictionException { |
239 |
0
|
if (prefix == f.length - 1) { |
240 |
0
|
IVecInt clause = new VecInt(f.length); |
241 |
0
|
for (int i = 0; i < f.length - 1; ++i) { |
242 |
0
|
clause.push(f[i]); |
243 |
|
} |
244 |
0
|
clause.push(f[f.length - 1] * (negation ? -1 : 1)); |
245 |
0
|
processClause(clause); |
246 |
0
|
return; |
247 |
|
} |
248 |
|
|
249 |
0
|
if (negation) { |
250 |
0
|
f[prefix] = -f[prefix]; |
251 |
0
|
xor2Clause(f, prefix + 1, false); |
252 |
0
|
f[prefix] = -f[prefix]; |
253 |
|
|
254 |
0
|
xor2Clause(f, prefix + 1, true); |
255 |
|
} else { |
256 |
0
|
xor2Clause(f, prefix + 1, false); |
257 |
|
|
258 |
0
|
f[prefix] = -f[prefix]; |
259 |
0
|
xor2Clause(f, prefix + 1, true); |
260 |
0
|
f[prefix] = -f[prefix]; |
261 |
|
} |
262 |
|
} |
263 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 4 |
Complexity Density: 0,25 |
|
264 |
0
|
private void iff2Clause(int[] f, int prefix, boolean negation)... |
265 |
|
throws ContradictionException { |
266 |
0
|
if (prefix == f.length - 1) { |
267 |
0
|
IVecInt clause = new VecInt(f.length); |
268 |
0
|
for (int i = 0; i < f.length - 1; ++i) { |
269 |
0
|
clause.push(f[i]); |
270 |
|
} |
271 |
0
|
clause.push(f[f.length - 1] * (negation ? -1 : 1)); |
272 |
0
|
processClause(clause); |
273 |
0
|
return; |
274 |
|
} |
275 |
|
|
276 |
0
|
if (negation) { |
277 |
0
|
iff2Clause(f, prefix + 1, false); |
278 |
0
|
f[prefix] = -f[prefix]; |
279 |
0
|
iff2Clause(f, prefix + 1, true); |
280 |
0
|
f[prefix] = -f[prefix]; |
281 |
|
} else { |
282 |
0
|
f[prefix] = -f[prefix]; |
283 |
0
|
iff2Clause(f, prefix + 1, false); |
284 |
0
|
f[prefix] = -f[prefix]; |
285 |
0
|
iff2Clause(f, prefix + 1, true); |
286 |
|
} |
287 |
|
} |
288 |
|
|
289 |
|
} |