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.branchAndBound()
'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)
branchAndBound(self, doStatistics=0)
isRelaxationAbondoned(self)
isRelaxationDualInfeasible(self)
isRelaxationInfeasible(self)
isRelaxationOptimal(self)
setNodeCompare(self, nodeCompareObject)

Previous topic

CyLP.cy.CyCoinPackedMatrix

Next topic

CyLP.cy.CyCoinModel

This Page