cylp.cy.CyCbcModel

class cylp.cy.CyCbcModel.CyCbcModel[source]

Interfaces CbcModel. To solve a first you create a cylp.cy.CyClpSimplex object either by reading it from an mps file using CyClpSimplex.readMps() or by using cylp modeling tool cylp.py.modeling.CyLPModel. Then you ask the object for a CyCbcModel which is capable solving MIPs using B&B

Usage

>>> import numpy as np
>>> from cylp.cy import CyCbcModel, CyClpSimplex
>>> from cylp.py.modeling.CyLPModel import CyLPModel, CyLPArray
>>> model = CyLPModel()
>>>
>>> x = model.addVariable('x', 3, isInt=True)
>>> y = model.addVariable('y', 2)
>>>
>>> A = np.array([[1., 2., 0],[1., 0, 1.]])
>>> B = np.array([[1., 0, 0], [0, 0, 1.]])
>>> D = np.array([[1., 2.],[0, 1]])
>>> a = CyLPArray([5, 2.5])
>>> b = CyLPArray([4.2, 3])
>>> x_u= CyLPArray([2., 3.5])
>>>
>>> model += A @ x <= a
>>> model += 2 <= B @ x + D @ y <= b
>>> model += y >= 0
>>> model += 1.1 <= x[1:3] <= x_u
>>>
>>> c = CyLPArray([1., -2., 3.])
>>> model.objective = c * x + 2 * y.sum()
>>>
>>> s = CyClpSimplex(model)
>>>
>>> cbcModel = s.getCbcModel()
>>>
>>> cbcModel.solve()
0
>>> print(cbcModel.status)
solution
>>> sol_x = cbcModel.primalVariableSolution['x']
>>>
>>> (abs(sol_x - np.array([0, 2, 2])) <= 10**-6).all()
True
addCutGenerator(self, CyCglCutGenerator generator, howOften=1, name='', normal=True, atSolution=False, infeasible=False, howOftenInSub=-100, whatDepth=-1, whatDepthInSub=-1)[source]

Add a Cgl cut generator, such as cylp.cy.CyCgl.CyCglGomory. The other arguments are those of CbcModel::addCutGenerator.

addPythonCutGenerator(self, pythonCutGeneratorObject, howOften=1, name='', normal=True, atSolution=False, infeasible=False, howOftenInSub=-100, whatDepth=-1, whatDepthInSub=-1)[source]

Add a cut generator written in Python: an object whose generateCuts(si, cglTreeInfo) method returns a list of cuts. See cylp/py/mip/GomoryCutGenerator.py for an example. The other arguments are those of addCutGenerator().

The cuts must be in terms of the model’s variables, but Cbc calls generateCuts on the problem after its preprocessing, which can have fewer rows and columns. See issue 255.

If generateCuts raises an exception, Cbc finishes its search without calling it again, and solve() then raises the exception.

allowableFractionGap[source]

Stop when the gap between the objective value of the best solution and bestPossibleObjValue is less than this fraction of the absolute value of the best solution’s objective value.

allowableGap[source]

Stop when the gap between the objective value of the best solution and bestPossibleObjValue is less than this.

allowablePercentageGap[source]

allowableFractionGap as a percentage.

bestPossibleObjValue[source]

A bound on the optimal objective value: the best of the best possible value left in the branch-and-bound tree and the best solution found.

dualColumnSolution[source]

Variables’ reduced costs as one array, in column order. Unlike dualVariableSolution, it is not split up by variable. A copy.

Return type:

Numpy array

dualConstraintSolution[source]

Dual variables’ solution. Once solve() has found a solution, Cbc fixes the integer variables at their values in it and solves the LP relaxation again, so these are the duals of that LP.

Return type:

Numpy array

dualVariableSolution[source]

Variables’ reduced costs. See dualConstraintSolution for the LP that they belong to.

Return type:

Numpy array

integerTolerance[source]

How far from an integer an integer variable’s value can be and still count as an integer.

isRelaxationAbandoned(self)[source]

Whether Cbc gave up on the LP relaxation it solved first because of numerical difficulties.

isRelaxationDualInfeasible(self)[source]

Whether Cbc proved that the LP relaxation it solved first is dual infeasible, i.e. unbounded if it’s feasible.

isRelaxationInfeasible(self)[source]

Whether Cbc proved that the LP relaxation it solved first is infeasible.

isRelaxationOptimal(self)[source]

Whether Cbc solved the LP relaxation it solved first to optimality.

logLevel[source]

How much Cbc prints: 0 for nothing, more for more.

maximumNodes[source]

The maximum number of nodes that solve() explores.

maximumSeconds[source]

The time limit of solve(), in seconds.

maximumSolutions[source]

Stop after finding this many solutions.

nodeCount[source]

The number of nodes of the branch-and-bound tree that Cbc explored.

numberHeuristicSolutions[source]

The number of solutions that Cbc’s heuristics found.

numberObjects[source]

The number of objects that Cbc branches on, such as integer variables. It is 0 until solve() creates them.

numberThreads[source]

The number of threads that Cbc uses, if it was built with threads. 0 means the default.

objectiveValue[source]

The objective value of the best solution found.

osiSolverInteface[source]

The solver that Cbc uses for the LP relaxations, as a cylp.cy.CyOsiSolverInterface.CyOsiSolverInterface.

primalColumnSolution[source]

Solution to the primal variables as one array, in column order. Unlike primalVariableSolution, it is not split up by variable, which is much faster for large models. A copy.

Return type:

Numpy array

primalConstraintSolution[source]

Constraints’ activities, i.e. the value of each constraint’s left-hand side at the solution.

Return type:

Numpy array

primalVariableSolution[source]

Solution to the primal variables.

Return type:

Numpy array

setNodeCompare(self, nodeCompareObject)[source]

Use nodeCompareObject, a cylp.py.mip.NodeCompareBase, to choose the next node of the branch-and-bound tree to explore.

solutionCount[source]

The number of solutions that Cbc found.

solve(self)[source]

Call CbcMain. Solve the problem using the same parameters used by CbcSolver. Equivalent to solving the model from the command line using cbc’s binary.

status[source]

The result of solve():

  • 'solution' if Cbc proved that its solution is optimal, or within allowableGap or allowableFractionGap of the optimum,

  • 'relaxation infeasible', 'relaxation abandoned' or 'problem proven infeasible',

  • otherwise, why Cbc stopped: 'stopped on gap', 'stopped on nodes', 'stopped on time', 'stopped on user event', 'stopped on solutions', 'linear relaxation unbounded', 'search completed' or 'unset'.