model the minimization of sum of inverse functions
回答済みHello,
The problem I am solving is to minimize sum of 1/x[k] for k in range(n), under a set of linear constraints. I set the lower and upper bounds for each x[k] be greater than 0; therefore, 1/x is a convex function over the intervals.
Here is how I write the model in Gurobi,
x = model.addVars(n, lb = -GRB.INFINITY, ub = GRB.INFINITY, vtype=GRB.CONTINUOUS, name = 'x')
for i in range(n):
model.addConstr(x[i] <= upper[i]) # upper bounds are greater than 0
model.addConstr(x[i] >= lower[I]) # lower bounds are also greater than 0
# add some additional linear constraints here
model.setObjective(quicksum(1/x[i] for i in range(n)), GRB.MINIMIZE)
Then Gurobi gives me the following error
unsupported operand type(s) for /: 'int' and 'Var'
My first question is, can Gurobi recognize this model as a convex program as I expected?
Then, I tried to reformulate the problem by introducing additional variables z[k] for k in range(n), and adding constraints
for i in range(n):
model.addConstr(1 <= z[i]*x[i])
The new objective function is
model.setObjective(quicksum(z[i] for i in range(n)), GRB.MINIMIZE).
My expectation is to solve my original problem as a convex optimization by Gurobi. Even though I could get outputs by introducing variables z, the set of additional constraints 1 <= z[i]x[i] are not convex constraints.
How could I model my original problem as a convex program?
Thank you.
-
正式なコメント
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 Miranda,
Indeed, your problem can be solved as a second order cone problem. You can reformulate
\[ x \cdot z \geq 1\]
as
\[ \begin{align}x^2 + x\cdot z + z^2 - x^2 - z^2 &\geq 1\\
(x + z)^2 &\geq x^2 + z^2 + 1\\
x + z & \geq \sqrt{x^2 + z^2 + 1} \end{align}\]which is a rotated second order cone. Thus, Gurobi reformulates your problem and can solve it as a convex problem. You do not have to set the NonConvex parameter. Note that this is possible as long as \(x,z \geq 0\)
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
2件のコメント