python-如何显示纸浆中定义的(原始)线性程序的对偶
作者:互联网
关于堆栈溢出的第一个问题…喜欢这个网站…
我在Python上使用PuLP.基于输入变量,目标函数和约束条件,我试图查看与初始LP问题(原始)的最优解相关的对偶变量/值.我在搜索文档时遇到麻烦,我只是想清楚一点.有没有办法用纸浆做到这一点?下面有示例代码显示原始输入.
注意:我编辑了我的问题,从提出双重要求到询问双重结果(基于反馈).
注2:根据反馈进行了进一步编辑以澄清.
import pulp
lpProb = pulp.LpProblem("example", pulp.LpMinimize)
x1 = pulp.LpVariable("x1", 0, None, pulp.LpContinuous)
x2 = pulp.LpVariable("x2", 0, None, pulp.LpContinuous)
x3 = pulp.LpVariable("x3", 0, None, pulp.LpContinuous)
lpProb += 3*x1 + 4*x2 + 2*x3
lpProb += x1 + 2*x2 + x3 >= 42
lpProb += 5*x1 + 7*x2 + 4*x3 >= 68
lpProb.solve()
print(pulp.LpStatus[lpProb.status])
for i in lpProb.variables():
print("Variable {0} = {1}".format(i.name, i.varValue))
print("Objective function z = {0}".format(pulp.value(lpProb.objective)))
解决方法:
@StuartMitchell在对该问题的评论中提出了以下建议.它打印每个约束的名称,对数值和松弛度.
for name, c in list(lpProb.constraints.items()):
print(name, ":", c, "\t", c.pi, "\t\t", c.slack)
标签:python-3-x,linear-programming,pulp,python 来源: https://codeday.me/bug/20191109/2013160.html