Skip to main content

a Variable which is the upper bound of a sum

Answered

Comments

4 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?.
  • Richard Oberdieck
    • Gurobi Staff

    Hi,

    I would model this using auxiliary variables /(y_i/):

    M = m.addVar(vtype=GRB.INTEGER,lb=1,ub=4)
    y_i = m.addVars(4, vtype=GRB.BINARY, name='y')

    1-sum(P_i*y_i) # The constraint you want
    m.addConstrs(i*y_i <= M for i in range(4)) # This forces y_i to be 1 only if M reaches it

    Is this what you are looking for?

    0
  • ibtissam labriji
    • Gurobi-versary
    • Curious
    • Conversationalist

    Hello Richard, 

    Thank you for your response. Yes it does the trick. Although, I think that : the range should go to 5. So that y_4 can be taken into consideration : 

    m.addConstrs(i*y_i <= M for i in range(5))

    Please, correct me if I am wrong.

    Regards, 

    Ibtissam

    0
  • Richard Oberdieck
    • Gurobi Staff

    Yes, you are right, it actually should be

    m.addConstrs(i*y_i <= M for i in range(1,5))

    since y_0 does not exist.

    0

Post is closed for comments.