'AttributeError: 'gurobipy.QuadExpr' object has no attribute 'getVar'

I am trying to solve a MILP problem using Python with Gurobi Solver. When I solve the model with the constraint (attached below), it appears the error like this: "AttributeError: 'gurobipy.QuadExpr' object has no attribute 'getVar'". Could you help me to fix this error? Thank you in advance!

mdl.addConstrs((t[i,k] * X[i,j,k] - te1[i] <= 5) >> (z1[i,k] == 1) for i,j,k in arcos if i != 0 and i != 23)

where: t[i,j]: a continuous variable; X[i,j,k], z1[i,k]: binary variables; te1[i]: a parameter



Solution 1:[1]

This is indeed not a very informative error message. Developers are notorious for not paying much attention to formulating good, meaningful error messages. They should. A better error message could have prevented this post.

Now to the underlying issue. An indicator constraint has the following structure:

binary variable = 0 ==> linear constraint 

or

binary variable = 1 ==> linear constraint 

You need to reformulate things to fit into this scheme. Or use a big-M formulation.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1