Skip to main content

Abs value constraint for MLinExpr

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?.
  • Yuriy Zinchenko
    Gurobi Staff Gurobi Staff

    You can simply change your variable declaration from using MVar to regular Gurobi variables; the abs-value should work there without any issues.  Have you tried that by any chance?

     

     

    0
  • Maliheh Aramon
    Gurobi Staff Gurobi Staff
    Hi Christian,
     
    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.addMVar(shape=(3, 2), name="y")

    m.addConstr(A @ x == b)

    # We still do not support vectorization of the general constraints. The
    # constraints should be added via indexing
    for i in range(3):
    for j in range(2):
    m.addConstr(y[i, j] == gp.abs_(x[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.