当前位置: 首页>>代码示例>>Python>>正文


Python CyClpSimplex.extractCyLPModel方法代码示例

本文整理汇总了Python中cylp.cy.CyClpSimplex.extractCyLPModel方法的典型用法代码示例。如果您正苦于以下问题:Python CyClpSimplex.extractCyLPModel方法的具体用法?Python CyClpSimplex.extractCyLPModel怎么用?Python CyClpSimplex.extractCyLPModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cylp.cy.CyClpSimplex的用法示例。


在下文中一共展示了CyClpSimplex.extractCyLPModel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_removeVar2

# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import extractCyLPModel [as 别名]
    def test_removeVar2(self):
        s = CyClpSimplex()
        fp = os.path.join(currentFilePath, '../../input/p0033.mps')
        s.extractCyLPModel(fp)
        y = s.addVariable('y', 3)
        s.primal()

        x = s.getVarByName('x')
        s.addConstraint(x[1] +  y[1] >= 1.2)
        #s.primal()
        s.removeVariable('x')
        s.primal()
        s = s.primalVariableSolution
        self.assertTrue((s['y'] - np.array([0, 1.2, 0]) <= 10**-6).all())
开发者ID:HerrKevin,项目名称:CyLP,代码行数:16,代码来源:test_modeling.py

示例2: read_instance

# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import extractCyLPModel [as 别名]
def read_instance(module_name = None, file_name = None):

    if module_name is not None:
        lp = CyClpSimplex()

        mip = ilib.import_module(module_name)
            
        A = np.matrix(mip.A)
        #print np.linalg.cond(A)
        b = CyLPArray(mip.b)
        
        #Warning: At the moment, you must put bound constraints in explicitly for split cuts
        x_l = CyLPArray([0 for _ in range(mip.numVars)])
            
        x = lp.addVariable('x', mip.numVars)
        
        lp += x >= x_l
        try:
            x_u = CyLPArray(getattr(mip, 'x_u'))
            lp += x <= x_u
        except:
            pass
        
        lp += (A * x <= b if mip.sense[1] == '<=' else
               A * x >= b)
        c = CyLPArray(mip.c)
        lp.objective = -c * x if mip.sense[0] == 'Max' else c * x
        return lp, x, mip.A, mip.b, mip.sense[1], mip.integerIndices
    elif file_name is not None:
        lp = CyClpSimplex()
        m = lp.extractCyLPModel(file_name)
        x = m.getVarByName('x')
        integerIndices = [i for (i, j) in enumerate(lp.integerInformation) if j == True]
        infinity = lp.getCoinInfinity()
        sense = None
        for i in range(lp.nRows):
            if lp.constraintsLower[i] > -infinity:
                if sense == '<=':
                    print "Function does not support mixed constraint..."
                    break
                else: 
                    sense = '>='
                    b = lp.constraintsLower
            if lp.constraintsUpper[i] < infinity: 
                if sense == '>=':
                    print "Function does not support mixed constraint..."
                    break
                else: 
                    sense = '<='
                    b = lp.constraintsUpper
        return lp, x, lp.coefMatrix, b, sense, integerIndices
    else:
        print "No file or module name specified..."
        return None, None, None, None, None, None
开发者ID:ashutoshmahajan,项目名称:CuPPy,代码行数:56,代码来源:cuttingPlanes.py

示例3: read_instance

# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import extractCyLPModel [as 别名]
def read_instance(module_name = True, file_name = None):

    if module_name:
        lp = CyClpSimplex()

        mip = ilib.import_module(module_name)
            
        A = np.matrix(mip.A)
        #print np.linalg.cond(A)
        b = CyLPArray(mip.b)
        
        #We assume variables have zero lower bounds
        x_l = CyLPArray([0 for _ in range(mip.numVars)])
            
        x = lp.addVariable('x', mip.numVars)
        
        lp += x >= x_l
        try:
            x_u = CyLPArray(getattr(mip, 'x_u'))
            lp += x <= x_u
        except:
            pass
        
        lp += (A * x <= b if mip.sense[1] == '<=' else
               A * x >= b)
        c = CyLPArray(mip.c)
        lp.objective = -c * x if mip.sense[0] == 'Max' else c * x
        
        return lp, x, mip.A, mip.b, mip.sense, mip.integerIndices
    else:
        #TODO Change sense of inequalities so they are all the same
        #     by explicitly checking lp.constraintsUpper and lp.constraintsLower
        #Warning: Reading MP not well tested 
        lp.extractCyLPModel(file_name)
        x = lp.cyLPModel.getVarByName('x')
        sense = ('Min', '>=')
        return lp, x, None, None, sense, integerIndices
开发者ID:desteffy,项目名称:CuPPy,代码行数:39,代码来源:cuttingPlanes.py

示例4: CyLPArray

# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import extractCyLPModel [as 别名]
    if (firstExample):
        x = m.addVariable('x', 2, isInt=True)

        A = np.matrix([[7., -2.],[0., 1], [2., -2]])
        b = CyLPArray([14, 3, 3])

        m += A * x <= b
        m += x >= 0

        c = CyLPArray([-4, 1])
        m.objective = c * x
        s = CyClpSimplex(m)
    else:
        s = CyClpSimplex()
        cylpDir = os.environ['CYLP_SOURCE_DIR']
        inputFile = os.path.join(cylpDir, 'cylp', 'input', 'p0033.mps')
        m = s.extractCyLPModel(inputFile)
        x = m.getVarByName('x')
        s.setInteger(x)

    cbcModel = s.getCbcModel()

    gc = GomoryCutGenerator(m)
    cbcModel.addPythonCutGenerator(gc, name='PyGomory')

    cbcModel.branchAndBound()

    print cbcModel.primalVariableSolution

开发者ID:HerrKevin,项目名称:CyLP,代码行数:30,代码来源:GomoryCutGenerator.py

示例5: __init__

# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import extractCyLPModel [as 别名]
 def __init__(self, module_name = None, file_name = None,
              A = None, b = None, c = None,
              points = None, rays = None,
              sense = None, integerIndices = None, 
              numVars = None):
     
     if file_name is not None:
         # We got a file name, so ignore everything else and read in the instance
         lp = CyClpSimplex()
         lp.extractCyLPModel(file_name)
         self.integerIndices = [i for (i, j) in enumerate(lp.integerInformation) if j == True]
         infinity = lp.getCoinInfinity()
         A = lp.coefMatrix
         b = CyLPArray([0 for _ in range(lp.nRows)])
         for i in range(lp.nRows):
             if lp.constraintsLower[i] > -infinity:
                 if lp.constraintsUpper[i] < infinity:
                     raise Exception('Cannot handle ranged constraints')
                 b[i] = -lp.constraintsLower[i]
                 for j in range(lp.nCols):
                     A[i, j] = -A[i, j]
             elif lp.constraintsUpper[i] < infinity:
                 b[i] = lp.constraintsUpper[i]
             else:
                 raise Exception('Constraint with no bounds detected')
         x = lp.addVariable('x', lp.nCols)
         lp += A * x <= b
         lp += x <= lp.variablesUpper
         lp += x >= lp.variablesLower
         lp.objective = lp.objective
         self.sense = '<='
         numVars = lp.nCols
     else:
         min_or_max = None
         if module_name is not None:
             # We got a module name, read the data from there
             mip = ilib.import_module(module_name)
             self.A = mip.A if hasattr(mip, 'A') else None
             self.b = mip.b if hasattr(mip, 'b') else None
             points = mip.points if hasattr(mip, 'points') else None
             rays = mip.rays if hasattr(mip, 'rays') else None
             self.c = mip.c if hasattr(mip, 'c') else None
             self.sense = mip.sense[1] if hasattr(mip, 'sense') else None
             min_or_max = mip.sense[0] if hasattr(mip, 'sense') else None
             self.integerIndices = mip.integerIndices if hasattr(mip, 'integerIndices') else None
             x_u = CyLPArray(mip.x_u) if hasattr(mip, 'x_u') else None
             numVars = mip.numVars if hasattr(mip, 'numVars') else None
             self.x_sep = mip.x_sep if hasattr(mip, 'x_sep') else None
             if numVars is None and mip.A is not None:
                 numVars = len(mip.A)
    
             if numVars is None:
                 raise "Must specify number of variables when problem is not"   
         else:
             self.A = A
             self.b = b
             self.c = c
             self.points = points
             self.rays = rays
             if sense is not None:
                 self.sense = sense[1]
                 min_or_max = sense[0]
             self.integerIndices = integerIndices
             x_u = None
             
         lp = CyClpSimplex()
         if self.A is not None:
             A = np.matrix(self.A)
             b = CyLPArray(self.b)
         elif numVars <= 2 and GRUMPY_INSTALLED:
             p = Polyhedron2D(points = points, rays = rays)
             A = np.matrix(p.hrep.A)
             b = np.matrix(p.hrep.b)
         else:
             raise "Must specify problem in inequality form with more than two variables\n"   
     
         #Warning: At the moment, you must put bound constraints in explicitly for split cuts
         x_l = CyLPArray([0 for _ in range(numVars)])
             
         x = lp.addVariable('x', numVars)
         
         lp += x >= x_l
         if x_u is not None:
             lp += x <= x_u
         lp += (A * x <= b if self.sense == '<=' else
                A * x >= b)
         c = CyLPArray(self.c)
         if min_or_max == 'Max':
             lp.objective = -c * x
         else:
             lp.objective = c * x
         self.lp = lp
         self.x = x
开发者ID:tkralphs,项目名称:CuPPy,代码行数:95,代码来源:milpInstance.py


注:本文中的cylp.cy.CyClpSimplex.extractCyLPModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。