Skip to main content

Use min_ to get element wise minimum of a MVar and 1

Answered

Comments

2 comments

  • Riley Clement
    • Gurobi Staff

    Hi Weihang,

    The elements in your "product array" are gurobipy.MLinExpr.  The initial arguments to gurobipy.min_ need to be variables.  You can fix this by introducing auxiliary variables like so:

    # could be INTEGER if numbers in "condition matrix" are integer
    product_aux = m.addMVar(n2, vtype=gp.GRB.CONTINUOUS)

    for i in range(n2):
        m.addConstr(product_aux[i] == product[0, i])
        m.addConstr(binary[0, i] == gp.min_(product_aux[i] , 1))

    - Riley

    0
  • Weihang Zhang
    • Gurobi-versary
    • First Comment
    • First Question

    Hi Riley,

    Thanks very much for the answer. It is clear now why it was not working previously. Really appreciate the help!

    0

Please sign in to leave a comment.