TypeError: list indices must be integers, not tuple

862 views
Skip to first unread message

ชวิศ บุญมี

unread,
Jun 27, 2016, 5:25:40 AM6/27/16
to Gurobi Optimization
How I can solve this problem?
I just have started to use it, So I would like some advise.
The error is

Traceback (most recent call last):
  File "C:/Users/proje201/Desktop/python/test3", line 39, in <module>
    m.addConstr(y[i,j]*d[i,j]<=30,"Limit_distance_%s_%s"%(i,j))
TypeError: list indices must be integers, not tuple

May be have some problem with parameter "d"
that I input

d = [[10,20,30],
    [20,30,10],
    [30,10,20],
    [10,40,30],
    [40,10,20]]

Please recommend and solve this problem for me
I have attached file in this email too.
best regards



test3

Renan Garcia

unread,
Jun 27, 2016, 8:33:25 AM6/27/16
to gur...@googlegroups.com
In your case, y is a dictionary of variables, where the keys are tuples. Thus, you would refer to a specific variable using y[i,j].

However, d is a list of lists of coefficients. Therefore, you must refer to a specific coefficient using d[i][j].

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<test3>

Reply all
Reply to author
Forward
0 new messages