Retrive attribute Pi
Awaiting user inputI have a pure linear model, but I cannot retrieve the dual value (Pi). Are there any common reasons why this might happen? See my code below, for it only tries to retrieve the dual values in the case of optimality.
# Open a file named "sensitivity_analysis.txt" in write mode
if lp_model.status == GRB.INFEASIBLE:
# handle infeasibility
pass
elif lp_model.status == GRB.OPTIMAL:
# handle optimality
with open("sensitivity_analysis.txt", "w") as file:
# Sensitivity analysis for constraints
file.write("\nConstraint sensitivity analysis:\n")
for constr in lp_model.getConstrs():
constr_name = constr.ConstrName
constr_slack = constr.slack
constr_dual_value = constr.getAttr("Pi")
file.write(f"Constraint: {constr_name}\n")
file.write(f" Slack: {constr_slack}\n")
file.write(f" Dual value (Shadow price): {constr_dual_value}\n")
0
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
What is the error you get? Please share excerpts from the logfile so we can better understand the issue. -G
0
Post is closed for comments.
Comments
2 comments