1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
#!/usr/bin/env python
# Test for output of dual variables
# Import PuLP modeler functions
from pulp import *
# A new LP problem
prob = LpProblem("test7", LpMinimize)
x = LpVariable("x", 0, 4)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)
prob += x + 4*y + 9*z, "obj"
prob += x + y <= 5, "c1"
prob += x + z >= 10,"c2"
prob += -y+ z == 7,"c3"
prob.writeLP("test7.lp")
prob.solve()
print("Status:", LpStatus[prob.status])
for v in prob.variables():
print(v.name, "=", v.varValue, "\tReduced Cost =", v.dj)
print("objective=", value(prob.objective))
print("\nSensitivity Analysis\nConstraint\t\tShadow Price\tSlack")
for name, c in list(prob.constraints.items()):
print(name, ":", c, "\t", c.pi, "\t\t", c.slack)
|