Skip to main content

"TypeError: 'int' object is not subscriptable" while setting a constrain



1 comment

  • Eli Towle
    Gurobi Staff Gurobi Staff

    Hi Vincent,

    I suspect this is the problem:

    (2*o[3] + o[2])*[yTruck[(tr,m-1,o)]] for o in range(UBorders)

    range(UBorders) returns a list of integers, so every value of o you are looping over is an integer. You see this error because writing o[2] and o[3] isn't valid. Brackets used in this way enclose indices or keys, which don't make sense to use on an integer. Using notation like this would work if o were (e.g.) a list or dictionary object. What are you trying to do with the expression 2*o[3] + o[2]?

    Also, you should remove the outer brackets from [yTruck[(tr,m-1,o)]]. Placing brackets around something will construct a list. Then, your mathematical expression includes the product or sum of a list and a number, which doesn't quite make sense.

    Finally, assuming yTruck and zTruck are Gurobi variables, you can remove the parentheses from inside their corresponding index brackets (though keeping the parentheses shouldn't cause any problems).

    I hope this helps!



Please sign in to leave a comment.