Skip to main content

tupledict.select() does not work as expected

Answered

Comments

1 comment

  • Eli Towle
    Gurobi Staff Gurobi Staff

    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.