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

General expression : min_ or max_

回答済み

コメント

3件のコメント

  • 正式なコメント
    Simranjit Kaur
    • 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

    The min_() helper function can only be used to set one variable equal to a group of variables and/or constants. This would be used if, e.g., you want to add a constraint like \( x = \min\{y, z, 2\} \), where \(x\), \(y\), and \(z\) are variables.

    In your case, the elements of \( \texttt{index} \) are not variables. Thus, the minimum of \( \texttt{100} \) and \( \texttt{sum(100 for i in index if i.id == 0)} \) is a constant value that doesn't depend on any variables. This means you can use Python's built-in \( \texttt{min()} \) function:

    model.addConstr(quicksum(100*schedule[i] for i in index) <= 100 - min(100, sum(100 for i in index if i.id == 0)))

    Note that I used Python's built-in \( \texttt{sum()} \) function instead of Gurobi's quicksum() function. The latter returns a LinExpr object, which won't work well with \( \texttt{min()} \).

    0
  • Sung Ook Hwang
    • Gurobi-versary
    • First Comment
    • First Question

    Thank you Eli for your help!

    0

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