CPMpy pumpkin interface (cpmpy.solvers.pumpkin)

Interface to Pumpkin’s API

Pumpkin is a combinatorial optimisation solver developed by the ConSol Lab at TU Delft. It is based on the (lazy clause generation) constraint programming paradigm. (see https://github.com/consol-lab/pumpkin)

Always use cp.SolverLookup.get("pumpkin") to instantiate the solver object.

Installation

Requires that the ‘pumpkin-solver’ python package is installed:

$ pip install pumpkin-solver

The rest of this documentation is for advanced users

List of classes

CPM_pumpkin

Interface to Pumpkin's API

Module details

class cpmpy.solvers.pumpkin.CPM_pumpkin(cpm_model=None, subsolver=None)[source]

Interface to Pumpkin’s API

Creates the following attributes (see parent constructor for more):

  • pum_solver: the pumpkin.Model() object

add(cpm_expr_orig)[source]

Eagerly add a constraint to the underlying solver.

Any CPMpy expression given is immediately transformed (through transform()) and then posted to the solver in this function.

This can raise ‘NotImplementedError’ for any constraint not supported after transformation

The variables used in expressions given to add are stored as ‘user variables’. Those are the only ones the user knows and cares about (and will be populated with a value after solve). All other variables are auxiliary variables created by transformations.

Parameters:

cpm_expr (Expression or list of Expression) – CPMpy expression, or list thereof

Returns:

self

get_core()[source]

For use with s.solve(assumptions=[...]). Only meaningful if the solver returned UNSAT. In that case, get_core() returns a small subset of assumption variables that are unsat together.

CPMpy will return only those variables that are False (in the UNSAT core)

Note

Note that there is no guarantee that the core is minimal, though this interface does open up the possibility to add more advanced Minimal Unsatisfiabile Subset algorithms on top. All contributions welcome!

has_objective()[source]

Returns whether the solver has an objective function or not.

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=True)[source]

Post the given expression to the solver as objective to minimize/maximize

Parameters:
  • 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

Note

technical side note: any constraints created during conversion of the objective are premanently posted to the solver

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: List[_NumVarImpl], vals: List[int | bool])

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: float | None = None, prove=False, proof_name='proof.drcp', proof_location='.', assumptions: List[_BoolVarImpl] | None = None)[source]

Call the Pumpkin solver

Parameters:
  • time_limit (float, optional) – maximum solve time in seconds

  • prove – whether to produce a DRCP proof (.lits file and .drcp proof file).

  • proof_name – name for the the proof files.

  • proof_location – location for the proof files (default to current working directory).

  • assumptions – CPMpy Boolean variables (or their negation) that are assumed to be true. For repeated solving, and/or for use with s.get_core(): if the model is UNSAT, get_core() returns a small subset of assumption variables that are unsat together.

solveAll(display: Expression | List[Expression] | Callable | None = None, time_limit: float | None = None, solution_limit: int | None = None, call_from_model=False, **kwargs)

Compute all solutions and optionally display the solutions.

This is the generic implementation, solvers can overwrite this with a more efficient native implementation

Parameters:
  • display (-) – either a list of CPMpy expressions, OR a callback function, called with the variables after value-mapping default/None: nothing displayed

  • time_limit (-) – stop after this many seconds (default: None)

  • solution_limit (-) – stop after this many solutions (default: None)

  • call_from_model (-) – whether the method is called from a CPMpy Model instance or not

  • argument (- any other keyword)

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:

Solver support by current system setup.

Return type:

[bool]

supported_global_constraints: frozenset[str] = frozenset({'InDomain', 'abs', 'alldifferent', 'cumulative', 'div', 'element', 'max', 'min', 'negative_table', 'no_overlap', 'table'})
supported_reified_global_constraints: frozenset[str] = frozenset({})
to_predicate(cpm_expr, tag=None)[source]

Convert a CPMpy expression to a Pumpkin predicate (comparison with constant)

to_pum_ivar(cpm_var, tag=None)[source]

Helper function to convert (boolean) variables and constants to Pumpkin integer expressions

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

static version() str | None[source]

Returns the installed version of the solver’s Python API.