Skip to main content

Modifying the capacity constraints in multiple scenarios

Answered

Comments

1 comment

  • Marika Karbstein
    • Gurobi Staff Gurobi Staff

    Hi Yuri,

    To identify the RHS and the LHS of the constraint, you need to reformulate the constraint such that all variables are on the left-hand side and all constants are on the right-hand side. Reformulating the capacity constraints to

    c1 = model.addConstrs(gp.quicksum(demand[i] * x[i, j] for i in customers) - capacity[j] * y[j] <= 0 for j in destinations)

    gives a RHS of 0.

    Changing the coefficient of a variable in a constraint is not directly possible when defining a scenario. You need to add two constraints and then deactivate one of them in each scenario. Deactivate here means to set the RHS such that the constraints are always satisfied.
    Here is a rough idea:

    # define the demand constraints
    c1 = model.addConstrs(gp.quicksum(demand[i] * x[i, j] for i in customers) <= capacity[j] * y[j] for j in destinations)
    # define demand constraints with different capacity
    c2 = model.addConstrs(gp.quicksum(demand[i] * x[i, j] for i in customers) <= fixed_capacity * y[j] for j in destinations)
    # deactivate the c2 constraints (for the base scenario)
    for j in destinations:
      c2[j].Rhs = GRB.INFINITY
    # define scenario (deactivate c1 and activate c2)
    for j in destinations:
    c1[j].ScenNRhs = GRB.INFINITY
    c2[j].ScenNRhs = 0

    I hope this helps,
    Marika

    1

Please sign in to leave a comment.