Skip to main content

KeyError: 0e

Answered

Comments

2 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • 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

Post is closed for comments.