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

KeyError: 0e

回答済み

コメント

1件のコメント

  • Riley Clement
    • Gurobi Staff

    Hi Maide,

    If you were to print the keys of your y tupledict you would see the following

    >> print(y.keys())
    <gurobi.tuplelist (50 tuples, 3 values each):
     ( 0 , 0 , B )
     ( 0 , 1 , B )
     ( 0 , 2 , B )
     ( 0 , 3 , B )
    ...

    There is a third index with values "B" that you did not intend and this will give you a clue as to what is happening.

    Let's review the method signature for addVars from the reference manual:

    addVars ( *indices, lb=0.0, ub=float('inf'), obj=0.0, vtype=GRB.CONTINUOUS, name="" ) 

    The * has special meaning here and allows an arbitrary number of arguments, to index the variables, to be passed to the function.  However this means that every parameter that comes after it must have arguments passed via keyword.  This is why GRB.BINARY ( = "B") is being interpreted as another indice.

    So to fix this pass the vtype via keyword, i.e. vtype=GRB.BINARY (or vtype="B").

    - Riley

    0

サインインしてコメントを残してください。