Skip to main content

Implement constraints correctly



1 comment

  • Jaromił Najman
    Gurobi Staff 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:
      (sum(y[i,j] for j in P if (i,j) in D) == 1), 'Constraint5')

    Best regards, 


Please sign in to leave a comment.