Menu

Error running the example from Documentation

Anonymous
2012-12-11
2013-04-06
  • Anonymous

    Anonymous - 2012-12-11

    I'm running Choco 2.1.5. I tried out the example on page 24 of the official Documentation.

    public static void main(String[] args) throws Exception {
            ChocoLogging.toSearch();
            Model m = new CPModel();
            IntegerVariable x = makeIntVar("x", 1, 100);
            IntegerVariable y = makeIntVar("y", 1, 100);
            IntegerVariable z = makeIntVar("z", 1, 100);
            IntegerVariable a = makeIntVar("a", 1, 100);
            IntegerVariable b = makeIntVar("b", 1, 100);
            IntegerVariable c = makeIntVar("c", 1, 100);
            m.addConstraint(ifOnlyIf(or(eq(x, mult(10, abs(y))), leq(z, 9)),
                    allDifferent(a, b, c)));
            Solver s = new CPSolver();
            s.read(m);
            if (s.solve()) {
                System.out.println("***Solution");
                System.out.println(s.solutionToString());
            } else {
                System.out.println("***No solution");
            }
        }
    

    It throws an exception.

    Exception in thread "main" java.lang.UnsupportedOperationException
    at choco.kernel.solver.constraints.AbstractSConstraint.opposite(AbstractSConstraint.java:270)
    at choco.cp.solver.constraints.reified.ReifiedFactory.builder(ReifiedFactory.java:59)
    at choco.cp.solver.constraints.reified.leaves.ConstraintLeaf.extractResult(ConstraintLeaf.java:85)
    at choco.cp.solver.constraints.reified.leaves.bool.NotNode.extractResult(NotNode.java:58)
    at choco.cp.solver.constraints.reified.leaves.bool.OrNode.extractResult(OrNode.java:67)
    at choco.cp.solver.constraints.reified.leaves.bool.AndNode.extractConstraint(AndNode.java:86)
    at choco.cp.solver.constraints.reified.ExpressionSConstraint.getDecomposition(ExpressionSConstraint.java:281)
    at choco.cp.solver.CPSolver.decisionOnExpression(CPSolver.java:1966)
    at choco.cp.solver.CPSolver.post(CPSolver.java:1895)
    at choco.cp.solver.CPSolver.post(CPSolver.java:1931)
    at choco.cp.solver.CPModelToCPSolver.readConstraints(CPModelToCPSolver.java:296)
    at choco.cp.solver.CPSolver.read(CPSolver.java:519)
    at org.clafer.Test.main(Test.java:85)

    I'm also having trouble with the ifThenElse constraint. Both of the following examples should have solutions but Choco cannot find any solutions.

    public static void main(String[] args) throws Exception {
            ChocoLogging.toSearch();
            Model m = new CPModel();
            SetVariable x = makeSetVar("x", 1, 10);
            m.addConstraint(ifThenElse(TRUE, eqCard(x, 0), leqCard(x, 1)));
            Solver s = new CPSolver();
            s.read(m);
            if (s.solve()) {
                System.out.println("***Solution");
                System.out.println(s.solutionToString());
            } else {
                System.out.println("***No solution");
            }
        }
    
    public static void main(String[] args) throws Exception {
            ChocoLogging.toSearch();
            Model m = new CPModel();
            SetVariable x = makeSetVar("x", 1, 10);
            IntegerVariable i = makeBooleanVar("i");
            m.addConstraint(ifThenElse(eq(i, 1), eqCard(x, 1), eqCard(x, 1)));
            
            Solver s = new CPSolver();
            s.read(m);
            if (s.solve()) {
                System.out.println("***Solution");
                System.out.println(s.solutionToString());
            } else {
                System.out.println("***No solution");
            }
        }
    
     
  • Charles Prud'homme

    Hi,

    Thank you for reporting the bug, the following instruction is missing:

    m.setDefaultExpressionDecomposition(false);
    

    Hope it helps,
    CP

     
  • Anonymous

    Anonymous - 2012-12-14

    If I make a slight modification to the constraint, it fails with the same error. Even with setDefaultExpressionDecomposition set to false. I'm generating lots of the choco constraints programmatically and it feels very brittle.

    ChocoLogging.toSearch();
            
            Model m = new CPModel();
            m.setDefaultExpressionDecomposition(false);
            SetVariable x = makeSetVar("x", 1, 100);
            IntegerVariable a = makeIntVar("a", 1, 100);
            IntegerVariable b = makeIntVar("b", 1, 100);
            IntegerVariable c = makeIntVar("c", 1, 100);
            m.addConstraint(ifOnlyIf(eqCard(x, 0),
                    allDifferent(a, b, c)));
            Solver s = new CPSolver();
            s.read(m);
            if (s.solve()) {
                System.out.println("***Solution");
                System.out.println(s.solutionToString());
            } else {
                System.out.println("***No solution");
            }
    

    Also, anything about the ifOnlyIf failing in the original post?

    Thanks!

     

Log in to post a comment.