An indice problem: TypeError: tuple indices must be integers or slices, not tuple
回答済みHello,
I define parameters, variables like following and used in the following constraint. When I check examples it seems OK but get an tuple error like following:
activities = [ "A","B","C","E","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"]
normal_durations = [2,4,6,10,2,2,3,6,4,2,6,4,4,8,4,1,2,3]
time = [x for x in range(1,29)]
b = [2,8,25,27.5,6.67,16,7,math.inf,math.inf,6,math.inf,5,0.9,1.3,9,math.inf,math.inf,1.5,2]
activity_decrease = m.addVars(activities,vtype=GRB.INTEGER, name="activity_decrease")
x = m.addVars(activities,time,vtype=GRB.BINARY, name="x")
#each task must be performed
m.addConstrs(gp.quicksum([x[j,t] for t in time]) == normal_durations[activities.index(j)] -
b[activities.index(j)]*activity_decrease[j] for j in activities )
Can you check my code please?
-
正式なコメント
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 why not try our AI Gurobot?. -
Hi,
You are using \(\texttt{math.inf}\) which is not compatible with Gurobi objects. You have to replace \(\texttt{math.inf}\) with \(\texttt{GRB.INFINITY}\). Still, the equality constraints you construct would be infeasible in this case, thus it would be best to omit the constraints were \(\texttt{b = inf}\).
m.addConstrs( gp.quicksum([x[j,t] for t in time]) ==
normal_durations[activities.index(j)] - b[activities.index(j)]*activity_decrease[j]
for j in activities if b[activities.index(j)] != math.inf )Best regards,
Jaromił0 -
Hi Jaromil,
Thanks for your correction. But there must be some other mistakes, since I've still got this error message after the correction.
I tried to reach out x values from console and got following:
x
Here is the some part of the output:

But when I reach out an object with clarifying its indices, I got the same error as well. Is there any mistake about calling the object ?

Best,
Cevat Enes
0 -
Hi Cevat,
I am not sure what you mean by "reach out an object with clarifying its indices" but could you try calling the model.update() after adding the variables?
Best regards,
Jaromił0 -
Hi Jaromil,
Sorry for not clear explanation..
I realized a difference in object type of these variables.Then I saw a comma after defining x variables. After I removed it, it seems OK, I got no error from there. So, thank you for all help :)

Best,
Cevat Enes
0
投稿コメントは受け付けていません。
コメント
5件のコメント