How to get shadow price/dual in gurobi attached to the constraints it is referring to

Viewed 300

I am new to python and currently using gurobi to solve some optimization problems. I know that i can use model.getAttr('Pi', m.getConstrs()) function to get the shadow(dual) prices. This function however just spits out an array of values. I have about 30 constraints and it is hard to track which value is attached to which constraint. Is there a way you can print out the shadow price where it specifies which shadow price is attached to which constraint?

Thank you very much.

1 Answers

One option is to loop over your constraints and print the respective name and dual variable:

for c in m.getConstrs():
    print(f"{c.VarName}: {c.Pi}")
Related