Commit 875dd60b authored by Lonca Emmanuel's avatar Lonca Emmanuel
Browse files

Simple AllDifferent constraints take much less memory.

parent d1a49f59
Pipeline #167 passed with stage
in 12 minutes and 59 seconds
...@@ -21,6 +21,7 @@ package org.sat4j.csp.constraints3; ...@@ -21,6 +21,7 @@ package org.sat4j.csp.constraints3;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import org.sat4j.csp.intension.ICspToSatEncoder;
import org.sat4j.csp.intension.IIntensionCtrEncoder; import org.sat4j.csp.intension.IIntensionCtrEncoder;
import org.sat4j.reader.XMLCSP3Reader; import org.sat4j.reader.XMLCSP3Reader;
import org.xcsp.common.Types.TypeOperatorRel; import org.xcsp.common.Types.TypeOperatorRel;
...@@ -40,19 +41,20 @@ public class ComparisonCtrBuilder { ...@@ -40,19 +41,20 @@ public class ComparisonCtrBuilder {
public ComparisonCtrBuilder(IIntensionCtrEncoder intensionEnc) { public ComparisonCtrBuilder(IIntensionCtrEncoder intensionEnc) {
this.intensionCtrEncoder = intensionEnc; this.intensionCtrEncoder = intensionEnc;
} }
public boolean buildCtrAllDifferent(XVarInteger[] list) { // TODO: public boolean buildCtrAllDifferent(XVarInteger[] list) {
// remove final ICspToSatEncoder solver = this.intensionCtrEncoder.getSolver();
// dependence
// to
// varmapping
for (int i = 0; i < list.length - 1; ++i) { for (int i = 0; i < list.length - 1; ++i) {
final String norm1 = CtrBuilderUtils.normalizeCspVarName(list[i].id); final int[] d1 = solver.getCspVarDomain(list[i].id);
for (int j = i + 1; j < list.length; ++j) { for (int j = i + 1; j < list.length; ++j) {
final String norm2 = CtrBuilderUtils.normalizeCspVarName(list[j].id); final int[] d2 = solver.getCspVarDomain(list[j].id);
final String expr = "ne(" + norm1 + "," + norm2 + ")"; for(int v1 : d1) {
if (this.intensionCtrEncoder.encode(expr)) for(int v2 : d2) {
return true; if(v1 == v2) {
solver.addClause(new int[]{-solver.getSolverVar(list[i].id, v1), -solver.getSolverVar(list[j].id, v2)});
}
}
}
} }
} }
return false; return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment