Skip to content

Commit

Permalink
Fix #1090
Browse files Browse the repository at this point in the history
  • Loading branch information
cprudhom committed May 7, 2024
1 parent 27988eb commit 5ebd7a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,17 @@ public ESat isEntailed() {
for (int i = 0; i < n; i++) {
if (!(vars[i].isInstantiated() && vars[i + n].isInstantiated())) {
allInst = false;
break;
}
if (X[i].isInstantiated() && !Y[X[i].getValue() - minX].contains(i + minY)) {
return ESat.FALSE;
if (X[i].isInstantiated()) {
int x = X[i].getValue() - minX;
if (x < 0 || x >= n) return ESat.FALSE;
if (!Y[x].contains(i + minY) && Y[x].isInstantiated()) return ESat.FALSE;
}
if (Y[i].isInstantiated() && !X[Y[i].getValue() - minY].contains(i + minX)) {
return ESat.FALSE;
if (Y[i].isInstantiated()) {
int y = Y[i].getValue() - minY;
if (y < 0 || y >= n) return ESat.FALSE;
if (!X[y].contains(i + minX) && X[i].isInstantiated()) return ESat.FALSE;
}
}
if (allInst) return ESat.TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
*/
package org.chocosolver.solver.constraints.nary;

import org.chocosolver.solver.Settings;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Settings;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.exception.SolverException;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.util.ESat;
import org.testng.Assert;
Expand Down Expand Up @@ -124,4 +126,30 @@ public void test00() {
solver.findAllSolutions();
Assert.assertEquals(10, solver.getSolutionCount());
}

@Test(groups = "1s")
public void test01(){
Model model = new Model();
IntVar[] fwd = model.intVarArray(2, -2, 2);
IntVar[] rev = model.intVarArray(2, -2, 2);
Constraint cons = model.inverseChanneling(fwd, rev);
BoolVar bv = cons.reify();
model.arithm(bv, "=", 0).post();
Solver solver = model.getSolver();
while(solver.solve());
Assert.assertEquals(solver.getSolutionCount(), 623);
}

@Test(groups = "1s")
public void test02() {
Model model = new Model();
IntVar[] fwd = model.intVarArray(2, -2, 2);
IntVar[] rev = model.intVarArray(2, -2, 2);
Constraint cons = model.inverseChanneling(fwd, rev);
BoolVar bv = cons.reify();
model.arithm(bv, "=", 1).post();
Solver solver = model.getSolver();
while (solver.solve()) ;
Assert.assertEquals(solver.getSolutionCount(), 2);
}
}

0 comments on commit 5ebd7a3

Please sign in to comment.