Formulate constraints "<" ">"
AnsweredHello together,
i want to implement a transition of the continous variable e[a] into the binary variable ej[a,t]. Therefore 7 constraints are necessary. 5 of them are expressed by ">=". For the otherones I need a ">" constraint. Gurobi doesn't allow this expression. The question is: Can I reformulate the constraints to meet Gurobis needs.
As you can see below, I tried to fix the problem by the mathematical incorrect way. This leads to the "unfeasibility or unbounded" - Error in some cases. This is because some e[a] values cause mutually exclusive ej[a,t].
Can anyone help please. I apprechite it.
Example of what the code should do (and also does for most e[a] values)
e[a1] =0.68 --> ej[a1, t0] =0, ej[a1, t1] =1, ej[a1, t2] =0, ej[a1, t3] =0, ...
e[a2] =2.1 --> ej[a1, t0] =0, ej[a1, t1] =0, ej[a1, t2] =1, ej[a1, t3] =0, ...
Implementation:
for a in A:
for t in T:
model.addConstr(L*(1-PC)<=(e[a]-t)/BigM)
model.addConstr(U*PD>=(t+1-e[a])/BigM)
model.addConstr(ej[a,t]<=PC)
model.addConstr(ej[a,t]<=PD)
model.addConstr(ej[a,t]>=PC+PD-1)
model.addConstr(U * PC>=((e[a]-t)/BigM)+0.01) #instead of: (U * PC>(e[a]-t)/BigM)
model.addConstr(L*(1-PD)<=((-e[a]+t+1)/BigM)-0.01) #instead of: (L (1-PD)<(-e[a]+t+1)/BigM)
-
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 Moe,
You're on the right track. Adding a small constant is the best way of doing this.
Please see this article on strict inequalities.
Cheers,
David1 -
Hi David,
thanks for the answer. What is the smallest number that makes sense in this case?
Moe
0 -
Hi Moe,
I think any value greater than than FeasiblityTol (tolerance for constraints) makes sense to me: i.e. anything \(>\texttt{1.0e-6}\), otherwise equality will be accepted as a feasible constraint. But I'd try some different values to see what works best for your application.
Cheers,
David0
Post is closed for comments.
Comments
4 comments