Can new variables be added in a callback function?
AnsweredHello,
I am trying to solve the RCPSP using the lazy constraints feature of Gurobi (model is coded in Python). In the chosen formulation, disjunctive precedence constraints are used to resolve resource conflicts. These constraints include maximum and minimum terms depending on sets of variables. As the max_() and min_() functions cannot be used in a callback function, I reformulated the constraints as sets of linear inequalities, where binary auxiliary variables are required. Therefore, I was wondering if there is any way to add new variables (i.e. do something similar to "model.addVar(...)") within the callback function?
Thanks a lot for your help!
Kind regards
Jonas
-
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. -
Hi Jonas,
the documentation would suggest that your desired behavior is not supported. Perhaps someone from Gurobi team can confirm this?
I would recommend that you try to reformulate your problem further, or add the required variables upfront (if they are not too numerous).
Best regards
Jonasz0 -
That's correct - adding variabels on the fly, that is, column generation is not supported out-of-the-box with Gurobi. Please check out this discussion where Tobi explains the situation in some more detail: Column Generation Explanation – Gurobi Help Center
Cheers,
Matthias0 -
Hi Jonasz and Matthias,
thanks for clarifying that. Unfortunately, I will not be able to use lazy constraints in this case.
But thanks a lot for your help!Kind regards
Jonas0
Post is closed for comments.
Comments
4 comments