/
AllDifferentBinary.java
40 lines (34 loc) · 1.17 KB
/
AllDifferentBinary.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* mini-cp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3
* as published by the Free Software Foundation.
*
* mini-cp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mini-cp. If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
*
* Copyright (c) 2018. by Laurent Michel, Pierre Schaus, Pascal Van Hentenryck
*/
package minicp.engine.constraints;
import minicp.engine.core.AbstractConstraint;
import minicp.engine.core.IntVar;
import minicp.engine.core.Solver;
public class AllDifferentBinary extends AbstractConstraint {
private IntVar[] x;
public AllDifferentBinary(IntVar... x) {
super(x[0].getSolver());
this.x = x;
}
@Override
public void post() {
Solver cp = x[0].getSolver();
for (int i = 0; i < x.length; i++) {
for (int j = i + 1; j < x.length; j++) {
cp.post(new NotEqual(x[i], x[j]), false);
}
}
}
}