From f03bfa8b26b45b0ba2b47c6eadafa7787200a9c9 Mon Sep 17 00:00:00 2001 From: Vivien Maisonneuve Date: Tue, 19 Aug 2014 16:00:56 +0200 Subject: [PATCH 1/1] Add method Polyhedron.convex_union() --- doc/reference.rst | 6 ++++++ linpy/polyhedra.py | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/doc/reference.rst b/doc/reference.rst index 18e69c0..83ee9d3 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -2,6 +2,7 @@ Module Reference ================ + Symbols ------- @@ -227,6 +228,7 @@ They are implemented by the :class:`Rational` class, that inherits from both :cl See the documentation of :class:`fractions.Fraction` for more information and examples. + Polyhedra --------- @@ -278,6 +280,10 @@ This space can be unbounded. The tuple of constraints, i.e., equalities and inequalities. This is semantically equivalent to: ``equalities + inequalities``. + .. method:: convex_union(polyhedron[, ...]) + + Return the convex union of two or more polyhedra. + .. method:: widen(polyhedron) Compute the *standard widening* of two polyhedra, Ã  la Halbwachs. diff --git a/linpy/polyhedra.py b/linpy/polyhedra.py index e5e2523..50af053 100644 --- a/linpy/polyhedra.py +++ b/linpy/polyhedra.py @@ -144,6 +144,15 @@ class Polyhedron(Domain): def aspolyhedron(self): return self + def convex_union(self, *others): + """ + Return the convex union of two or more polyhedra. + """ + for other in others: + if not isinstance(other, Polyhedron): + raise TypeError('arguments must be Polyhedron instances') + return Polyhedron(self.union(*others)) + def __contains__(self, point): if not isinstance(point, Point): raise TypeError('point must be a Point instance') -- 2.20.1