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

Adding a constraint with multiple MVar

回答済み

コメント

3件のコメント

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

    You could convert the constant vector to a (sparse) diagonal matrix, then build the constraint using Gurobi's support for matrix multiplication:

    import gurobipy as gp
    import numpy as np
    import scipy.sparse as sp

    m = gp.Model()

    x = m.addMVar(3, name='x')
    y = m.addMVar(3, name='y')

    a = np.array([4, 5, 3])
    m.addConstr(x <= sp.diags(a) @ y)
    0
  • Andreas Morr
    • Gurobi-versary
    • First Comment
    • First Question

    Thanks for the great answer! Works perfectly.

    0

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