cylp.cy.CyCbcModel¶
- class cylp.cy.CyCbcModel.CyCbcModel[source]¶
Interfaces
CbcModel. To solve a first you create acylp.cy.CyClpSimplexobject either by reading it from anmpsfile usingCyClpSimplex.readMps()or by using cylp modeling toolcylp.py.modeling.CyLPModel. Then you ask the object for aCyCbcModelwhich is capable solving MIPs using B&BUsage
>>> 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 ofCbcModel::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. Seecylp/py/mip/GomoryCutGenerator.pyfor an example. The other arguments are those ofaddCutGenerator().The cuts must be in terms of the model’s variables, but Cbc calls
generateCutson the problem after its preprocessing, which can have fewer rows and columns. See issue 255.If
generateCutsraises an exception, Cbc finishes its search without calling it again, andsolve()then raises the exception.
- allowableFractionGap[source]¶
Stop when the gap between the objective value of the best solution and
bestPossibleObjValueis 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
bestPossibleObjValueis less than this.
- allowablePercentageGap[source]¶
allowableFractionGapas 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
dualConstraintSolutionfor 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.
- 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.
- 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
- setNodeCompare(self, nodeCompareObject)[source]¶
Use
nodeCompareObject, acylp.py.mip.NodeCompareBase, to choose the next node of the branch-and-bound tree to explore.
- 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 withinallowableGaporallowableFractionGapof 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'.