Implementing SOCP Constraints Using Python
回答済みHello,
I've been reading the documentation, and searching the forum (apologies if I've missed it), but am not sure how to correctly implement an SOCP constraint in Gurobi using the Python interface. Here is the problem:
$$\begin{align} \min\limits_{x} q^T x \\ \text{s.t.} \quad &||Dx|| \leq c^{T} x \\ &0 \leq x_i \; \forall i = 1, \ldots, n\end{align}$$
x is an n-dimensional variable input using addMVar
q, D, c are all known (D is p.s.d.)
I attempted to follow this post: https://groups.google.com/forum/#!topic/gurobi/UlCbvUjCs_w . Any help would be greatly appreciated. Thanks!
-ari
-
正式なコメント
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 Ari,
We can do this by introducing an auxiliary n-dimensional MVar \( u = Dx \) and a nonnegative one-dimensional MVar \( y = c^\top x \). Then, we add the constraint \( u^\top u \leq y^2 \). For example:
import gurobipy as gp
import numpy as np
m = gp.Model()
x = m.addMVar(3, name="x")
u = m.addMVar(3, lb=-gp.GRB.INFINITY, name="u")
y = m.addMVar(1, name="y")
D = np.array([[2,-1,0],[-1,2,-1],[0,-1,2]])
c = np.array([1, 2, 3])
m.addConstr(u == D @ x)
m.addConstr(y == c @ x)
m.addConstr(u @ u <= y @ y)I hope this helps!
Eli
0 -
Thank you so much for the help!!
0
投稿コメントは受け付けていません。
コメント
3件のコメント