Skip to main content

Seek help about formulation of the constraints

Awaiting user input

Comments

2 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jonasz Staszek
    • 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

Post is closed for comments.