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

how to manage unused binary values during solve?

回答済み

コメント

4件のコメント

  • 正式なコメント
    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 why not try our AI Gurobot?.
  • Jaromił Najman
    • Gurobi Staff

    Hi Amir,

    In Gurobi's MATLAB API, you can set the initial value of all variables via the start (you have to scroll far down to the bottom) field.

    In Python, you can set the initial values via the Start attribute.

    Best regards,
    Jaromił

    0
  • amir b
    • Gurobi-versary
    • First Comment
    • First Question

    Hi I used this code

    pG = m.addMVar(shape = p_Ng * p_Ns, vtype = GRB.BINARY)
    for i in range(0, p_Ng * p_Ns):
        pG[i].Start = GRB.UNDEFINED
        # or pG[i].Start = 0 did not work

    but it says 'No start values specified in MIP start' . After solve, some pG variables which did not affected by the constarints is still set to 1.

    ----------------------

    I would like to say my problem in another way

    A = np.array([[1, 0, 0, 0, 0], [0, 1, 0, 0, 0]])
    m = gp.Model('mat_mul_model_test')
    some_var = m.addVar(vtype = GRB.INTEGER)
    x = m.addMVar(5, vtype = GRB.BINARY)
    m.addConstr(A @ x == 0)
    m.setObjective(some_var, GRB.MINIMIZE)
    m.optimize()
    x_values = x.X
    print(x_values)

    it prints

    [-0. -0. -0. -0. -0.]

    and when I set to 1 using

    m.addConstr(A @ x == 1)

    it prints

    [1. 1. 1. 1. 1.]

    But, I expect to have this output

    [1 1 0 0 0]

    or something that i can see it is not used with NaN values like this one:

    [1 1 NaN NaN NaN]

    How do I define this behavior for unused variables using Python API attributes?

     

    0
  • Jaromił Najman
    • Gurobi Staff

    Hi Amir,

    Unused variables are set by Gurobi to any feasible value, in this case either 0 or 1. Returning NaN is not correct because NaN is not a feasible value for a binary variable. I am no expert with YALMIP but it sounds strange to set the values of unused variables to NaN in the optimal solution because the optimal solution is then actually not a feasible one.

    If you want to fix the value of unused variables, you can add equality constraints setting these to 0 (or any other feasible value). Alternatively, you can add the unused variables to your objective function with the correct sign to force the unused variable to take the 0 value.

    Best regards,
    Jaromił

    0

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