本文整理匯總了Python中pylpsolve.LP.setMaximize方法的典型用法代碼示例。如果您正苦於以下問題:Python LP.setMaximize方法的具體用法?Python LP.setMaximize怎麽用?Python LP.setMaximize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pylpsolve.LP
的用法示例。
在下文中一共展示了LP.setMaximize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testBasicBasis
# 需要導入模塊: from pylpsolve import LP [as 別名]
# 或者: from pylpsolve.LP import setMaximize [as 別名]
def testBasicBasis(self):
# this should work as it's in the examples
lp = LP()
lp.addConstraint( (0, 1), "<", 3)
lp.addConstraint( (1, 1), "<", 3)
lp.setMaximize()
lp.setObjective([1,1])
lp.solve(guess = [3,3])
self.assert_(lp.getInfo("Iterations") == 0, lp.getInfo("Iterations"))
示例2: checkUB
# 需要導入模塊: from pylpsolve import LP [as 別名]
# 或者: from pylpsolve.LP import setMaximize [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)