Skip to main content

How can I make my constraint choose the max value?

Answered

Comments

6 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Silke Horn
    • Gurobi Staff

    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
  • Arif Ahmed
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you very much. The first syntax does not work for me but the second one does.

    0
  • Silke Horn
    • Gurobi Staff

    Glad to hear it works. There was a ")" missing in the first one. I updated it accordingly. It should work too.

    0
  • Arif Ahmed
    • Gurobi-versary
    • First Comment
    • First Question

    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
  • Jaromił Najman
    • Gurobi Staff

    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.