Can one change variable values in a gurobipy model object and see how this affects constraints?
AnsweredI am using Gurobi via gurobipy. I have a model object that gives me a solution that I find unintuitive. To explore the solution further I would like to change the values of certain variables of the problem and see how this affects certain linear constraints. Is that possible using the model object and if so how does one do it?
-
Hi Lutz,
You can fix a variable by setting its lower bound and upper bound to the same value and resolve the model.
var.UB = my_value
var.LB = my_valueTo see how these changes affect your constraints, you can check constraint attributes like Slack or Pi. Slack shows the difference between the left-hand side and the right-hand side of the constraint, indicating how close the constraint is to being binding. Pi represents the dual prices or shadow prices of the constraints, which can tell you how the objective value would improve if you slightly increased the right-hand side of the constraint.
slack = constr.getAttr('Slack')
pi = constr.getAttr('Pi')You may also find the following articles helpful:
- How do I diagnose a wrong result?
- How do I diagnose a wrong solution?
- How do I diagnose a suboptimal objective value returned as optimal by Gurobi?
Best regards,
Simran0
Please sign in to leave a comment.
Comments
1 comment