You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When guessing the dimension in sets.py: Set.init from the initialize kwarg, nesting is ignored.
However when accessing keys they are flattened. This results in incorrect guesses for cases such as this:
constraints = {c for c in itertools.product(['constrA', 'constrB'], range(5))}
vars = {v for v in itertools.product(['var1', 'var2', 'var3'], range(5))}
matrix_coefficients = {m for m in itertools.product(constraints, vars)}
m = ConcreteModel()
m.Matrix = Param(matrix_coefficients, default=0)
>>> ValueError: The value=('constrB', 4, 'var1', 1) does not have dimension=2, which is needed for set=Matrix_index
The code that is causing this sits in sets.py lines 691-695:
if type(self.initialize) is tuple:
tmp = len(self.initialize)
elif type(self.initialize) is list and len(self.initialize) > 0 \
and type(self.initialize[0]) is tuple:
tmp = len(self.initialize[0])
One way to amended this is to flattening the entire self.initialize before checking with the current method or flattening the single element used for guessing, e.g. with pyutilib.misc.flatten.
If we're considering that nested containers other than tuple might occur, getattr seems more adequate than a direct len call.
Finally looking over init it seems like lines 691 and 692 are dead code, as tuples are already converted to lists in lines 682-685!
In summary it seems that changeing lines 691-695 to:
if type(self.initialize) is list and len(self.initialize) > 0:
tmp = getattr(flatten(self.initialize[0]), 'len', 0)
should fix this behaviour.
The text was updated successfully, but these errors were encountered:
When guessing the dimension in sets.py: Set.init from the initialize kwarg, nesting is ignored.
However when accessing keys they are flattened. This results in incorrect guesses for cases such as this:
The code that is causing this sits in sets.py lines 691-695:
One way to amended this is to flattening the entire
self.initialize
before checking with the current method or flattening the single element used for guessing, e.g. withpyutilib.misc.flatten
.If we're considering that nested containers other than tuple might occur,
getattr
seems more adequate than a directlen
call.Finally looking over init it seems like lines 691 and 692 are dead code, as tuples are already converted to lists in lines 682-685!
In summary it seems that changeing lines 691-695 to:
should fix this behaviour.
The text was updated successfully, but these errors were encountered: