本文整理汇总了Python中pylpsolve.LP.bindSandwich方法的典型用法代码示例。如果您正苦于以下问题:Python LP.bindSandwich方法的具体用法?Python LP.bindSandwich怎么用?Python LP.bindSandwich使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylpsolve.LP
的用法示例。
在下文中一共展示了LP.bindSandwich方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkBindSandwich
# 需要导入模块: from pylpsolve import LP [as 别名]
# 或者: from pylpsolve.LP import bindSandwich [as 别名]
def checkBindSandwich(self, opts):
idxlist = [{}, {}]
idxlist[0]["t"] = (0,3)
idxlist[0]["N"] = "a"
idxlist[0]["l"] = [0,1,2]
idxlist[0]["a"] = ar([0,1,2])
idxlist[0]["r"] = ar([0,0,1,1,2,2])[::2]
idxlist[0]["f"] = ar([0,1,2],dtype=float64)
idxlist[1]["t"] = (3,6)
idxlist[1]["n"] = "b"
idxlist[1]["l"] = [3,4,5]
idxlist[1]["a"] = ar([3,4,5])
idxlist[1]["r"] = ar([3,3,4,4,5,5])[::2]
idxlist[1]["f"] = ar([3,4,5],dtype=float64)
lp = LP()
if opts[0] == "N":
self.assert_(lp.getIndexBlock(idxlist[0]["N"], 3) == (0,3) )
# Now bind the second group
lp.bindSandwich(idxlist[0][opts[0]], idxlist[1][opts[1]])
if opts[2] == "u":
lp.addConstraint( (idxlist[0][opts[0]], 1), ">=", 1)
elif opts[2] == "l":
lp.addConstraint( (idxlist[0][opts[0]], 1), "<=", -1)
lp.setUnbounded(idxlist[0][opts[0]])
else:
assert False
lp.setObjective( (idxlist[1][opts[1]], [1,2,3]) )
lp.setMinimize()
lp.solve()
v = lp.getSolution()
v0 = 1 if opts[2] == "u" else -1
self.assert_(len(v) == 6, "len(v) = %d != 6" % len(v))
self.assertAlmostEqual(v[0], v0)
self.assertAlmostEqual(v[1], 0)
self.assertAlmostEqual(v[2], 0)
self.assertAlmostEqual(v[3], 1)
self.assertAlmostEqual(v[4], 0)
self.assertAlmostEqual(v[5], 0)
if opts[0] in "nN" and opts[1] in "nN":
d = lp.getSolutionDict()
self.assert_(set(d.iterkeys()) == set(["a", "b"]))
self.assertAlmostEqual(d["a"][0], v0)
self.assertAlmostEqual(d["a"][1], 0)
self.assertAlmostEqual(d["a"][2], 0)
self.assertAlmostEqual(d["b"][0], 1)
self.assertAlmostEqual(d["b"][1], 0)
self.assertAlmostEqual(d["b"][2], 0)