key Error in objective function
回答済みI am trying to formulate an objective function but getting a key error. I have tried to unpack the tuple but it's giving me a syntax error. Could anyone help me figure this out?
The issue is with variable u[o,d,a].
o and d are lists with single elements, but a is a list with tuples. I am getting the following key error:
KeyError: (14, 4, (1, 2))
I guess I need to have (14,4,1,2) but because A is a list of tuple, I am getting the above key error. I tried to unpack the tuple using quicksum((c[a]*u[o,d,*a]), but it is showing syntax error. Any help would be really appreciated.
# Variables:
y=mdl.addVars(D,vtype=GRB.BINARY,name="y")
x=mdl.addVars(O,D,vtype=GRB.INTEGER,name='x')
w=mdl.addVars(O,vtype=GRB.INTEGER,name="w")
z=mdl.addVars(A,vtype=GRB.BINARY, name="z")
u=mdl.addVars(O,D,A,vtype=GRB.BINARY, name="u")
v=mdl.addVars(O,D,A,vtype=GRB.INTEGER, name="v")
#objective
obj=quicksum(f[d]*y[d] for d in D)+ quicksum( g[a]*z[a] for a in A) + quicksum((c[a]*u[o,d,a]) for a in A for o in O for d in D )+quicksum(alpha*w[o] for o in O)
-
正式なコメント
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?. -
Could you also post the definition of \(\texttt{O,D,}\) and \(\texttt{A}\) to make the example reproducible?
Did you try accessing the values of \(\texttt{u}\) via
u[o,d,a[0],a[1]]
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント