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

Modifying the capacity constraints in multiple scenarios

回答済み

コメント

2件のコメント

  • 正式なコメント
    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.
  • Marika Karbstein
    • 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

投稿コメントは受け付けていません。