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.reader.csp; |
26 |
|
|
27 |
|
import java.util.HashMap; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import org.sat4j.core.VecInt; |
31 |
|
import org.sat4j.specs.ContradictionException; |
32 |
|
import org.sat4j.specs.ISolver; |
33 |
|
import org.sat4j.specs.IVec; |
34 |
|
import org.sat4j.specs.IVecInt; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 37 (37) |
Complexity: 5 |
Complexity Density: 0,48 |
|
36 |
|
public class BinarySupportEncoding implements Encoding { |
37 |
|
|
38 |
|
private final Map<Integer, IVecInt> supportsa = new HashMap<Integer, IVecInt>(); |
39 |
|
|
40 |
|
private final Map<Integer, IVecInt> supportsb = new HashMap<Integer, IVecInt>(); |
41 |
|
|
42 |
|
private static final Encoding instance = new BinarySupportEncoding(); |
43 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
44 |
0
|
private BinarySupportEncoding() {... |
45 |
|
|
46 |
|
} |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
0
|
public static Encoding instance() {... |
49 |
0
|
return instance; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
52 |
0
|
public void onFinish(ISolver solver, IVec<Var> scope)... |
53 |
|
throws ContradictionException { |
54 |
0
|
generateClauses(scope.get(0), supportsa, solver); |
55 |
0
|
generateClauses(scope.get(1), supportsb, solver); |
56 |
|
|
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
59 |
0
|
public void onInit(ISolver solver, IVec<Var> scope) {... |
60 |
0
|
supportsa.clear(); |
61 |
0
|
supportsb.clear(); |
62 |
|
} |
63 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
64 |
0
|
public void onNogood(ISolver solver, IVec<Var> scope,... |
65 |
|
Map<Evaluable, Integer> tuple) throws ContradictionException { |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0,17 |
|
68 |
0
|
public void onSupport(ISolver solver, IVec<Var> scope,... |
69 |
|
Map<Evaluable, Integer> tuple) throws ContradictionException { |
70 |
0
|
Var vara = scope.get(0); |
71 |
0
|
int va = tuple.get(vara); |
72 |
0
|
Var varb = scope.get(1); |
73 |
0
|
int vb = tuple.get(varb); |
74 |
0
|
addSupport(va, varb, vb, supportsa); |
75 |
0
|
addSupport(vb, vara, va, supportsb); |
76 |
|
} |
77 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
78 |
0
|
private void addSupport(int head, Evaluable v, int value,... |
79 |
|
Map<Integer, IVecInt> supports) { |
80 |
0
|
IVecInt sup = supports.get(head); |
81 |
0
|
if (sup == null) { |
82 |
0
|
sup = new VecInt(); |
83 |
0
|
supports.put(head, sup); |
84 |
|
} |
85 |
0
|
sup.push(v.translate(value)); |
86 |
|
} |
87 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0,44 |
|
88 |
0
|
private void generateClauses(Evaluable v, Map<Integer, IVecInt> supports,... |
89 |
|
ISolver solver) throws ContradictionException { |
90 |
0
|
IVecInt clause = new VecInt(); |
91 |
0
|
for (int key : v.domain()) { |
92 |
0
|
clause.clear(); |
93 |
0
|
IVecInt support = supports.get(key); |
94 |
0
|
clause.push(-v.translate(key)); |
95 |
0
|
if (support != null) { |
96 |
0
|
for (int i : support) |
97 |
0
|
clause.push(i); |
98 |
|
} |
99 |
0
|
solver.addClause(clause); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
|
} |