メインコンテンツへスキップ

Constraint with for loop

回答済み

コメント

1件のコメント

  • 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

サインインしてコメントを残してください。