• Gurobi Staff

The max_ function only takes a list of decision variables (or constants). You will have to define some auxiliary variables (say aux[1] and aux[2]) and add constraints as follows:

model.addConstr(aux[1] == a[1]*3)model.addConstr(aux[2] == a[2]*4)

Then you can add the max constraint using the auxiliary variables:

model.addConstr(x == gp.max_(a[0], aux[1], aux[2]))

Hello Silke,

I have a question regarding the use of the max_ function. I noticed that using it slows down the optimization somewhat. Is this because it is technically not a linear constraint? Have you ever observed a similar behavior?

• Gurobi Staff

Yes, adding the max_() constraints may make your model harder to solve.  Depending on how $$x$$ is used in your model, the max_() general constraint helper function will add either constraints or constraints and variables to your model.  Please check out Part 2 of this Modeling presentation from when the general constraint helper functions were first introduced to get a feel for how this is done.