TypeError: must be real number, not TempConstr
AnsweredHi
When I add the following constraint and execute it, an error occurs:
for k in orders:
for t in range(1, 60):
if t <= k.rk:
m.addConstr((t <= tao[k.no]) * (h[k.no, t] - k.rate + gp.quicksum(x[k.no, p.no] for p in orders_paths[k.no - 1] if t == p.arvt))\
== h[k.no, t + 1])
TypeError: must be real number, not TempConstr
I tried rewriting the constraint like the following,
for k in orders:
for t in range(1, 60):
if k.rk <= t <= tao[k.no]:
m.addConstr(h[k.no, t] - k.rate + gp.quicksum(x[k.no, p.no] for p in orders_paths[k.no - 1] if p.arvt == t ) == h[k.no, t + 1])
but then I get this error
GurobiError: Constraint has no bool value (are you trying "lb <= expr <= ub"?)
where tao_k is the decision variable.
and I need to determine the size of t and tao.
Can you check my code please?
Many thanks in advance!
-
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. -
As you said \(\texttt{tao}\) is an optimization variable. Thus, it does not have any value during model construction and you cannot use it in an if-condition. You have to model the conditional statement through modeling with additional constraints and variables.
The Knowledge Base article How do I model conditional statements in Gurobi? should be helpful.
0 -
Thanks. I will try to reconstruct the constraint using the method you mentioned.
0
Post is closed for comments.
Comments
3 comments