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
-
Official comment
This post is more than three 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 why not try our AI Gurobot?. -
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
Post is closed for comments.
Comments
3 comments