Choco
ChocLet was designed to be interoperable with Choco library.
The global identifier choco
, allows to declare variables, define constraints and solve a model.
Choco binding
The choco
is a binding of a Choco Model
instance, where some function are overriden to ease the usage.
let a = choco.int (0, 10);
// a is an intVar
println (a); //IV_1 = {0,1,2,3,4,5...,10}
Choco Model direct binding
The following function are directly callable with choco
object.
The prototype of the Java function are respected (direct binding).
Tables | alias |
---|---|
int |
intVar |
real |
realVar |
set |
setVar |
bool |
boolVar |
intArray |
intVarArray |
realArray |
realVarArray |
boolArray |
boolVarArray |
Choco custom binding
You can add your own binding to choco Model methods.
in choco {
def allDifferents -> ChocoConstraint;
}
let a = [choco.int (0, 10), choco.int (1, 3)];
choco.allDifferents (a).post ();
Choco model function override
The following function are provided by choco
object.
post (constraints...) -> void | This function will post the constraints to the model
- Parameters :
- constraints, an set of Constraints
- Parameters :
solve () -> bool | This function is a binding of the solve function, it will actually call the following Java code :
- Returns: is the model satisfied by current solution ?
Solver solver = model.getSolver (); return solver.solve ();
- clean () -> void | Clean the model, by removing all the posted variables and constraints
- restart () -> void | Restart the solving search, by calling the solver function restart
- print () -> void | Print the model to the screen
- strategy (varSelect, valSelect[, vars]) -> void | This function is used to monitor the solving execution Described in this section Solving
onOpenNode (onOpen, onClose) -> void
- Parameters :
- onOpen : a function fn () -> void
- onClose : a function fn () -> void
- Parameters :
printStats () -> void
model.getSolver ().printStatistics ();
solveOptimal () -> bool | Solve the problem until the optimal solution is found :
Solution s = new Solution (model); while (model.getSolver ().solve ()) s.record (); boolean feasible = model.getSolver ().isFeasible () == ESat.TRUE; if (feasible) s.restore (); return feasible;
exportJSON (filename) -> void | Export the model to a json file
- Parameters:
- filename : the name of the file in which the exportation will be done
- Parameters: