Skip to main content

Adding arbitrary functions to the model



1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    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, 


Please sign in to leave a comment.