Linearizing Max function in constraint
AnsweredI'm trying to linearize the following constraints in python.
mdl = Model('MTHFVRPTW')
rtkw = mdl.addVars(vehicles, trips, vtype=GRB.CONTINUOUS) #return time of trip w of vehicle k
aac = mdl.addVars(vehicles, customers, trips, vtype=GRB.CONTINUOUS) #arrival at customer with veh k on trip w
#13
mdl.addConstrs(rtkw[k,w] >= max(aac[k,i,w], earliest[i]) for i in customers for k in vehicles for w in trips)
#14
mdl.addConstrs(aac[k,j,w] >= max(aac[k,i,w], earliest[i]) for i,j in customers for k in vehicles for w in trips)
0
-
Official comment
This post is more than two 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. -
the list earliest is a parameter of my problem, not a variable
0 -
Hi Joao,
Let us assume that you would like to implement a constraint in the form \(\max(x, c)\) with \(c\) being a constant value.
- You need to fist define an auxiliary variable \(y\)
- You can then use the method Model.addGenConstrMax() (or general constraint helper function gurobipy.max_()) to implement the relationship \(y = \max(x, c)\).
- You can then use \(y\) in place of \(\max(x, c)\) in any other constraint where the \(\max\) function appears.
Best regards,
Maliheh
0
Post is closed for comments.
Comments
3 comments