Retrieve a specific subset value of variables
回答済みHello,
Is there a way to retrieve the value of a subset from a specific variable within Gurobi?
For instance, allot of X variables are created in the form of X[a,b,c,t]. After optimization, I want to retrieve for a variable with a specific a,b,c combination (lets say 'X[1,0,0'), the largest value of t of all the instances where this X[1,0,0,t] = 1.
-
正式なコメント
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. -
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 1largest_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
Xdictionary (whose values are variables) with a list comprehension, finding thosetvalues for which thea,b,cindices match and whose variable value is 1 (or close enough to 1). The list oftvalues is then sorted from smallest to largest and we take the last one using the -1 index.
Note this approach will result in alist index out of rangeerror if there are notvalues which satisfy the condition.- Riley
0 -
Thank you, works perfect!
0
投稿コメントは受け付けていません。
コメント
3件のコメント