tupledict.select() does not work as expected
AnsweredConsider 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
-
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
Please sign in to leave a comment.
Comments
1 comment