KeyError: 'Duplicate keys in Model.addVars()'
回答済みHi
I am trying to generate binaries variables z with a list of two-tuples as follows:
ik_list = [(0,1), (0,2), (1,1), (1,2)]
ik = gp.tuplelist(ik_list)
z = bao1.addVars(ik, GRB.BINARY, 'allocation')
But I get the following error:
KeyError: 'Duplicate keys in Model.addVars()'
each tuple is different, I don't understand why I am getting this error.
Thank you for your help.
0
-
正式なコメント
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?. -
The keys for the tupledict built by Model.addVars() are derived from the positional arguments you pass in. In your case, this means the list of keys are the Cartesian product of the iterables \( \texttt{ik} \), \( \texttt{GRB.BINARY} \) (equivalent to \( \texttt{'B'} \)), and \( \texttt{'allocation'} \):
(0, 1, 'B', 'a')
(0, 1, 'B', 'l')
(0, 1, 'B', 'l')
(0, 1, 'B', 'o')
...
(1, 2, 'B', 't')
(1, 2, 'B', 'i')
(1, 2, 'B', 'o')
(1, 2, 'B', 'n')To resolve the issue, use the proper keyword arguments to specify the VType and VarName variable attributes:
z = bao1.addVars(ik, vtype=GRB.BINARY, name='allocation')
0 -
Thank you, it works.
0
投稿コメントは受け付けていません。
コメント
3件のコメント