本文整理汇总了Python中pylpsolve.LP.setUpperBound方法的典型用法代码示例。如果您正苦于以下问题:Python LP.setUpperBound方法的具体用法?Python LP.setUpperBound怎么用?Python LP.setUpperBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylpsolve.LP
的用法示例。
在下文中一共展示了LP.setUpperBound方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkLBUBMix
# 需要导入模块: from pylpsolve import LP [as 别名]
# 或者: from pylpsolve.LP import setUpperBound [as 别名]
def checkLBUBMix(self, opts, lb, ub):
# these are indices to bound
lbindices = (0,3)
ubindices = {}
ubindices["t"] = (3,6)
ubindices["n"] = "a"
ubindices["N"] = "a"
ubindices["l"] = [3,4,5]
ubindices["a"] = ar([3,4,5],dtype=uint)
ubindices["f"] = ar([3,4,5],dtype=float64)
ubvalues = {}
ubvalues["s"] = ub
ubvalues["l"] = [ub, ub, ub]
ubvalues["a"] = ar([ub, ub, ub])
lbvalues = {}
lbvalues["s"] = lb
lbvalues["l"] = [lb, lb, lb]
lbvalues["a"] = ar([lb, lb, lb])
lp = LP()
lp.setLowerBound(lbindices, lbvalues[opts[1]])
if opts[0] == "N":
lp.getIndexBlock(ubindices["N"], 3)
lp.setUpperBound(ubindices[opts[0]], ubvalues[opts[1]])
lp.setObjective([1,1,1,-1,-1,-1])
for num_times in range(2): # make sure it's same anser second time
lp.solve()
self.assertAlmostEqual(lp.getObjectiveValue(), lb*3 - ub*3)
v = lp.getSolution()
self.assert_(len(v) == 6)
self.assertAlmostEqual(v[0], lb)
self.assertAlmostEqual(v[1], lb)
self.assertAlmostEqual(v[2], lb)
self.assertAlmostEqual(v[3], ub)
self.assertAlmostEqual(v[4], ub)
self.assertAlmostEqual(v[5], ub)
示例2: checkUB
# 需要导入模块: from pylpsolve import LP [as 别名]
# 或者: from pylpsolve.LP import setUpperBound [as 别名]
def checkUB(self, opts, ub):
# these are indices to bound
indices = {}
indices["t"] = (0,3)
indices["N"] = "a"
indices["l"] = [0,1,2]
indices["a"] = ar([0,1,2],dtype=uint)
indices["f"] = ar([0,1,2],dtype=float64)
ubvalues = {}
ubvalues["s"] = ub
ubvalues["l"] = [ub, ub, ub]
ubvalues["a"] = ar([ub, ub, ub])
lp = LP()
if opts[0] == "N":
lp.getIndexBlock(indices["N"], 3)
lp.setObjective([1,1,1,1,1,1])
lp.addConstraint( ((3,6), [[1,0,0],[0,1,0],[0,0,1]]), "<=", 10)
lp.setMaximize()
lp.setLowerBound(indices[opts[0]], None)
lp.setUpperBound(indices[opts[0]], ubvalues[opts[1]])
for num_times in range(2): # make sure it's same anser second time
lp.solve()
self.assertAlmostEqual(lp.getObjectiveValue(), ub*3 + 10 * 3)
v = lp.getSolution()
self.assert_(len(v) == 6)
self.assertAlmostEqual(v[0], ub)
self.assertAlmostEqual(v[1], ub)
self.assertAlmostEqual(v[2], ub)
self.assertAlmostEqual(v[3], 10)
self.assertAlmostEqual(v[4], 10)
self.assertAlmostEqual(v[5], 10)