Max_ for multidimensional array
AnsweredHi,
I have a multidimensional variable:
var = m.addVars(N,time,vtype=GRB.INTEGER, name ="Var_")
and I would like to calculate the maximum value of this variable for each N. For example,
max_var[0] is the maximum in value of var[0, t] in all time. I have defined this variable:
max_var = m.addVars(n,vtype=GRB.INTEGER, name ="MaxVar_")
and the constraint is:
m.addConstrs( (max_var[n] == max_(var[n,t]) for n in N), "cMaxValues")
but it always returns the last element in var[n,t]. Am I in the correct way or Gurobi needs only lists for the max_ function?
Thanks!
0

Hi Ana,
The term
max_(var[n,t])
only takes the maximum value of exactly one variable \(\texttt{var[n,t]}\) because the object \(\texttt{var[n,t]}\) is exactly one variable at position \(\texttt{(n,t)}\). To take the maximum value over all \(\texttt{t}\), you have to construct a list
max_(var[n,t] for t in range(time))
Best regards,
Jaromił0 
Many thanks for your response!!!
Finally it works!
0
Please sign in to leave a comment.
Comments
2 comments