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 org.sat4j.core.VecInt; |
28 |
|
import org.sat4j.specs.ContradictionException; |
29 |
|
import org.sat4j.specs.ISolver; |
30 |
|
import org.sat4j.specs.IVecInt; |
31 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 4 |
Complexity Density: 0,56 |
|
32 |
|
public class Var implements Evaluable { |
33 |
|
|
34 |
|
private final Domain domain; |
35 |
|
|
36 |
|
private final String id; |
37 |
|
|
38 |
|
private final int startid; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
40 |
0
|
public Var(String idvar, Domain domain, int lastvarnumber) {... |
41 |
0
|
this.domain = domain; |
42 |
0
|
this.id = idvar; |
43 |
0
|
this.startid = lastvarnumber + 1; |
44 |
|
} |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@see |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0
|
public Domain domain() {... |
52 |
0
|
return domain; |
53 |
|
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@see |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
0
|
public int translate(int key) {... |
61 |
0
|
return domain.pos(key) + startid; |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@see |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0,4 |
|
69 |
0
|
public void toClause(ISolver solver) throws ContradictionException {... |
70 |
0
|
IVecInt clause = new VecInt(domain.size()); |
71 |
0
|
for (int i = 0; i < domain.size(); i++) |
72 |
0
|
clause.push(i + startid); |
73 |
0
|
solver.addClause(clause); |
74 |
0
|
solver.addAtMost(clause, 1); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
77 |
0
|
public int findValue(int[] model) {... |
78 |
0
|
for (int i = 0; i < domain.size(); i++) { |
79 |
0
|
int varnum = i + startid; |
80 |
0
|
if (model[varnum - 1] == varnum) |
81 |
0
|
return domain.get(i); |
82 |
|
} |
83 |
0
|
throw new RuntimeException("BIG PROBLEM: no value for a var!"); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
@see |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0
|
@Override... |
92 |
|
public String toString() { |
93 |
0
|
return id; |
94 |
|
} |
95 |
|
|
96 |
|
} |