X-Git-Url: https://scm.cri.ensmp.fr/git/linpy.git/blobdiff_plain/7b93cea1daf2889e9ee10ca9c22a1b5124404937..7fff25bf40e4db570565586fb49165d1675002c2:/linpy/polyhedra.py?ds=sidebyside diff --git a/linpy/polyhedra.py b/linpy/polyhedra.py index e9226f2..8eddb2d 100644 --- a/linpy/polyhedra.py +++ b/linpy/polyhedra.py @@ -35,7 +35,9 @@ __all__ = [ class Polyhedron(Domain): - + """ + Polyhedron class allows users to build and inspect polyherons. Polyhedron inherits from Domain. + """ __slots__ = ( '_equalities', '_inequalities', @@ -45,6 +47,10 @@ class Polyhedron(Domain): ) def __new__(cls, equalities=None, inequalities=None): + """ + Create and return a new Polyhedron from a string or list of equalities and inequalities. + """ + if isinstance(equalities, str): if inequalities is not None: raise TypeError('too many arguments') @@ -74,21 +80,21 @@ class Polyhedron(Domain): @property def equalities(self): """ - Return a list of the equalities in a set. + Return a list of the equalities in a polyhedron. """ return self._equalities @property def inequalities(self): """ - Return a list of the inequalities in a set. + Return a list of the inequalities in a polyhedron. """ return self._inequalities @property def constraints(self): """ - Return ta list of the constraints of a set. + Return the list of the constraints of a polyhedron. """ return self._constraints @@ -96,15 +102,15 @@ class Polyhedron(Domain): def polyhedra(self): return self, - def disjoint(self): + def make_disjoint(self): """ - Return a set as disjoint. + Return a polyhedron as disjoint. """ return self def isuniverse(self): """ - Return true if a set is the Universe set. + Return true if a polyhedron is the Universe set. """ islbset = self._toislbasicset(self.equalities, self.inequalities, self.symbols) @@ -114,11 +120,14 @@ class Polyhedron(Domain): def aspolyhedron(self): """ - Return polyhedral hull of a set. + Return the polyhedral hull of a polyhedron. """ return self def __contains__(self, point): + """ + Report whether a polyhedron constains an integer point + """ if not isinstance(point, Point): raise TypeError('point must be a Point instance') if self.symbols != point.symbols: @@ -233,6 +242,9 @@ class Polyhedron(Domain): @classmethod def fromstring(cls, string): + """ + Create and return a Polyhedron from a string. + """ domain = Domain.fromstring(string) if not isinstance(domain, Polyhedron): raise ValueError('non-polyhedral expression: {!r}'.format(string)) @@ -261,7 +273,7 @@ class Polyhedron(Domain): @classmethod def fromsympy(cls, expr): """ - Convert a sympy object to an expression. + Convert a sympy object to a polyhedron. """ domain = Domain.fromsympy(expr) if not isinstance(domain, Polyhedron): @@ -270,7 +282,7 @@ class Polyhedron(Domain): def tosympy(self): """ - Return an expression as a sympy object. + Return a polyhedron as a sympy object. """ import sympy constraints = [] @@ -351,41 +363,41 @@ def _polymorphic(func): @_polymorphic def Lt(left, right): """ - Assert first set is less than the second set. + Returns a Polyhedron instance with a single constraint as left less than right. """ return Polyhedron([], [right - left - 1]) @_polymorphic def Le(left, right): """ - Assert first set is less than or equal to the second set. + Returns a Polyhedron instance with a single constraint as left less than or equal to right. """ return Polyhedron([], [right - left]) @_polymorphic def Eq(left, right): """ - Assert first set is equal to the second set. + Returns a Polyhedron instance with a single constraint as left equal to right. """ return Polyhedron([left - right], []) @_polymorphic def Ne(left, right): """ - Assert first set is not equal to the second set. + Returns a Polyhedron instance with a single constraint as left not equal to right. """ return ~Eq(left, right) @_polymorphic def Gt(left, right): """ - Assert first set is greater than the second set. + Returns a Polyhedron instance with a single constraint as left greater than right. """ return Polyhedron([], [left - right - 1]) @_polymorphic def Ge(left, right): """ - Assert first set is greater than or equal to the second set. + Returns a Polyhedron instance with a single constraint as left greater than or equal to right. """ return Polyhedron([], [left - right])