Skip to main content

Adding MVars in indicator function

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?.
  • Jaromił Najman
    • Gurobi Staff Gurobi Staff

    Hi,

    Could you try using Vars instead of MVars for \(\texttt{assignment}\) and \(\texttt{unfair_assignment}\) variables? The reason is that MVars are meant to be used in matrix operations and not scalar multiplication as in your case.

    We're aware of this limitation and hope to make MVar objects compatible with general constraint functions in a future release.

    Best regards,
    Jaromił

    0
  • Maliheh Aramon
    • Gurobi Staff Gurobi Staff
    Hi,
     
    Gurobi 10.0  was recently released. Included in this release is the extension of Gurobi Matrix API which enables natural model building using matrix based expressions relying on NumPy concepts such as vectorization and broadcasting.
     
    The new capabilities of modelling classes MVar, MLinExpr, and MQuadExpr are not still fully integrated with general constraints. The general constraints should be added by indexing the Matrix API classes. See the snippet below:
    m = gp.Model()

    A = np.random.rand(3, 3)
    b = np.random.rand(3, 2)
    x = m.addMVar(shape=(3, 2), name="x")
    y = m.addVars(3, 2, vtype=gp.GRB.BINARY, name="y")

    for i in range(3):
    for j in range(2):
    m.addConstr((y[i, j] == 1) >> (A[i, :] @ x[:, j] <= b[i, j]))
     
    Checkout the Matrix-friendly Modeling with Gurobipy webinar if you would like to learn more about this new functionality. 
     
    Please continue submitting new community posts for any bugs you might encounter in the
    future or for any comments/questions you might have. Users like you help to
    make Gurobi better!
     
    Best regards,
    Maliheh
    0

Post is closed for comments.