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

Implement constraints correctly

回答済み

コメント

2件のコメント

  • 正式なコメント
    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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • Jaromił Najman
    • Gurobi Staff

    You define your \(y\) variables over \(D\). However, the set \(D\) does not contain the keys \((0,0),(0,3)\) and more. The error occurs, because you build constraint 5 over the sets \(N\) and \(P\) of which, the combinations \((0,0),(0,3)\) and other are not present in \(D\). The probably easiest way to fix this would be to add an additional \(\texttt{if}\) check when constructing constraint 5

    #Constraint that force vessel to visit all Ports
    for i in N:
      f.addConstr(
      (sum(y[i,j] for j in P if (i,j) in D) == 1), 'Constraint5')

    Best regards, 
    Jaromił

    0

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