CPMpy exact interface (cpmpy.solvers.choco)
Interface to Choco solver’s Python API
Requires that the ‘pychoco’ python package is installed:
$ pip install pychoco
Documentation of the solver’s own Python API: https://pypi.org/project/pychoco/ https://pychoco.readthedocs.io/en/latest/
List of classes
Interface to the Choco solver python API |
Module details
- class cpmpy.solvers.choco.CPM_choco(cpm_model=None, subsolver=None)[source]
Interface to the Choco solver python API
Requires that the ‘pychoco’ python package is installed: $ pip install pychoco
See detailed installation instructions at: https://pypi.org/project/pychoco/ https://pychoco.readthedocs.io/en/latest/
Creates the following attributes (see parent constructor for more): chc_model: the pychoco.Model() created by _model() chc_solver: the choco Model().get_solver() instance used in solve()
- get_core()
For use with s.solve(assumptions=[…]). Only meaningful if the solver returned UNSAT.
Typically implemented in SAT-based solvers
Returns a small subset of assumption literals that are unsat together. (a literal is either a _BoolVarImpl or a NegBoolView in case of its negation, e.g. x or ~x) Setting these literals to True makes the model UNSAT, setting any to False makes it SAT
- maximize(expr)
Post the given expression to the solver as objective to maximize
maximize() can be called multiple times, only the last one is stored
- minimize(expr)
Post the given expression to the solver as objective to minimize
minimize() can be called multiple times, only the last one is stored
- property native_model
Returns the solver’s underlying native model (for direct solver access).
- objective(expr, minimize)[source]
Post the given expression to the solver as objective to minimize/maximize
expr: Expression, the CPMpy expression that represents the objective function
minimize: Bool, whether it is a minimization problem (True) or maximization problem (False)
‘objective()’ can be called multiple times, only the last one is stored
(technical side note: constraints created during conversion of the objective are premanently posted to the solver. Choco accepts variables to maximize or minimize so it is needed to post constraints and create auxiliary variables)
- objective_value()
Returns the value of the objective function of the latest solver run on this model
- Returns:
an integer or ‘None’ if it is not run, or a satisfaction problem
- solution_hint(cpm_vars, vals)
For warmstarting the solver with a variable assignment
Typically implemented in SAT-based solvers
- Parameters:
cpm_vars – list of CPMpy variables
vals – list of (corresponding) values for the variables
- solve(time_limit=None, **kwargs)[source]
Call the Choco solver
Arguments: - time_limit: maximum solve time in seconds (float, optional) - kwargs: any keyword argument, sets parameters of solver object
- solveAll(display=None, time_limit=None, solution_limit=None, call_from_model=False, **kwargs)[source]
Compute all (optimal) solutions, map them to CPMpy and optionally display the solutions.
- Arguments:
- display: either a list of CPMpy expressions, OR a callback function, called with the variables after value-mapping
default/None: nothing displayed
solution_limit: stop after this many solutions (default: None)
time_limit: maximum solve time in seconds (float, default: None)
Returns: number of solutions found
- solver_var(cpm_var)[source]
Creates solver variable for cpmpy variable or returns from cache if previously created
- solver_vars(cpm_vars)
Like solver_var() but for arbitrary shaped lists/tensors
- status()
- static supported()[source]
Check for support in current system setup. Return True if the system has package installed or supports solver, else returns False.
- Returns:
[bool]: Solver support by current system setup.
- transform(cpm_expr)[source]
Transform arbitrary CPMpy expressions to constraints the solver supports
Implemented through chaining multiple solver-independent transformation functions from the cpmpy/transformations/ directory.
See the ‘Adding a new solver’ docs on readthedocs for more information.
- Parameters:
cpm_expr (Expression or list of Expression) – CPMpy expression, or list thereof
- Returns:
list of Expression