'<' not supported between instances of 'Var' and 'int'
AnsweredDear all,
I'm trying to make a constraint for the maximum capacity of the vehicle. I have k-vehicle, with maximum capacity in d[k]. I don't want the current capacity x[i,k] reach to d[k]
for k in vehiculos:
for i,k in arco_qua:
mdl.addConstrs((x[i,k] < d[k])
which results error '<' not supported between instances of 'Var' and 'int'.
-
Official comment
This post is more than three 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. -
Hi Putri,
Please note that in math programming there are no strict inequalities. You need to model such restrictions by adding a small tolerance, e.g.
mdl.addConstr(x[i,k] + eps <= d[k])
You should also not use outer for-loops and then call the \(\texttt{addConstrs}\) method - note the difference between Model.addConstr() and Model.addConstrs(). And you are using the same index \(\texttt{k}\) for both loops - this is not going to work. You should always use dedicated loop indices.
Cheers,
Matthias0 -
Hi Matthias, thanks for your great insight!
I already put the epsilon:
mdl.addConstr((x[i,k] + eps <= d[k]) for i,k in arco_qua for k in vehiculos)
where
n = 11
nodes = [i for i in range(n)]
vehiculos = [1,2,3,4]
arco_qua = [(i,k) for i in nodes for k in vehiculos]which result TypeError: unsupported operand type(s) for -: 'generator' and 'NoneType'
0 -
Hi Putri!
Please review the two links to addConstr and addConstrs that I shared above. You have to use the 's' variant if you want to use Python list comprehensions inside the call. The addConstr method is only going to create a single constraint and cannot be used with an included for loop in the argument.
And again: please don't re-use the same variable name 'k' in different loops. This is going to create all kinds of issues and you should double check that you really add those constraints that you intend to add.
I hope that helps.
Cheers,
Matthias0 -
You might also want to check out this article about strict inequalities: Why doesn't Gurobi support strict inequality constraints like x < a?
0
Post is closed for comments.
Comments
5 comments