Skip to main content

Constraint with for loop

Answered

Comments

2 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.
  • Chung-Kyun Han
    • Gurobi Staff

    Hi Rayan,

    Thank you for reaching us again.

    You can write concise code when you refer to our 'Python Dictionary Example' page.
    And, specifically, you can resolve your issue with 'tuplelist class'.

    The following is an arbitrary example utilizing the tuplelist class.

    import gurobipy as gp

    l = gp.tuplelist([(i, j) for i in range(10) for j in range(10)])

    m = gp.Model()
    x = m.addVars(l, name="x")
    m.update()

    m.addConstr(x[0, 0] <= gp.quicksum(i + j * x[i, j] for i, j in l.select([2, 3, 5], '*')))
    m.addConstr(x[1, 1] <= gp.quicksum(i + j * x[i, j] for i, j in l.select([1, 5, 6], '*')))

    Feel free to leave comments if you have any further questions.

     

    Best regards,
    Chung-Kyun Han

     

    0

Post is closed for comments.