メインコンテンツへスキップ

KeyError: 'Duplicate keys in Model.addVars()'

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    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?.
  • Eli Towle
    • Gurobi Staff

    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
  • Cipriano Santos
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you, it works.

    0

投稿コメントは受け付けていません。