class Polyhedron(Domain):
-
+ """
+ Polyhedron class allows users to build and inspect polyherons. Polyhedron inherits from Domain.
+ """
__slots__ = (
'_equalities',
'_inequalities',
)
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')
@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
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)
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:
@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))
@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):
def tosympy(self):
"""
- Return an expression as a sympy object.
+ Return a polyhedron as a sympy object.
"""
import sympy
constraints = []
@_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])