assyncronimous
assyncronimous

Reputation: 33

AttributeError: 'gurobipy.LinExpr' object has no attribute '__colno__'

I am trying to model a MILP problem using Python with Gurobi Solver. I have the latest Gurobi solver version. My problem started after I added a constraint with new function of gurobi m.addGenConstrAbs which add the abs value of the function as a constraint. Here is my code which create a gurobi feedback as:

AttributeError: 'gurobipy.LinExpr' object has no attribute '__colno__'.

My code which results with 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 returns with this error. What do you think the problem came from? Thanks.

Upvotes: 3

Views: 5929

Answers (1)

Greg Glockner
Greg Glockner

Reputation: 5653

The arguments to Model.addGenConstrAbs() must be variables (Var), not linear expressions (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") 

Upvotes: 3

Related Questions