Skip to main content

Adding a constraint with multiple MVar

Answered

Comments

3 comments

  • Official comment
    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

    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

Post is closed for comments.