Skip to main content

Question about converting a matrix to indicator matrix in gurobi

Answered

Comments

2 comments

  • Official comment
    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.
  • Simon Bowly
    • 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

Post is closed for comments.