Max of value and if negative, return 0 (gurobipy)
AnsweredHi,
I am trying to currently implement a lp with gurobipy, where some of the decision variables have a max function in it. The constraint I want to implement looks like this:
where e[j] and t[j] are my continuous decision variables and are defined as:

So far, I've tried to solve it like this according to my research of similar problems but it is still not working, as my lp now becomes infeasible although it shouldn't:
for j in range(n):
model.addConstr(e_sum[j] == d[j] - c[m-1,j,(s[j]) - 1])
model.addConstr(t_sum[j] == c[m-1,j,(s[j]) - 1] - d[j])
# Constraint
for j in range(n):
model.addGenConstrMax(e[j], [e_sum[j], 0.0])
model.addGenConstrMax(t[j], [t_sum[j], 0.0])
model.addConstr(c[m-1,j,(s[j]) - 1] - t[j] + e[j] == d[j], 'Constraint')
-
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,
This can happen if the variables \(e_{sum}^j\) and \(t_{sum}^j\) are defined to be always \(\geq 0\). When adding a variable to the model, its lb is set to 0 by default. If these variables can take negative values, make sure to set the lb accordingly. For example, you can set it to \(-\mbox{float("inf")}\).
If this is not the cause of infeasibility in your model, you might want to check out the article How do I determine why my model is infeasible?
Best regards,
Maliheh
0
Post is closed for comments.
Comments
2 comments