X-Git-Url: https://svn.cri.ensmp.fr/git/linpy.git/blobdiff_plain/6f888673868879dfd38050bcaedb93c7fd5bac66..4af78812d25b28cee283e671c0bd5944133b6ce5:/linpy/linexprs.py?ds=sidebyside diff --git a/linpy/linexprs.py b/linpy/linexprs.py index ab5d344..a49f90e 100644 --- a/linpy/linexprs.py +++ b/linpy/linexprs.py @@ -178,8 +178,7 @@ class LinExpr: Iterate over the coefficient values in the expression, and the constant term. """ - for coefficient in self._coefficients.values(): - yield coefficient + yield from self._coefficients.values() yield self._constant def __bool__(self): @@ -248,9 +247,10 @@ class LinExpr: """ Test whether two linear expressions are equal. """ - return isinstance(other, LinExpr) and \ - self._coefficients == other._coefficients and \ - self._constant == other._constant + if isinstance(other, LinExpr): + return self._coefficients == other._coefficients and \ + self._constant == other._constant + return NotImplemented def __le__(self, other): from .polyhedra import Le @@ -273,9 +273,9 @@ class LinExpr: Return the expression multiplied by its lowest common denominator to make all values integer. """ - lcm = functools.reduce(lambda a, b: a*b // gcd(a, b), + lcd = functools.reduce(lambda a, b: a*b // gcd(a, b), [value.denominator for value in self.values()]) - return self * lcm + return self * lcd def subs(self, symbol, expression=None): """ @@ -498,7 +498,9 @@ class Symbol(LinExpr): return True def __eq__(self, other): - return self.sortkey() == other.sortkey() + if isinstance(other, Symbol): + return self.sortkey() == other.sortkey() + return NotImplemented def asdummy(self): """