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

749 views
Skip to first unread message

Assyncronimous

unread,
Mar 21, 2017, 8:21:55 AM3/21/17
to Gurobi Optimization

0
down vote
favorite
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.

Renan Garcia

unread,
Mar 21, 2017, 8:28:41 AM3/21/17
to gur...@googlegroups.com
As specified in http://www.gurobi.com/documentation/7.0/refman/py_model_addgenconstrabs.html, the second argument for Model.addGenConstrAbs() should be a variable. If you need the absolute value for an expression in your model, just introduce an auxiliary variable that stores the value of the expression, and then use that variable as the argument for Model.addGenConstrAbs().

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Espinoza

unread,
Mar 21, 2017, 8:31:45 AM3/21/17
to Gurobi Optimization
My guess would be that PEN[t] should be declared as a variable before... is that so?

Assyncronimous

unread,
Mar 22, 2017, 7:36:21 AM3/22/17
to Gurobi Optimization
Thanks @Renan Garcia, it works now with creating a slack variable.
Reply all
Reply to author
Forward
0 new messages