def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False): """ Construct polyhedron from V-representation data. INPUT: - ``vertices`` -- list of point. Each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``rays`` -- list of rays. Each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``lines`` -- list of lines. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl sage: Polyhedron_ppl._init_from_Vrepresentation(p, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = LCM_list([denominator(v_i) for v_i in v]) if d.is_one(): gs.insert(point(Linear_Expression(v, 0))) else: dv = [ d*v_i for v_i in v ] gs.insert(point(Linear_Expression(dv, 0), d)) if rays is None: rays = [] for r in rays: d = LCM_list([denominator(r_i) for r_i in r]) if d.is_one(): gs.insert(ray(Linear_Expression(r, 0))) else: dr = [ d*r_i for r_i in r ] gs.insert(ray(Linear_Expression(dr, 0))) if lines is None: lines = [] for l in lines: d = LCM_list([denominator(l_i) for l_i in l]) if d.is_one(): gs.insert(line(Linear_Expression(l, 0))) else: dl = [ d*l_i for l_i in l ] gs.insert(line(Linear_Expression(dl, 0))) if gs.empty(): self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty') else: self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)
def ppl_convert(P): r""" Convert a Sage polyhedron to a ppl polyhedron EXAMPLES:: sage: from surface_dynamics.misc.ppl_utils import ppl_convert # optional - pplpy sage: P = ppl_convert(Polyhedron(vertices=[(0,1,0),(1,0,1)], rays=[(0,0,1),[3,2,1]])) # optional - pplpy sage: P.minimized_generators() # optional - pplpy Generator_System {ray(0, 0, 1), point(0/1, 1/1, 0/1), point(1/1, 0/1, 1/1), ray(3, 2, 1)} """ if isinstance(P, ppl.C_Polyhedron): return P gs = ppl.Generator_System() for v in P.vertices_list(): gs.insert(ppl.point(sum(j * ppl.Variable(i) for i, j in enumerate(v)))) for r in P.rays_list(): gs.insert(ppl.ray(sum(j * ppl.Variable(i) for i, j in enumerate(r)))) for l in P.lines_list(): gs.insert(ppl.line(sum(j * ppl.Variable(i) for i, j in enumerate(l)))) return ppl.C_Polyhedron(gs)
def ppl_convert(P): r""" Convert a Sage polyhedron to a ppl polyhedron EXAMPLES:: sage: from surface_dynamics.misc.ppl_utils import ppl_convert # optional - pplpy sage: P = ppl_convert(Polyhedron(vertices=[(0,1,0),(1,0,1)], rays=[(0,0,1),[3,2,1]])) # optional - pplpy sage: P.minimized_generators() # optional - pplpy Generator_System {ray(0, 0, 1), point(0/1, 1/1, 0/1), point(1/1, 0/1, 1/1), ray(3, 2, 1)} """ if isinstance(P, ppl.C_Polyhedron): return P gs = ppl.Generator_System() for v in P.vertices_list(): gs.insert(ppl.point(sum(int(j) * ppl.Variable(i) for i,j in enumerate(v)))) for r in P.rays_list(): gs.insert(ppl.ray(sum(int(j) * ppl.Variable(i) for i,j in enumerate(r)))) for l in P.lines_list(): gs.insert(ppl.line(sum(int(j) * ppl.Variable(i) for i,j in enumerate(l)))) return ppl.C_Polyhedron(gs)
def fibration_generator(self, dim): """ Generate the lattice polytope fibrations. For the purposes of this function, a lattice polytope fiber is a sub-lattice polytope. Projecting the plane spanned by the subpolytope to a point yields another lattice polytope, the base of the fibration. INPUT: - ``dim`` -- integer. The dimension of the lattice polytope fiber. OUTPUT: A generator yielding the distinct lattice polytope fibers of given dimension. EXAMPLES:: sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL sage: p = LatticePolytope_PPL((-9,-6,-1,-1),(0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0)) sage: list( p.fibration_generator(2) ) [A 2-dimensional lattice polytope in ZZ^4 with 3 vertices] """ assert self.is_full_dimensional() # "points" are the potential vertices of the fiber. They are # in the $codim$-skeleton of the polytope, which is contained # in the points that saturate at least $dim$ equations. points = [ p for p in self._integral_points_saturating() if len(p[1])>=dim ] points = sorted(points, key=lambda x:len(x[1])) # iterate over point combinations subject to all points being on one facet. def point_combinations_iterator(n, i0=0, saturated=None): for i in range(i0, len(points)): p, ieqs = points[i] if saturated is None: saturated_ieqs = ieqs else: saturated_ieqs = saturated.intersection(ieqs) if len(saturated_ieqs)==0: continue if n == 1: yield [i] else: for c in point_combinations_iterator(n-1, i+1, saturated_ieqs): yield [i] + c point_lines = [ line(Linear_Expression(p[0].list(),0)) for p in points ] origin = point() fibers = set() gs = Generator_System() for indices in point_combinations_iterator(dim): gs.clear() gs.insert(origin) for i in indices: gs.insert(point_lines[i]) plane = C_Polyhedron(gs) if plane.affine_dimension() != dim: continue plane.intersection_assign(self) if (not self.is_full_dimensional()) and (plane.affine_dimension() != dim): continue try: fiber = LatticePolytope_PPL(plane) except TypeError: # not a lattice polytope continue fiber_vertices = tuple(sorted(fiber.vertices())) if fiber_vertices not in fibers: yield fiber fibers.update([fiber_vertices])
def _init_from_Vrepresentation(self, vertices, rays, lines, minimize=True, verbose=False): """ Construct polyhedron from V-representation data. INPUT: - ``vertices`` -- list of point. Each point can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``rays`` -- list of rays. Each ray can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``lines`` -- list of lines. Each line can be specified as any iterable container of :meth:`~sage.geometry.polyhedron.base.base_ring` elements. - ``verbose`` -- boolean (default: ``False``). Whether to print verbose output for debugging purposes. EXAMPLES:: sage: p = Polyhedron(backend='ppl') sage: from sage.geometry.polyhedron.backend_ppl import Polyhedron_ppl sage: Polyhedron_ppl._init_from_Vrepresentation(p, [], [], []) """ gs = Generator_System() if vertices is None: vertices = [] for v in vertices: d = LCM_list([denominator(v_i) for v_i in v]) if d.is_one(): gs.insert(point(Linear_Expression(v, 0))) else: dv = [d * v_i for v_i in v] gs.insert(point(Linear_Expression(dv, 0), d)) if rays is None: rays = [] for r in rays: d = LCM_list([denominator(r_i) for r_i in r]) if d.is_one(): gs.insert(ray(Linear_Expression(r, 0))) else: dr = [d * r_i for r_i in r] gs.insert(ray(Linear_Expression(dr, 0))) if lines is None: lines = [] for l in lines: d = LCM_list([denominator(l_i) for l_i in l]) if d.is_one(): gs.insert(line(Linear_Expression(l, 0))) else: dl = [d * l_i for l_i in l] gs.insert(line(Linear_Expression(dl, 0))) if gs.empty(): self._ppl_polyhedron = C_Polyhedron(self.ambient_dim(), 'empty') else: self._ppl_polyhedron = C_Polyhedron(gs) self._init_Vrepresentation_from_ppl(minimize) self._init_Hrepresentation_from_ppl(minimize)