Solvers¶

Abstract solver class. 

Interface to the Gecode solver. 

Interface to the Chuffed solver. 

Interface to the Optimathsat solver. 

Interface to the Opturion CPX solver. 

Generic interface to MIP solvers. 

Interface to the Gurobi solver. 

Interface to the COINOR CBC solver. 

Interface to the Oscar/CBLS solver. 

Interface to the ORtools solver. 
Interface to the Gecode solver. 

Interface to the Chuffed solver. 

Interface to the Optimathsat solver. 

Interface to the Opturion CPX solver. 

Interface to the Gurobi solver. 

Interface to the COINOR CBC solver. 

Interface to the Oscar/CBLS solver. 

Interface to the ORtools solver. 
PyMzn interfaces with solvers through the Solver
base class. This class
includes the necessary infomation for PyMzn to setup the solver, and provides
two main functions to support custom solver arguments and parsing the solution
stream of the solver.
PyMzn provides a number of solver implementations outofthebox. PyMzn’s
default solver is pymzn.gecode
, an instance of pymzn.Gecode
.
To use a solver that is not provided by PyMzn or to extend an existing one, one
has to subclass the Solver
class and implement the args
method, which
returns a list of command line arguments for executing the process. The
command line arguments supported by this function have to be paired with proper
extraFlags
in the solver configuration file (see the solver configuration
files page
from the MiniZinc reference manual for additional details).
For instance, suppose you have the following configuration file for an external
solver, my_solver.msc
:
{
"name" : "My Solver",
"version": "1.0",
"id": "org.myorg.my_solver",
"executable": "fznmysolver"
}
You want to support the command line argument solvetwiceasfast
. First
you need to add the flag into the solver configuration file:
{
"name" : "My Solver",
"version": "1.0",
"id": "org.myorg.my_solver",
"executable": "fznmysolver",
"extraFlags": [
["solvetwiceasfast", "provides twofold speedup", "bool", "false"]
]
}
This will make the argument available to the minizinc
executable when using
the solver my_solver
. Next, to add this option to PyMzn, you need to
subclass the Solver
class and override the args
function:
1 2 3 4 5 6 7 8 9 10 11  from pymzn import Solver
class MySolver(Solver):
def __init__(self):
super().__init__(solver_id='my_solver')
def args(self, solve_twice_as_fast=False, **kwargs):
args = super().args(**kwargs)
if solve_twice_as_fast:
args.append('solvetwiceasfast')
return args

It is then possible to run the minizinc
function with the custom solver:
my_solver = MySolver()
pymzn.minizinc('test.mzn', solver=my_solver, solve_twice_as_fast=True)