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

Retrieve a specific subset value of variables

回答済み

コメント

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 Sander,

    There are several ways you could do this in python (or our interactive interface).  Here is one approach:

    ind = (1,0,0)  # the a,b,c values you want to match
    eps = 1e-6  # tolerance to use for comparison in case values are not exactly 1
    largest_t = sorted([t for (a,b,c,t),v in X.items() if (a,b,c) == ind and abs(v.X - 1) < eps])[-1]

    In this approach we loop through the X dictionary (whose values are variables) with a list comprehension, finding those t values for which the a,b,c indices match and whose variable value is 1 (or close enough to 1).  The list of t values is then sorted from smallest to largest and we take the last one using the -1 index.

    Note this approach will result in a list index out of range error if there are no t values which satisfy the condition.

    - Riley

    0
  • Sander Mertens
    • Gurobi-versary
    • Curious
    • Conversationalist

    Thank you, works perfect!

    0

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