padawan
padawan

Reputation: 1315

Using or constraint for RealVariables in Choco 2

I use Choco 2.1.5 with Eclipse IDE in Windows 8.1

When I compile the code below:

CPModel m = new CPModel();
m.setDefaultExpressionDecomposition(false);
RealVariable A = Choco.makeRealVar("a", -5.5, 5.5);
RealVariable B = Choco.makeRealVar("b", -4.4, 4.4);
RealVariable C = Choco.makeRealVar("c", -3.3, 3.3);
m.addConstraint(Choco.or(
        Choco.eq(A, Choco.plus(B,C)),
        Choco.eq(B, Choco.plus(A,C)),
        Choco.eq(C, Choco.plus(A,B))
        ));
CPSolver solver = new CPSolver();
solver.read(m);
System.out.println(solver.solve());

I get the following output:

Exception in thread "main" java.lang.UnsupportedOperationException
    at choco.kernel.solver.constraints.AbstractSConstraint.opposite(AbstractSConstraint.java:270)
    at choco.cp.solver.CPModelToCPSolver.makeSConstraintAndOpposite(CPModelToCPSolver.java:335)
    at choco.cp.solver.CPModelToCPSolver.createGenericMetaConstraint(CPModelToCPSolver.java:457)
    at choco.cp.solver.CPModelToCPSolver.createMetaConstraint(CPModelToCPSolver.java:432)
    at choco.cp.solver.CPModelToCPSolver.readModelConstraint(CPModelToCPSolver.java:353)
    at choco.cp.solver.CPModelToCPSolver.readConstraints(CPModelToCPSolver.java:292)
    at choco.cp.solver.CPSolver.read(CPSolver.java:519)
    at coverbylines.Test.main(Test.java:88)

But when I try with IntegerVariables, I don't get any errors. What would be the problem? Is there anyway around this?

Upvotes: 0

Views: 200

Answers (1)

cprudhom
cprudhom

Reputation: 111

Not all constraints can be reified safely in Choco2, only a subset of them can be safely reified. Real constraints are not part of that sub-set, and Choco.or(...) induces reification. Have a look at Choco3 wherein any constraints can reified, even real constraints (which implies, though, to install a third-party library, Ibex).

Upvotes: 1

Related Questions