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.Map;
28
29 import org.sat4j.core.VecInt;
30 import org.sat4j.specs.ContradictionException;
31 import org.sat4j.specs.ISolver;
32 import org.sat4j.specs.IVec;
33 import org.sat4j.specs.IVecInt;
34
35 public class DirectEncoding implements Encoding {
36
37 private final IVecInt clause = new VecInt();
38
39 private static final Encoding instance = new DirectEncoding();
40
41 private DirectEncoding() {
42
43 }
44
45 public static Encoding instance() {
46 return instance;
47 }
48
49 public void onFinish(ISolver solver, IVec<Var> scope) {
50 }
51
52 public void onInit(ISolver solver, IVec<Var> scope) {
53 }
54
55 public void onNogood(ISolver solver, IVec<Var> scope,
56 Map<Evaluable, Integer> tuple) throws ContradictionException {
57 clause.clear();
58 Var v;
59 for (int i = 0; i < scope.size(); i++) {
60 v = scope.get(i);
61 clause.push(-v.translate(tuple.get(v)));
62 }
63 solver.addClause(clause);
64
65 }
66
67 public void onSupport(ISolver solver, IVec<Var> scope,
68 Map<Evaluable, Integer> tuple) {
69 }
70
71 }