Skip to main content

Maximum of two values

Answered

Comments

4 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jonasz Staszek
    • Community Moderator
    • Gurobi-versary
    • Thought Leader
    • First Question

    Hi Sakir,

    first of all, the max_() method in Guroby Python has a slightly different syntax - take a look at the documentation.

    On top of this, the max_() method takes variables as arguments and not linear expressions. You might want to try something along the lines of:

    aux = model.addVars(I, vtype="C", name="aux")
    for i in I
    model.addLConstr(aux[i] == y[i-1] + a*z[i-1])
       model.addConstr(y[i] == max_(aux[i], constant=0))

    Hope this helps.

    Best regards
    Jonasz

     

     

    0
  • Gwyneth Butera
    • Gurobi Staff

    Also, the article How do I model logical and general expressions? may be of use when using max in a constraint in gurobipy.

    0
  • SAKIR KARAKAYA
    • Gurobi-versary
    • First Comment
    • First Question

    Hi,

    Thank you so much for your quick response. The equation I shared is not a constraint. After solving the constrained optimization model, I'd like to make a straightforward mathematical operation. Actually, when I tried the following, the problem is solved. 

    y[i] = max(0, y[i-1].X+ a*z[i-1].X)
    0

Post is closed for comments.