tupledict.select() does not work as expected
回答済みConsider the following MWE:
import gurobipy as gp
d = gp.tupledict([
((('AT','CH'),('BE','AT')), 1),
((('AT','CH'),('BE','DE')), 2),
((('AT','DE'),('BE','DE')), 3),
])
print(d.select(('AT','CH'), '*'))
I was thinking that the selction yields \(\texttt{[1, 2]}\). It does not but returns an empty list.
Is it possible however, to get the desired result?
0
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
The keys of a tupledict should be a tuple of scalar values, not tuple values. From the tupledict documentation:
Note that a \( \texttt{tupledict} \) key must be a tuple of scalar values (\(\texttt{int}\), \(\texttt{float}\), \(\texttt{string}\), ...). Thus, you can use \( \texttt{(1, 2.0, 'abc')}\) as a key, but you can't use \(\texttt{((1, 2.0), 'abc')}\).
You get the desired result if you use four strings as the tupledict keys instead of two tuples:
d = gp.tupledict([
(('AT', 'CH', 'BE', 'AT'), 1),
(('AT', 'CH', 'BE', 'DE'), 2),
(('AT', 'DE', 'BE', 'DE'), 3),
])
print(d.select('AT','CH', '*', '*'))0
投稿コメントは受け付けていません。
コメント
2件のコメント