Re-optimization with a partial solution and new constraints
AnsweredHello all,
I'm testing a re-optimization method that goes as follows.
Initialize model
model.solve() --> solution stored as model.sol
Edit model.sol by removing solutions to some variables (incl. objective) to create a partial solution (partial.sol).
model2 = model.copy()
model2.read(partial.sol)
Add additional constraints to model2 and update the model.
re-optimize the model for those variables that were not in the partial solution.
So, I want to keep part of the solution from the first optimization and re-optimize for a subset of variables with extra constraints (and maybe with a different objective function). How can I ask Gurobi to do this? It seems like Gurobi re-optimizes for all variables and not only for the subset of variables I want to handle.
Regards
Charitha
-
Hi Charitha,
Is there a particular reason why you create a copy of your model instead of directly working with the original model? If you would work with your original model, you would not have to write a model.sol file. You could just set the corresponding start attributes and add additional constraint to your model.
Is your model a LP or a MIP? This is important to distinguish because a feasible solution usually does not help much if you work with an LP. If your model is an LP, you have to work with the Basis attributes VBasis and CBasis. If your model is a MIP, then working with the Start attribute or just reading in a (partial) solution file is the way to go.
So, I want to keep part of the solution from the first optimization and re-optimize for a subset of variables with extra constraints (and maybe with a different objective function)
Do you mean that you would like to fix some variables to the values that you found in a previous optimization run? If so, then you can fix a variable by setting its LB and UB attribute to the same value, e.g.,
# fix variable x to 1
x.LB = 1
x.UB = 1Best regards,
Jaromił0 -
Dear Jaromil,
Is there a particular reason why you create a copy of your model instead of directly working with the original model?
No. Anyway, I wanted to save the solution file for later inspection. I will continue based on your suggestion.
Is your model a LP or a MIP?
It is a MIP model.
Do you mean that you would like to fix some variables to the values that you found in a previous optimization run?
Yes. I will follow your example. Thank you.
0
Please sign in to leave a comment.
Comments
2 comments