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

Error when using addConstrs to construct vector constraints

回答済み

コメント

2件のコメント

  • 正式なコメント
    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.
  • Riley Clement
    • Gurobi Staff

    Hi Magnus,

    The best way to debug this is to set intermediate variables to some values:

    b = B[0]
    t = T[0]
    i = 0

    Then play around with the expression:

    np.transpose(C) @ gamma[b,t,i,:].tolist() - [x_L[b,t], x_S[b,t]] <= normPsi[b,t,:]

    Where does it fail?  What's the smallest piece of it that fails? What are the types of these things?  What are their shapes?  Which pieces are not compatible with each other?

    Do this, and you will find there are incompatibilities between gurobipy.MVar and numpy.matrix.  You can't simply use them interchangeably.  If you use the following then you will not have errors.

    np.transpose(C) @ gamma[b,t,i,:] - gp.hstack([x_L[b,t], x_S[b,t]]) <= normPsi[b,t,:]

    Note that gurobipy.hstack was introduced in v11.

    - Riley

     

    0

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