Skip to main content

How to sum up the values of a gurobi variable

Answered

Comments

2 comments

  • Official comment
    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

    This should give you a list of the values:

    idle = [v.X for v in idle_time.values()]

    You can add \( \texttt{if v.X > 0.5} \) to the list comprehension, though then the list wouldn't include idle times between \( 0 \) and \( 0.5 \) (inclusive).

    It looks like you added the \( \texttt{idle_time} \) variables using Model.addVars(). If so, you could alternatively combine tupledict.sum() and LinExpr.getValue() to calculate the sum of idle times:

    idle = idle_time.sum().getValue()

    This approach will sum all of the idle times, including those between \( 0 \) and \( 0.5 \).

    0

Post is closed for comments.