Linear expression with MAX
AnsweredI have a two set of 'n' variables. I would like a liner combination corresponding variables of the two sets. THis results in 'n' variables. I would like to compare the max resulting 'n' varianles against a constant.
Example 
import gurobipy as gp
ZZZ=[]
for i in range (3):
for j in range (10):
varname="S_%02d_%02d"% (i, j)
XXX[i][j] =opt_mod.addVar(name=varname, vtype=gp.GRB.CONTINUOUS, lb=0.0)
ZZZ.append(XXX[i][j] +YYY[i][j] *W[i])
YYY is defined in similar fashion as XXX.
opt_mod.addConstr(gp.max_(ZZZ) <= KEYWIDTH) # KEYWIDTH is a constant.
0

Hi Shesha,
This can be done with the help of some auxiliary variables.
 Define auxiliary variables Z[i][j], add constraints Z[i][j] = XXX[i][j] +YYY[i][j] *W[i].
 Define another auxiliary variable ZZZ, and set it to max of Z[i][j] variables using the general constraint helper functions max_()
 If you want the max value to be at most KEYWIDTH, set the upper bound of the ZZZ variable to KEYWIDTH.
Best regards,
Simran0 
Thanks a lot for the information
0
Please sign in to leave a comment.
Comments
2 comments