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
-
What is the error you get? Please share excerpts from the logfile so we can better understand the issue. -G
0
Please sign in to leave a comment.
Comments
1 comment