Property error : ‘gurobipy. LinExpr’ object has no attribute ‘__colno__’… here is a solution to the problem.
Property error : ‘gurobipy. LinExpr’ object has no attribute ‘__colno__’
I’m trying to model a MILP problem using Python and Gurobi Solver. I have the latest version of the Gurobi solver. My problem started after I added a constraint using the new function of gurobi m.addGenConstrAbs, which added the abs value of the function as a constraint. Here is my code, which creates a gurobi feedback:
AttributeError: ‘gurobipy. The LinExpr’ object does not have the attribute ‘__colno__’.
My code that generated this feedback is:
for t in range(0,Period):
m.addGenConstrAbs(PEN[t], EG [t]+STG[t]-XXX, "PEN Constraint")
where EG[t],
STD[t], and XXX are decision variables.
I don’t understand why Gurobi or Python return this error. What do you think the problem is? Thank you.
Solution
Model.addGenConstrAbs() must be a variable (Var
), not a linear expression (LinExpr
). Try this :
for t in range(0,Period):
z = m.addVar(lb=-GRB. INFINITY)
m.addConstr(z == EG[t]+STG[t]-XXX)
m.addGenConstrAbs(PEN[t], z, "PEN Constraint")