Solver utilities (cpmpy.solvers.utils)

Utilities for handling solvers

List of functions

param_combinations

Recursively yield all combinations of param values

class cpmpy.solvers.utils.SolverLookup[source]
classmethod base_solvers()[source]

Return ordered list of (name, class) of base CPMpy solvers

First one is default

classmethod get(name=None, model=None, **init_kwargs)[source]

get a specific solver (by name), with ‘model’ passed to its constructor

This is the preferred way to initialise a solver from its name

Parameters:
  • name – name of the solver to use

  • model – model to pass to the solver constructor

  • init_kwargs – additional keyword arguments to pass to the solver constructor

classmethod lookup(name=None)[source]

lookup a solver _class_ by its name

warning: returns a ‘class’, not an object! see get() for normal uses

classmethod print_status()[source]

Print all CPMpy solvers and their installation status on this system.

classmethod solvernames()[source]
classmethod supported()[source]

Return the list of names of all solvers (and subsolvers) supported on this system.

If a solver name is returned, it means that the solver’s .supported() function returns True and it is hence ready for immediate use (e.g. any separate binaries are also installed if necessary, and licenses are active if needed).

Typical use case is to use these names in SolverLookup.get(name).

cpmpy.solvers.utils.get_supported_solvers()[source]

Returns a list of solvers supported on this machine.

Deprecated since version 0.9.4: Please use SolverLookup object instead.

Returns:

a list of SolverInterface sub-classes :list[SolverInterface]:

cpmpy.solvers.utils.param_combinations(all_params, remaining_keys=None, cur_params=None)[source]

Recursively yield all combinations of param values

For example usage, see examples/advanced/hyperparameter_search.py https://github.com/CPMpy/cpmpy/blob/master/examples/advanced/hyperparameter_search.py

  • all_params is a dict of {key: list} items, e.g.: {'val': [1,2], 'opt': [True,False]}

  • output is an generator over all {key:value} combinations of the keys and values. For the example above: generator([{'val':1,'opt':True},{'val':1,'opt':False},{'val':2,'opt':True},{'val':2,'opt':False}])