Skip to content

Commit

Permalink
Trac #28960: Initialize CombinatorialPolyhedron from incidence matrix…
Browse files Browse the repository at this point in the history
… of cone or lattice polytope

#28743 and #28766 implemented the incidence matrix for lattice polytopes
and cones.

We use the incidence matrix to
- accept a cone as input of `CombinatorialPolyhedron`,
- process a lattice polytope as input more easily.

In both cases the `CombinatorialPolyhedron` can be obtained without
previously calculating the face lattice (avoiding the method `facets`).

URL: https://trac.sagemath.org/28960
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Laith Rastanawi
  • Loading branch information
Release Manager committed Apr 8, 2020
2 parents 67d097d + d513adc commit 2e00b63
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ from sage.graphs.digraph import DiGraph
from sage.combinat.posets.lattices import FiniteLatticePoset
from sage.geometry.polyhedron.base import Polyhedron_base
from sage.geometry.lattice_polytope import LatticePolytopeClass
from sage.geometry.cone import ConvexRationalPolyhedralCone
from sage.structure.element import Matrix
from sage.misc.misc import is_iterator
from .conversions \
Expand All @@ -114,6 +115,7 @@ cdef class CombinatorialPolyhedron(SageObject):
- ``data`` -- an instance of
* :class:`~sage.geometry.polyhedron.parent.Polyhedron_base`
* or a :class:`~sage.geometry.lattice_polytope.LatticePolytopeClass`
* or a :class:`~sage.geometry.cone.ConvexRationalPolyhedralCone`
* or an ``incidence_matrix`` as in
:meth:`~sage.geometry.polyhedron.base.Polyhedron_base.incidence_matrix`
In this case you should also specify the ``Vrep`` and ``facets`` arguments
Expand Down Expand Up @@ -157,6 +159,12 @@ cdef class CombinatorialPolyhedron(SageObject):
sage: CombinatorialPolyhedron(L)
A 3-dimensional combinatorial polyhedron with 8 facets
a cone::
sage: M = Cone([(1,0), (0,1)])
sage: CombinatorialPolyhedron(M)
A 2-dimensional combinatorial polyhedron with 2 facets
an incidence matrix::
sage: P = Polyhedron(rays=[[0,1]])
Expand Down Expand Up @@ -358,10 +366,22 @@ cdef class CombinatorialPolyhedron(SageObject):
self._bounded = True
Vrep = data.vertices()
self._n_Vrepresentation = len(Vrep)
facets = data.facets()
facets = tuple(data.facet_normals())
self._n_Hrepresentation = len(facets)
data = tuple(tuple(vert for vert in facet.vertices())
for facet in facets)
data = data.incidence_matrix()
elif isinstance(data, ConvexRationalPolyhedralCone):
# input is ``Cone``
self._bounded = False
Vrep = tuple(data.rays()) + (data.lattice().zero(),)
self._n_Vrepresentation = len(Vrep)
facets = tuple(data.facet_normals())
self._n_Hrepresentation = len(facets)
far_face = tuple(i for i in range(len(Vrep) - 1))
self._dimension = data.dim()
from sage.matrix.all import matrix
from sage.rings.all import ZZ
data = matrix(ZZ, data.incidence_matrix().rows()
+ [[ZZ.one() for _ in range(len(facets))]])
else:
# Input is different from ``Polyhedron`` and ``LatticePolytope``.
if not unbounded:
Expand Down Expand Up @@ -607,6 +627,17 @@ cdef class CombinatorialPolyhedron(SageObject):
A ray in the direction (1, 0, 0),
A vertex at (0, 0, 0),
A ray in the direction (0, 1, 0))
sage: points = [(1,0,0), (0,1,0), (0,0,1),
....: (-1,0,0), (0,-1,0), (0,0,-1)]
sage: L = LatticePolytope(points)
sage: C = CombinatorialPolyhedron(L)
sage: C.Vrepresentation()
(M(1, 0, 0), M(0, 1, 0), M(0, 0, 1), M(-1, 0, 0), M(0, -1, 0), M(0, 0, -1))
sage: M = Cone([(1,0), (0,1)])
sage: CombinatorialPolyhedron(M).Vrepresentation()
(N(1, 0), N(0, 1), N(0, 0))
"""
if self.Vrep() is not None:
return self.Vrep()
Expand All @@ -629,6 +660,24 @@ cdef class CombinatorialPolyhedron(SageObject):
An inequality (0, 1, 0) x - 1 >= 0,
An inequality (0, 1, 1) x - 3 >= 0,
An inequality (0, 0, 1) x - 1 >= 0)
sage: points = [(1,0,0), (0,1,0), (0,0,1),
....: (-1,0,0), (0,-1,0), (0,0,-1)]
sage: L = LatticePolytope(points)
sage: C = CombinatorialPolyhedron(L)
sage: C.Hrepresentation()
(N(1, -1, -1),
N(1, 1, -1),
N(1, 1, 1),
N(1, -1, 1),
N(-1, -1, 1),
N(-1, -1, -1),
N(-1, 1, -1),
N(-1, 1, 1))
sage: M = Cone([(1,0), (0,1)])
sage: CombinatorialPolyhedron(M).Hrepresentation()
(M(0, 1), M(1, 0))
"""
if self.facet_names() is not None:
return self.equalities() + self.facet_names()
Expand Down

0 comments on commit 2e00b63

Please sign in to comment.