cylp.cy.CyCbcModel

class cylp.cy.CyCbcModel.CyCbcModel

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.matrix([[1., 2., 0],[1., 0, 1.]])
>>> B = np.matrix([[1., 0, 0], [0, 0, 1.]])
>>> D = np.matrix([[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)
addPythonCutGenerator(self, pythonCutGeneratorObject, howOften=1, name='', normal=True, atSolution=False, infeasible=False, howOftenInSub=-100, whatDepth=-1, whatDepthInSub=-1)
isRelaxationAbondoned(self)
isRelaxationDualInfeasible(self)
isRelaxationInfeasible(self)
isRelaxationOptimal(self)
setNodeCompare(self, nodeCompareObject)
solve(self)

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.