addGenConstrMax:'gurobipy.LinExpr' object has no attribute '__cindex__'
AnsweredI was trying to add a constraint as following:
for i in demand_list:
maxVarsList = [data1.loc[i,j]*x[j] for j in truck_list]
m.addGenConstrMax(sum(z[i,j] for j in truck_list), maxVarsList)
note: x[j] is a binary decision variable, z[i,j] is a decision variable, data1.loc[i,j] is a given variable.
AttributeError: 'gurobipy.LinExpr' object has no attribute '__cindex__'
How to add this max constraint correctly?
-
Official comment
This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Dear Yutong,
could you please share a minimal reproducible example of the code which throws the error you mention?
Best regards
Jonasz0 -
Dear Yutong,
On top of providing a minimal reproducible example as noted by Jonasz, please note that the addGenConstrMax method does not accept an expression as its input. You have to provide a single optimization variable as first argument. Thus, you have to introduce an auxiliary variable \(aux\) and add the auxiliary equality constraint \(aux = \sum z_{ij}\), \(aux = \max(\dots)\).
Best regards,
Jaromił0
Post is closed for comments.
Comments
3 comments