Adding a quadratic constraint as a ratio of two expressions to a model
回答済みI am writing an optimization problem using GurobiPy. My constraints are in the form of rational expressions. For e.g., assume the Model has one decision variable, 'c', and a bunch of penalty variables, where I want to minimize the sum of the penalty variables. A minimal working code is:
import gurobipy as gp
from gurobipy import GRB
n_pen = 6
m = gp.Model()
var = []
var.append(m.addVar(lb=c_lb, ub=c_ub, vtype=GRB.CONTINUOUS, name=("c")))
for i in range(n_pen):
var.append(m.addVar(lb=pen_lb, ub = pen_ub, vtype=GRB.CONTINUOUS, name=("n_pen%d" %i)))
m.update()
m.setObjective(gp.quicksum(var[i] for i in range(1,n_pen+1)),GRB.MINIMIZE)
The constraint is of the form:
c^4/(2*(c^4-1))+n_pen0 == 1
I know raising a variable to a power of '4' is not possible directly and neither can I have an expression in the denominator. For the denominator part, the constraint can be modified to c^4 - 2*c^4*n_pen0+2*n_pen == 2 but it gives another problem, a constraint probably cannot be built as a product of three terms.
Is there a way to write a constraint for the expressions I listed above?
regards,
-
正式なコメント
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 why not try our AI Gurobot?. -
Hi Syed,
Did you have a look at our Knowledge Base articles How do I model multilinear terms in Gurobi? and How do I divide by a variable in Gurobi? For the polynomial terms, you might want to use the addGenConstrPow() or the addGenConstrPoly() function.
These most likely will provide you the answer.
Best regards,
Jaromił0 -
Hi Jaromil,
Thanks for your response. I did not look at the two articles you referred to but I was able to resolve this last night by just using the addGenConstrPow() to generate my power terms and then add the expression directly as a constraint. For the division, I cross multiplied to remove any denominator term. I didn't use addGenConstrPoly() but it may help in having a clean code.
0
投稿コメントは受け付けていません。
コメント
3件のコメント