メインコンテンツへスキップ

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

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • Gurobi Staff
    This post is more than two 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 try Gurobot, our chatbot interface offering instant, expert-level support.
  • 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

投稿コメントは受け付けていません。