How to use multiplication of variable inside gp.max_() ?
Answeredx is a continuous varibale, and a[] is an array of decision variables. I want to add the following
model.addConstr(x == gp.max_(a[0]*1, a[1]*3, a[2]*4))
But I am getting error. How to solve this?

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]))
0 
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?
0 
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.
0
Please sign in to leave a comment.
Comments
3 comments