Skip to main content

Seek help about formulation of the constraints

Awaiting user input

Comments

1 comment

  • Jonasz Staszek
    Community Moderator Community Moderator
    Gurobi-versary
    Thought Leader
    First Question

    Hi Yunfan,

    I assume you use Python API.

    Based on your inputs, I would imagine the following code to work:

    import gurobipy as gp

    model = gp.Model()

    # define K, C, I and x
    for k in K:
        for c in C:
            for i in I:
                m.addLConstr(
                    x[k, c, i] <= gp.quicksum(x[k, c - 1, j] for j in N[i]),
                    name=f"c_{k}_{c}_{i}",
                )

    # alternatively
    m.addConstrs(
        (
            x[k, c, i] <= gp.quicksum(x[k, c - 1, j] for j in N[i])
            for k in K
            for c in C
            for i in I
        ),
        name="c",
    )

     

    0

Please sign in to leave a comment.