The docs for
ift say that it returns "if(b, y1, y2)", so I was surprised to see that it apparently also disallows y1 from being equal to y2. I would have expected that if b were true, y2 would be unconstrained -- is this not the normal meaning of "if"?
Below is a demonstration of what I mean. It sets up a constraint like "n = if(p, a, b)", and propagates two time, once starting with p unconstrained ("p = [0, 1]") and once with p set to true ("p = 1"). In both cases a starts as "a = 2" and b starts as "b = {1..3}", and I would expect it to remain that way after propagation. However when p = 1, b is changed to exclude 2 (that is, "b = {1, 3}") -- why should this be?
import org.chocosolver.solver.Model;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
public class IftExample {
public static void iftExample(Model m, BoolVar p) {
IntVar n = m.intVar ("n", -10, 10);
IntVar a = m.intVar ("a", new int[]{2});
IntVar b = m.intVar ("b", new int[]{1, 2, 3});
n.eq(p.ift(a, b)).post();
try {
m.getSolver().propagate();
System.out.println(m.toString());
}
catch(ContradictionException ex) {
System.out.println("contradiction!");
}
}
public static void main(String args[]) {
// First with an unconstrained predicate
Model mA = new Model();
BoolVar pA = mA.boolVar("pA");
iftExample(mA, pA);
// Now with predicate set to true
Model mB = new Model();
BoolVar pB = mB.boolVar("pB", true);
iftExample(mB, pB);
}
}
If this is intended behavior, perhaps the docs for ift could be clarified?
Thanks,
--Chouser