How to update the constraints of a multi-stage problem (remove some, add some) and ensure that the values of the relevant variables decided upon do not disappear
AnsweredI am implementing a multi-stage problem using gurobipy. The problem is continuous and needs to be optimised at each stage.
At each stage some new constraints is added and at the same time the constraint from the previous stage needs to be removed. Here is some of the relevant code:
model.optimize()
constrs_linE = model.getConstrs()
for i in constrs_linE:
model.remove(i)
model.update()
The problem I am having is that if I delete the old constraint in this way, then the values of the variables that have been decided will no longer exist either.
How do I solve this problem? Thank you.
-
Official comment
This post is more than three 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. -
The problem I am having is that if I delete the old constraint in this way, then the values of the variables that have been decided will no longer exist either.
You should save the solution point values of variables of interest after every optimization step if you need them. You can access the solution point values of variables via the X attribute.
0
Post is closed for comments.
Comments
2 comments