-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
I think I found a bug which occurs when using the flags --intermediate
, and not finding any solutions. objective(self)
in src/minizinc/result.py
picks out the last element in a list inside getattr
-function. I think this causes a bug as when we have no solution, solve()
in src/minizinc/instance.py
returns an empty list which results in IndexError: list index out of range
.
Here is the code in result.py
, I think a simple if-statement is enough to fix it.
@property
def objective(self) -> Optional[Union[int, float]]:
"""Returns objective of the solution
Returns the objective of the solution when possible. If no solutions
have been found or the problem did not have an objective, then None is
returned instead.
Returns:
Optional[Union[int, float]]: best objective found or None
"""
if self.solution is not None:
if isinstance(self.solution, list):
return getattr(self.solution[-1], "objective", None) # <----- here is the bug
else:
return getattr(self.solution, "objective", None)
else:
return None
Please let me know if I have just misunderstood something (and it is not an actual bug).
Metadata
Metadata
Assignees
Labels
No labels