Help save net neutrality! Learn more.

## import for Constraint document.SUBSCRIPTION_OPTIONS = { "thing": "thread", "subscribed": false, "url": "subscribe", "icon": { "css": "fa fa-envelope-o" } };

Help
2009-10-12
2013-04-06
• Patrick Prosser - 2009-10-12

What do I have to import so that I can do the following?

Constraint exp = or(neq(z, y),  leq(z,9) );

• Arnaud Malapert - 2009-10-12

import choco.Choco.*;

Best regards,
Arnaud

• Julien Menana - 2009-10-12

import static choco.Choco.*;

• Patrick Prosser - 2009-10-12

That doesn't work. This appers to be the minimal set of imports (below). How can it be reduced? (I am accessing the jar file via environment variables and running from a command line (old school or what))

//
// Compare propagation of allDiff with clique of neq
// Note: problem is insoluble
//

import static choco.Choco.*;
import choco.cp.model.CPModel;
import choco.cp.solver.CPSolver;
import choco.kernel.model.Model;
import choco.kernel.solver.Solver;
import choco.kernel.model.variables.integer.IntegerExpressionVariable;
import choco.kernel.model.variables.integer.IntegerVariable;
import choco.kernel.solver.ContradictionException;

import choco.kernel.model.constraints.Constraint;

public class Prop0 {

public static void main(String args) throws ContradictionException {

Model m = new CPModel();
IntegerVariable x = makeIntVar(&quot;X&quot;,1,2);
IntegerVariable y = makeIntVar(&quot;Y&quot;,1,2);
IntegerVariable z = makeIntVar(&quot;Z&quot;,1,2);

Constraint c_xy = neq(x,y);
Constraint c_xz = neq(x,z);
Constraint c_yz = neq(y,z);

m.addConstraint(c_xy);
m.addConstraint(c_xz);
m.addConstraint(c_yz);

System.out.println(m.pretty());

Solver s = new CPSolver();
s.read(m);
s.propagate();

System.out.println(s.pretty());   // propagation has no effect

System.out.println(s.solve());
}
}

• Hi,

What doesn't work?

You cannot reduce the import more than what you have done:

import static choco.Choco.*;
import choco.cp.model.CPModel;
import choco.cp.solver.CPSolver;
import choco.kernel.model.constraints.Constraint;
import choco.kernel.model.variables.integer.IntegerVariable;
import choco.kernel.model.Model;
import choco.kernel.solver.ContradictionException;
import choco.kernel.solver.Solver;

Hope it helps,

Charles

• Sorry, you can reduce it by using only CPxxx object and avoid declaring Constraint objects.

import static choco.Choco.*;
import choco.cp.model.CPModel;
import choco.cp.solver.CPSolver;
import choco.kernel.model.variables.integer.IntegerVariable;
import choco.kernel.solver.ContradictionException;

public class sandbox {

public static void main(String args) throws ContradictionException {

CPModel m = new CPModel();
IntegerVariable x = makeIntVar(&quot;X&quot;,1,2);
IntegerVariable y = makeIntVar(&quot;Y&quot;,1,2);
IntegerVariable z = makeIntVar(&quot;Z&quot;,1,2);

m.addConstraint(neq(x,y));
m.addConstraint(neq(x,z));
m.addConstraint(neq(y,z));

System.out.println(m.pretty());

CPSolver s = new CPSolver();
s.read(m);
s.propagate();

System.out.println(s.pretty());   // propagation has no effect

System.out.println(s.solve());
System.out.println(s.pretty());

}
}

Charles

Log in to post a comment.