本文整理汇总了Python中cylp.cy.CyClpSimplex.getCoinInfinity方法的典型用法代码示例。如果您正苦于以下问题:Python CyClpSimplex.getCoinInfinity方法的具体用法?Python CyClpSimplex.getCoinInfinity怎么用?Python CyClpSimplex.getCoinInfinity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cylp.cy.CyClpSimplex
的用法示例。
在下文中一共展示了CyClpSimplex.getCoinInfinity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_instance
# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import getCoinInfinity [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
示例2: __init__
# 需要导入模块: from cylp.cy import CyClpSimplex [as 别名]
# 或者: from cylp.cy.CyClpSimplex import getCoinInfinity [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