- How do I add CHOCO to my project?
You just need to add the latest version of CHOCO to your classpath.
- Go to "File/Settings"
- Select "Project Settings
- Click on "Librairies", then on [+]
- Enter "CHOCO" as the name of the library, and "OK"
- Choose your project and "OK"
- Click on "Attach Jar Directories" and select the directory that contains Choco-x.x.x.jar
- Go to "Project/Properties"
- Select "Jave Build Path" on the left menu
- On the right panel, select "Librairies"
- Click on "Add Externals JARs..." button
- Select Choco-x.x.x.jar file
- I can not see APIs of CHOCO!
Add the following code to your class, to see the APIs:
import static choco.Choco.*;
- How do I get the value of variables through the solver?
There are two different kinds of variables: those associated with the Model (like IntegerVariable, SetVariable,…) and those associated with the Solver (like IntDomainVar, SetVar,…). The second type is a Solver interpretation of the first one (which is only declarative). After having defined your model with variables and constraints, it has to be read by the Solver. After that, a Solver object is created. You can access the Variable Model value through the Solver using the following method of the Solver:
where v is a Model variable (or an array of Model variables) and it returns a Solver variable.
- How do I use constante value inside constraint?
Some constraints doesn't provide API with java object (like int, double or Integer). You can define constant variable (ie, variable with one unique value) liek this:
IntegerVariable one = constant(1);
RealVariable one = constant(1.0);
And, you can use this variable inside the constraint:
Model m = new CPModel();
IntegerVariable x = makeIntVar("x", 0, 10);
IntegerVariable two = constant(2);
IntegerVariable maximum = makeIntVar("max", 0, 15);
m.addConstraint(eq(maximum, max(x, two));
Do not forget that some constraints provide api with java object.
- How can I use Choco to solve CSP'08 benchmark?
You can easily load an XML file of the CSP'08 competition and solve it with CHOCO. To load the file, we use the XMLParser available here:
String fileName = "../../ProblemsData/CSPCompet/intension/nonregres/graph1.xml";
File instance = new File(fileName);
XmlModel xs = new XmlModel(); // A class to provide facilities for loading and solving CSP'08 xml file
InstanceParser parser = xs.load(instance); // loading of the CPS'08 xml file
Once the file has been loaded, a Model object is build from the InstanceParser object:
CPModel model = xs.buildModel(parser); // Creation of the model
At this point, you can choose to solve this model with a pre-processing step. The pre-processing step analyzes variables and constraints, makes some specific choices to improve the resolution. Concerning variables, it analyzes domains and constraints and choose what seems to be the best kind of domain (for example, enumerated or bounded domain), or add one variable where large number of variables are equals, ... Concerning constraints, it detects clique of differences or disjunctions and state the corresponding global constraints, breaks symetries, detects distance… Then, it can also choose the search strategy. To do this, use the following code:
PreProcessCPSolver s = xs.solve(model); // Build a BlackBoxSolver and solve it.
Finally, you can print informations concerning the resolution:
xs.postAnalyze(instance, parser, s);
You can easily solve benchmarks of CSP'08 competition, or with your own problem modelize inCSP'08 xml format.
- Why do I have a error when I add my constraint?
If you have a error message like this:
Component class could not be found: my.package.and.my.Constraint.ConstraintManager
and if the ConstraintManager is an inner class of your constraint, you must define the name in the component name like this:
For more details, see the documentation.
- Are bounds with positive and negative infinity supported within CHOCO?
Integer or Double bounds are not really appreciate in CHOCO. Because, during propgation, a basic test is done on bounds and the following operation can be applied: “upper bound +1”. Integer.MAX_VALUE+1 is equal to …Integer.MIN_VALUE, and it corrupts the propagation. If you really want to have a large domain, a division with 10 should be sufficient:
IntegerVariable v1 = makeIntVar("v1", Integer.MIN_VALUE/10, Integer.MIN_VALUE/10);
// equivalent to:
IntegerVariable v1 = makeIntVar("v1");
RealVariable a1 = makeRealVar("A1", Double.NEGATIVE_INFINITY/10, Double.POSITIVE_INFINITY/10);
- I'm working with the sources in Eclipse environment, and I get "new sun.security.action.GetPropertyAction("line.separator"));" error
You have to define an access rule to allow the access of the constructor GetPropertyAction(String) to Eclipse.
- Go intoProject/Properties/Java build path, on the Librairies tab
- Select your JRE and left-clic on Access rules
- Edit this entry to set sun.security.action accessible