メインコンテンツへスキップ

Implementing SOCP Constraints Using Python

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    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?.
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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
  • ari
    • Gurobi-versary
    • First Question
    • First Comment

    Thank you so much for the help!!

    0

投稿コメントは受け付けていません。