How can I make my constraint choose the max value?
AnsweredI have defined x[t], y[t], z[t], and I would like a set of constraints over time such that
for t in range (0,100)
m.addConstr(x[t], gurobipy.GRB.EQUAL, max_(y[t],z[t]))
However, I am getting the error name 'max_' is not defined. How do I resolve this.
Regards
-
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?. -
You should use the overloaded form of addConstr as follows:
m.addConstr(x[t] == max_(y[t], z[t]))
Alternatively, you can use addGenConstrMax:
m.addGenConstrMax(x[t], [y[t], z[t]])
0 -
Thank you very much. The first syntax does not work for me but the second one does.
0 -
Glad to hear it works. There was a ")" missing in the first one. I updated it accordingly. It should work too.
0 -
I get the same error with the first syntax, i.e. "name 'max_ ' not defined'
Could it be a limitation of the editor I am using?
0 -
The \(\texttt{max_}\) function is part of the \(\texttt{gurobipy}\) module. Thus, in your case, you have to access it via
gurobipy.max_(y[t], z[t])
0
Post is closed for comments.
Comments
6 comments