Skip to main content

Adding a constraint with multiple MVar

Answered

Comments

2 comments

  • Eli Towle
    Gurobi Staff 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

Please sign in to leave a comment.