Skip to main content

gurobipy.GurobiError: Second tuple member should be a Var

Ongoing

Comments

5 comments

  • 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

Please sign in to leave a comment.