Model Refinement
AnsweredHello Gurobi Community,
I am a Msc student using Gurobi to solve an energy trading MILP optimization problem in Python.
In my implementation, the script reads input variables from a spreadsheet for each trading period, solves the MILP and populates the same file with solutions for that period. It then flushes the constraints and solutions from the model, iterates to the next trading period and starts all over again.
I sense that this is rather inefficient and also presents me with a problem since I can't find a way to formulate constraints that stretch across multiple trading periods (e.g. limiting the number of charging cycles in a full day). Could anyone point me in the direction of a better approach?
A version of the project is hosted on Github here.
-
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 why not try our AI Gurobot?. -
Hi,
You don't have to remove all constraints each time you compute new values for your dynamic variables in the model, see here. You can just remove the ones that actually change completely or are not present or simply change the coefficients only.
With that you can add constraints which are valid for all or only a subset of trading periods and remove/leave/add them accordingly.
It seems like you are often just changing the coefficients of your constraints. For that, it is recommended to use the chgCoeff() function instead of reconstructing the constraints from scratch.
I also see that you call m.reset(0) and I am not sure if this is necessary in your case. It is possible that the solution of the previous optimization may provide a good warm start solution for the solver and speed up the optimization process.I hope the above could help.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments