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

Select variables in feasRelax()

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff 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 why not try our AI Gurobot?.
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    Hi Buddi,

    Yes, you can do this by passing a list of the corresponding Var objects to the vars argument of Model.feasRelax(). In the example in the documentation, all variable bounds are allowed to be violated, hence the use of Model.getVars().

    Here is a short example:

    import gurobipy as gp

    m = gp.Model()

    n = 10
    x = m.addVars(n, ub=1, name="x")
    y = m.addVar(ub=1, name="y")

    for i in range(n):
        m.addConstr(x[i] + y >= 3)

    m.optimize()

    if m.status == gp.GRB.INFEASIBLE:
    # Only relax x variables
        ubpen = [1.0]*n
        m.feasRelax(0, False, x, None, ubpen, None, None)
        m.optimize()

    The best way to minimize the sum of the absolute values of the bound violations for this problem and satisfy the \( n \) constraints is to set \( x_i = 1 \) for \( i = 1, \ldots, n \) and \( y = 2 \). The total violation in this case is \( 1 \), since each variable has an upper bound of \( 1 \). However, because we restrict Model.feasRelax() to only allow bound violations for the \( x \) variables, the solution is to set \( x_i = 2 \) for \( i = 1, \ldots, n \) and \( y = 1 \). This is total violation of \( n \).

    I hope this helps!

    Eli

    0

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