Skip to main content

Organizing model.printAttr('x') output.

Answered

Comments

2 comments

  • Official comment
    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?.
  • Silke Horn
    • Gurobi Staff Gurobi Staff

    You can get a list of all the x-values with model.getAttr('x'). However, the output produced by printAttr only contains the variables with non-zero values, the result of getAttr will contain all values including the zeroes.

    If all your variables are binaries, you could get the indices of all variables with value 1 as follows:

    output = [i for i, x in enumerate(m.getAttr("x")) if x > 0.5]

     

     

    1

Post is closed for comments.