Hi! I am a beginner at Gurobi.
I have a very simple question.
I am appreciate if you would kindly reply me.
Thank you very much in advance.
A=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
capacity={1:100, 2:100, 3:100, 4:100,
5:100, 6:100, 7:100, 8:100,
9:100, 10:100, 11:100, 12:100,
13:100, 14:100, 15:100, 16:100
}
free_flow_travel_time={1:100, 2:100, 3:100, 4:100,
5:100, 6:100, 7:100, 8:100,
9:100, 10:100, 11:100, 12:100,
13:100, 14:100, 15:100, 16:100
}
N=16
alpha=10
beta=4
M=10000
k=2
model=Model("critical_combination")
x={}
for a in A:
x[a]=model.addVar(vtype="C", name="x(%s)"%(a))
u={}
for a in A:
u[a]=model.addVar(vtype="B", name="u(%s)"%(a))
t={}
for a in A:
t[a]=model.addVar(vtype="C", name="t(%s)"%(a))
model.update()
for a in A:
model.addConstr(quicksum(u[a])==N-k)
for a in A:
model.addConstr(t[a]==free_flow_travel_time[a]*{1+alpha*(x[a]/capacity[a])}+(1-u[a]*M))
model.setObjective(quicksum(x[a]*t[a] for a in A), GRB.MAXIMIZE)
model.optimize()
__________________________________________________________________________
However, I got two error messages.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-29-1857719c0de3> in <module>()
37
38 for a in A:
---> 39 model.addConstr(quicksum(u[a])==N-k)
40
41 for a in A:
gurobi.pxi in gurobipy.quicksum (../../src/python/gurobipy.c:128383)()
TypeError: 'Var' object is not iterable
2) second error mesage (if I comment out and skip the part of the first error message)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-30-a3f5b34a1f7b> in <module>()
40 """
41 for a in A:
---> 42 model.addConstr(t[a]==free_flow_travel_time[a]*{1+alpha*(x[a]/capacity[a])}+(1-u[a]*M))
43 model.setObjective(quicksum(x[a]*t[a] for a in A), GRB.MAXIMIZE)
44
TypeError: unhashable type: 'gurobipy.LinExpr'