Skip to main content

How can I make my constraint choose the max value?

Answered

Comments

5 comments

  • Silke Horn
    Gurobi Staff 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 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 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

Please sign in to leave a comment.