Skip to main content

Maximum of two values

Answered

Comments

3 comments

  • Jonasz Staszek
    Community Moderator 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 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

Please sign in to leave a comment.