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

Organizing model.printAttr('x') output.

回答済み

コメント

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?.
  • 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

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