Adding arbitrary functions to the model
AnsweredI have a linear problem with a large number of binary variables. However, the problem has multiple objectives. The issue is that due to the large size of the problem, it takes up to 30 minutes to set up the problem using gurobipy. However, solving the problem, once modeled, is pretty quick.
The way I am solving this multiobjective problem requires me to be able to make certain combinations of the true objective as a scalar objective for gurobi, while adding a few constraints also related to the combination. I need to solve the problem for a large number of these combinations.
The time it takes to initialize the model makes it infeasible for me to solve this problem in a reasonable amount of time. Is there a way for me to store the multiple true objectives as some arbitrary function in the model, and create the scalar objective and additional constraints for gurobi using these arbitrary functions? That way, I would need to deal with the initialization step only once, making the process much faster.
One way that I have already thought of, but haven't yet tested, is modelling the true objectives as additional decision variables, and adding the linear equations for these objectives as equality constraints. However, that may make the problem more expensive to solve.
Additionally, I also would like to keep track of some more linear functions (as a sanity check on the optimization results). These are neither objectives nor constraints, just linear functions of the decision variables. Is there a way to store these as some arbitrary functions in the gurobi model?

The time it takes to initialize the model makes it infeasible for me to solve this problem in a reasonable amount of time.
Did you try identifying why the model building is taking so long? The Knowledge Base article How do I improve the time to build my model? might be helpful.
One way that I have already thought of, but haven't yet tested, is modelling the true objectives as additional decision variables, and adding the linear equations for these objectives as equality constraints. However, that may make the problem more expensive to solve.
This sounds reasonable since adding auxiliary variables and auxiliary constraints usually does not deteriorate performance. Of course only as long as the number of auxiliary objects is not too big. You should try this approach as check whether it works as expected.
Additionally, I also would like to keep track of some more linear functions (as a sanity check on the optimization results). These are neither objectives nor constraints, just linear functions of the decision variables. Is there a way to store these as some arbitrary functions in the gurobi model?
You can add a free auxiliary variable for every such linear function. As long as there are not too many, this should not have any impact on the solver's performance, since the presolve algorithm will remove these redundant constraints from the model. After a successful optimization, you can then access the values of the auxiliary variables and any variables participating in these constraints.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment