|
1 |
| package org.sat4j.reader.csp; |
|
2 |
| |
|
3 |
| |
|
4 |
| import org.sat4j.core.VecInt; |
|
5 |
| import org.sat4j.specs.ContradictionException; |
|
6 |
| import org.sat4j.specs.ISolver; |
|
7 |
| import org.sat4j.specs.IVecInt; |
|
8 |
| |
|
9 |
| |
|
10 |
| public class Nogoods implements Relation { |
|
11 |
| |
|
12 |
| private final int[] domains; |
|
13 |
| |
|
14 |
| private int[][] tuples; |
|
15 |
| |
|
16 |
0
| public Nogoods(int[] domains, int nbtuples) {
|
|
17 |
0
| this.domains = domains;
|
|
18 |
0
| tuples = new int[nbtuples][];
|
|
19 |
| } |
|
20 |
| |
|
21 |
0
| public void addTuple(int index, int[] tuple) {
|
|
22 |
0
| tuples[index] = tuple;
|
|
23 |
| } |
|
24 |
| |
|
25 |
0
| public void toClause(ISolver solver, Var[] vars)
|
|
26 |
| throws ContradictionException { |
|
27 |
0
| IVecInt clause = new VecInt();
|
|
28 |
0
| for (int i = 0; i < tuples.length; i++) {
|
|
29 |
0
| clause.clear();
|
|
30 |
0
| for (int j = 0; j < domains.length; j++) {
|
|
31 |
0
| clause.push(-vars[j].translate(tuples[i][j]));
|
|
32 |
| } |
|
33 |
| |
|
34 |
0
| solver.addClause(clause);
|
|
35 |
| } |
|
36 |
| } |
|
37 |
| |
|
38 |
0
| public int arity() {
|
|
39 |
0
| return domains.length;
|
|
40 |
| } |
|
41 |
| } |