Skip to main content

gurobipy.GurobiError: Second tuple member should be a Var

Ongoing

Comments

6 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff 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?.
  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    Hi,

    Could you provide a minimal reproducible example showing this issue?

    Best regards,
    Jaromił

    0
  • SAMAN ESKANDARZADEH
    Gurobi-versary
    First Comment
    First Question

    Thanks. I found out what the problem was. I had simplified my question but it turned out that the source of the error was in the parts, I had excluded. 

    0
  • Shashank Vats
    Gurobi-versary
    First Comment
    First Question

    Hey SAMAN ESKANDARZADEH,

    I'm facing the same issue while using LinExp(). Can you please let me know how you solved this issue? 

    0
  • SAMAN ESKANDARZADEH
    Gurobi-versary
    First Comment
    First Question

    Hey Shashank,

    It was a while ago, I do not recall it exactly, however, I think the problem was that for some (i,j) in the index_pair, there was not a corresponding variable defined. So for example tuple (2,3) was in index_pairs but x[2,3] was not defined as a var. I hope this helps.   

     

    0
  • Shashank Vats
    Gurobi-versary
    First Comment
    First Question

    Hi SAMAN ESKANDARZADEH,

    Thanks for the reply!

    In my case, I'm using the following statement:

    objective_func = LinExpr((dict1_ijk.get((i, j, k), 0) *
    dict2.get((d, l),0), dict3_dijl.get((d, i, j, l),0))

    for d in list1 for j, k, l in list2
    for i in dict4_j[j] )

    In the code snippet above, the second element of the LinExp() function, dict3_dijl.get((d, i, j, l),0), should be Var type but since I'm using get() function to check if that variable is present or not and returning 0 if its not, I'm being thrown with the error telling the second tuple member should be Var (the get() function is returning 0 when the variable is not present).

    Can you suggest a way to get past this error? 

    0

Post is closed for comments.