Menu

Logic constraints with SetVariables

Mikael
2011-11-21
2013-04-06
  • Mikael

    Mikael - 2011-11-21

    Hello!

    I am using choco 2.1.3 and the constraints implies, ifOnlyIf … don't seem to work with constraints that involve SetVariables.

    import java.util.Arrays;
    import choco.Choco;
    import choco.cp.model.CPModel;
    import choco.cp.solver.CPSolver;
    import choco.kernel.model.variables.integer.IntegerVariable;
    import choco.kernel.model.variables.set.SetVariable;
    public class TestImplies {
        public static void main(String[] args) {
    
            CPSolver s = new CPSolver();
            CPModel m = new CPModel();
    
            SetVariable set = Choco.constant(new int[]{1,2,3});
            IntegerVariable x = Choco.makeIntVar("x", 1, 3);
            IntegerVariable y = Choco.makeIntVar("y", 0, 10);
            m.addConstraint(Choco.implies(Choco.member(x, set), Choco.eq(y, 5)));
    
            s.read(m);
            s.solve();
    
            System.out.println(Arrays.toString(set.getValues()));
            System.out.println(s.getVar(x).getVal());
            System.out.println(s.getVar(y).getVal());
        }
    }
    

    In the test, the variable x is a member of the set but the eq constraint isn't applied on the variable y.

     
  • Charles Prud'homme

    Hi,

    Thank you for the bug detection.

    I've fixed it in the trunk (but not commited yet).

    I let you know when the release will be ready.

    Hope it helps;

    CP

     

Log in to post a comment.