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

Adding Quadratic constraint

回答済み

コメント

2件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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

    Have you tried the matrix-friendly Python API? It interacts well with NumPy ndarrays and SciPy sparse matrices. For example, we can add a constraint of the form \( x^\top Q x \leq 1 \) as follows:

    x = m.addMVar(3)
    Q = np.random.rand(3, 3)
    m.addConstr(x @ Q @ x <= 1)

    Note that we use MVar objects with this syntax, not Var objects. The expression \( \texttt{x @ Q @ x} \) is of type MQuadExpr instead of QuadExpr.

    For more examples, see matrix1.py and matrix2.py. Both of these are included in your Gurobi installation.

    0

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