gurobipy.GurobiError: Second tuple member should be a Var
OngoingHello,
I have a constraint as follows that produces error "gurobipy.GurobiError: Second tuple member should be a Var". I do not know how to resolve this.
model.addConstrs(y[j]-y[i] <= (1 - x.sum(i, '*')) for (i, j) in index_pairs)
The full error message is as follows:
ERROR:root:Traceback (most recent call last):
File "/DataWarehouse/BreakPolicyComparisonProject/MutipleVehicle/main.py", line 111, in pricing_mip
planning_quantities, dic_distance_matrix, service_time_task, CAPACITY,dual_values)
File "\DataWarehouse\BreakPolicyComparisonProject\MutipleVehicle\sample_models.py", line 163, in generate_pricing_mip_model
1 - var_consecutive_visits_pairs.sum(i, '*')) for (i, j) in index_pairs)
File "src\gurobipy\model.pxi", line 3443, in gurobipy.Model.addConstrs
File "\DataWarehouse\BreakPolicyComparisonProject\MutipleVehicle\sample_models.py", line 163, in <genexpr>
1 - var_consecutive_visits_pairs.sum(i, '*')) for (i, j) in index_pairs)
File "src\gurobipy\linexpr.pxi", line 483, in gurobipy.LinExpr.__mul__
File "src\gurobipy\quadexpr.pxi", line 45, in gurobipy.QuadExpr.__init__
File "src\gurobipy\linexpr.pxi", line 47, in gurobipy.LinExpr.__init__
gurobipy.GurobiError: Second tuple member should be a Var
-
Official comment
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?. -
Hi,
Could you provide a minimal reproducible example showing this issue?
Best regards,
Jaromił0 -
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 -
Hey SAMAN ESKANDARZADEH,
I'm facing the same issue while using LinExp(). Can you please let me know how you solved this issue?
0 -
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 -
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.
Comments
6 comments