Add/remove variables/constraints during model optimization
回答済みIs it possible to add/remove variables and/or constraints to a model while optimisation is running? If so, is the body of a callback function the right place to do this?
Instead, if this is not possible, what if:
1) I use a callback to poll for new changes to apply to the model (during optimisation)
2) when new changes are available I call model.terminate() to stop the optimisation process
3) I add/remove variables and/or constraints as needed
4) I resume optimisation calling model.optimize()
From which state the model resume the optimization at step 4? Does it make an attempt to reuse information gathered during the previous optimization cycle or does it completely forget them as soon as the model is changed during step 3?
Thank you.
-
正式なコメント
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. -
Hi Lorenzo,
Is it possible to add/remove variables and/or constraints to a model while optimisation is running? If so, is the body of a callback function the right place to do this?
It is possible to add constraints via callbacks during the optimization process using lazy constraint and/or user cuts. See How do I implement lazy constraints in Gurobi? and What is the difference between lazy constraints and user cuts? for more information. It is not possible to add/remove variables or remove constraints during the optimization process via callbacks.
If you know a priori all variables and constraints that will be added/removed, you could try Gurobi's Multi Scenario feature. In the Tips and Tricks documentation of this feature, we explain how one can "simulate" addition and removal of variables/constraints.
However, if the choice of adding/removing variables/constraints in your application comes through an iterative process, then it is probably best to take your approach and terminate the optimization process from a callback, when enough information has been gathered.
From which state the model resume the optimization at step 4? Does it make an attempt to reuse information gathered during the previous optimization cycle or does it completely forget them as soon as the model is changed during step 3?
Yes, Gurobi tries to re-use as much information as possible from a previous run. If your model is an LP, then Gurobi will try to re-use previous basis information to construct a warm start. In the LP case, the parameter LPWarmStart might be of interest. There is a very nice video explaining warm-start and other fundamentals from last year's CO@Work. The channel also has further informative videos on Optimization fundamentals and expert applications.
In the MIP case, Gurobi will use a previously available feasible point (if any) to construct an initial feasible solution.Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント