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

Error: must be real number, not MLinExpr while using model.addGenConstrIndicator

回答済み

コメント

3件のコメント

  • 正式なコメント
    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?.
  • Alison Cozad
    • Gurobi Staff

    The error is showing you that the last argument is a matrix linear expression rather than a linear expression.  This makes sense since you are using matrix variable objects, MVar, in the expression.  In fact, Model.addGenConstrIndicator() can't use matrix variable objects directly.  Really, both the binary variable and LHS arguments cannot be matrix variable objects.

    Luckily, Gurobi has a function to retrieve Var objects from MVar objects.  According to the documentation, the function MVar.tolist(),

    Returns the variables associated with this matrix variable as a list of individual Var objects.

     

    Therefore, you can create variable lists for each MVar in your indicator constraint:

    b_B_list=b_B.tolist()
    A_list=A.tolist()
    B_list=B.tolist()

     

    Then, you can update your indicator constraint definition to

    model.addGenConstrIndicator(b_B_list[i][j], 1, B_list[i][j]-A_list[i][j]>=.001)

     

     

    1
  • Fariha Kabir Torsha
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you so so much!

    0

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