MILP sesitivity analysis
AnsweredHi,
I am trying to do a sensitivity analysis on a MILP model. After solving the original problem I am trying to modify the bounds of some variables to make the model more restrictive. However, when I solve the new problem I get a better value of the objective function than that previously obtained. I have tried to set Heuristics to 0 but still have the same problem.
Also, I have tried to fix the binary variables of my initial solution and then modify the bounds of my continuous variables, however, when I print the values of the bounds before and after modifying it, the value is the same. This is the chuck of my code:
gb_problem.optimize()
gb_problem_fixed = gb_problem.fixed()
vars = gb_problem_fixed.getVars()
v = vars[0]
print(v.ub)
v.ub = 0
print(v.ub) # same as before
Thank you,
Alejandro
-
Hi Alejandro,
I am trying to do a sensitivity analysis on a MILP model. After solving the original problem I am trying to modify the bounds of some variables to make the model more restrictive. However, when I solve the new problem I get a better value of the objective function than that previously obtained. I have tried to set Heuristics to 0 but still have the same problem.
Can you please share a minimum reproducible example we can use to investigate the behaviour you are seeing? Please follow the instructions in the article Tutorial: Preparing a Minimal Reproducible Example.
Also, I have tried to fix the binary variables of my initial solution and then modify the bounds of my continuous variables, however, when I print the values of the bounds before and after modifying it, the value is the same. This is the chuck of my code:
gb_problem.optimize() gb_problem_fixed = gb_problem.fixed() vars = gb_problem_fixed.getVars() v = vars[0] print(v.ub) v.ub = 0 print(v.ub) # same as before
Please call model.update() after changing the variable upper bound to apply the change to the model.
Model modification in Gurobi is performed in a lazy fashion, meaning that the changes don't affect the model immediately. Instead, they are queued and are applied later, with the calls to model.update(), model.optimize() or model.write() methods. You can read more about Gurobi's lazy update approach in the "Lazy Update" section of our Python API Overview.
Best regards,
Simran0 -
Hello Simra,
I am trying to figure out how to make a minimal example since I am only observing this behavior with a big model (Variable types: 1583 continuous, 1022 integer), while with a smaller version of the problem, it works fine. Also, thanks for the information on how to update the model.
Best regards,
Alejandro
0 -
Hi Alejandro,
While you are trying to produce a smaller example, you can also do the following to get more insights into the behaviour you are observing:
- Confirm if your original model was solved to optimality. Check if you are using non-default terminating criteria, such as user-defined values for the TimeLimit and MIPGap parameters, which may have stopped the solver earlier and prevented it from finding the optimal solution.
- The default value of the MIPGap parameter is 1e-4. Set the MIPGap parameter to zero and solve your original model again. This will allow you to assess if a better solution for your original model exists compared to your previous solution.
- Solve your original model with variables fixed to their values in the solution you got from the restricted model and check if the resulting model is still feasible. To fix a variable, you can set its lower bound and upper bound attributes to the same value.
Unfortunately, you cannot attach a file to a community post; however, you can share models and log files through services like Filemail, Dropbox, Box, Google Drive, OneDrive, etc.
Best regards,
Simran0
Please sign in to leave a comment.
Comments
3 comments