Skip to main content

Question about converting a matrix to indicator matrix in gurobi

Answered

Comments

1 comment

  • Simon Bowly
    Gurobi Staff Gurobi Staff

    It's not possible to do this via numpy's type casting functions; you need to construct constraints to specify the relationship between v and k. I'm assuming here that k_i are binary variables in the model, as opposed to a post-processing step where the values of v_i are already known.

    You can express the necessary constraints using either a big-M formulation:

    model.addConstr(v[i] <= M*k[i])

    where M is an upper bound on the value of v_i, or using indicator constraints:

    model.addConstr((k[i] == 0) >> (v[i] == 0))
    0

Please sign in to leave a comment.