How do I divide by a variable in Gurobi?
回答済みHi there,
I got a question regarding adding a constraint in which one variable is divided by the other. I read through the community posts and already read the : "How do I divide by a variable in Gurobi?". I tried to incooporate this method, but after doing so it says my model is infeasible. I think the main reason for this, is that method described in that article is based on the fact that lower bound of x will be > 0. Within my model, the lower bound of x needs to be 0, causing the infeasibility of the model.
What i try to model, is two different power flows. The first flow (a[t]) is pre determined and vizualizes that power that should be flowing . The second power flow (b[t]), represents the actual power that is flowing, caused by restrictions of a range of different constraints. If b[t] < a[t] a penalty will be given, proportionally to the reduced power flow:
b[t]/a[t] * fine.
However, when modeling this the optimizer gave the following error: Divisor must be a constant. Which brought me to the explanation given in this post: how do I divide by a variable.
I tried to apply this method by introducing an additional variable: AuxVar1.
and the following constraint: AuxVar1 * a[t] = 1
Then I rearranged the first equation to b[t] * AuxVar1[t] * fine. However, this made my model infeasible. Mainly, because I think I both a[t] and b[t] will be 0 from time to time, since there are moments when there is no power delivery. Making the lb = 0 and ub = GRB.INFINITY for both a[t] and b[t]. To overcome this challenge, I thought of introducing an additional AuxVar (2) with the following constraint:
gp.max_(a[t], 1) for t in range (T)
Than rewrite: AuxVar1 * a[t] = 1 to AuxVar1[t] * AuxVar2[t] = 1
However, I do not understand how to properly set the lb and ub of all the AuxVars. I currently set them to: lb = 1 and ub = GRB.INFINITY.
Using the above described method, my model gives the following error:
GurobiError: Invalid argument value for required parameter (when it refers to the line with: m.optimize())
Is there anyone that perhaps knows how to handle this above described problem? Or does someone have an idea for an alternative approach?
Thanks in advance!
-
正式なコメント
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 Johan,
Did you set the NonConvex parameter to 2, as suggested in the article you linked?
Additionally, for the second auxiliary variable, which you defined as:
gp.max_(a[t], 1) for t in range (T)
Are there cases where \(a[t] \in (0, 1)\)? If yes, you may want to choose a different constant than 1 to supply to the max function - you risk distorting the denominator value this way.
Best regards
Jonasz0 -
Hi Jonasz,Yea the NonConvex parameter is set to 2.Fortunately, there are nog values between 0 and 1 for a.Therefore, this approach should work in my opinion.However, I still encounter the infeasibility.Do you perhaps have a tip on how to trackdown where this infeasibility is caused?Regards,Johan0
-
Normally I would compute an IIS. This article will tell you how to achieve this.
Best regards,
Jonasz0 -
Hi Jonasz,
I figured it out!
The approach for the divison variable worked.
Thanks for the help
Regards
0
投稿コメントは受け付けていません。
コメント
5件のコメント