Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
expose algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Apr 7, 2022
1 parent 89f9278 commit dd05cc2
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 53 deletions.
36 changes: 29 additions & 7 deletions src/sage/geometry/polyhedron/base3.py
Expand Up @@ -781,8 +781,8 @@ def facets(self):
return ()
return self.faces(self.dimension()-1)

@cached_method(do_pickle=True)
def f_vector(self, num_threads=None, parallelization_depth=None):
@cached_method(do_pickle=True, key=lambda self, x, y, z: None)
def f_vector(self, num_threads=None, parallelization_depth=None, algorithm=None):
r"""
Return the f-vector.
Expand All @@ -794,6 +794,12 @@ def f_vector(self, num_threads=None, parallelization_depth=None):
- ``parallelization_depth`` -- integer (optional); specify
how deep in the lattice the parallelization is done
- ``algorithm`` -- string (optional);
specify whether the face iterator starts with facets or vertices:
* ``'primal'`` -- start with the facets
* ``'dual'`` -- start with the vertices
* ``None`` -- choose automatically
OUTPUT:
Return a vector whose `i`-th entry is the number of
Expand Down Expand Up @@ -849,7 +855,7 @@ def f_vector(self, num_threads=None, parallelization_depth=None):
sage: Q.f_vector.is_in_cache()
True
"""
return self.combinatorial_polyhedron().f_vector(num_threads, parallelization_depth)
return self.combinatorial_polyhedron().f_vector(num_threads, parallelization_depth, algorithm=algorithm)

def bounded_edges(self):
"""
Expand Down Expand Up @@ -879,10 +885,18 @@ def bounded_edges(self):
yield (obj[i], obj[j])

@cached_method
def vertex_adjacency_matrix(self):
def vertex_adjacency_matrix(self, algorithm=None):
"""
Return the binary matrix of vertex adjacencies.
INPUT:
- ``algorithm`` -- string (optional);
specify whether the face iterator starts with facets or vertices:
* ``'primal'`` -- start with the facets
* ``'dual'`` -- start with the vertices
* ``None`` -- choose automatically
EXAMPLES::
sage: polytopes.simplex(4).vertex_adjacency_matrix()
Expand Down Expand Up @@ -1003,15 +1017,23 @@ def vertex_adjacency_matrix(self):
sage: P.adjacency_matrix().is_immutable()
True
"""
return self.combinatorial_polyhedron().vertex_adjacency_matrix()
return self.combinatorial_polyhedron().vertex_adjacency_matrix(algorithm=algorithm)

adjacency_matrix = vertex_adjacency_matrix

@cached_method
def facet_adjacency_matrix(self):
def facet_adjacency_matrix(self, algorithm=None):
"""
Return the adjacency matrix for the facets.
INPUT:
- ``algorithm`` -- string (optional);
specify whether the face iterator starts with facets or vertices:
* ``'primal'`` -- start with the facets
* ``'dual'`` -- start with the vertices
* ``None`` -- choose automatically
EXAMPLES::
sage: s4 = polytopes.simplex(4, project=True)
Expand Down Expand Up @@ -1053,7 +1075,7 @@ def facet_adjacency_matrix(self):
[1 0 1]
[1 1 0]
"""
return self.combinatorial_polyhedron().facet_adjacency_matrix()
return self.combinatorial_polyhedron().facet_adjacency_matrix(algorithm=algorithm)

def a_maximal_chain(self):
r"""
Expand Down
16 changes: 14 additions & 2 deletions src/sage/geometry/polyhedron/base4.py
Expand Up @@ -139,11 +139,23 @@ def vertex_facet_graph(self, labels=True):
"""
return self.combinatorial_polyhedron().vertex_facet_graph(names=labels)

def vertex_graph(self):
def vertex_graph(self, **kwds):
"""
Return a graph in which the vertices correspond to vertices
of the polyhedron, and edges to edges.
INPUT:
- ``names`` -- boolean (default: ``True``); if ``False``,
then the nodes of the graph are labeld by the
indices of the Vrepresentation
- ``algorithm`` -- string (optional);
specify whether the face iterator starts with facets or vertices:
* ``'primal'`` -- start with the facets
* ``'dual'`` -- start with the vertices
* ``None`` -- choose automatically
..NOTE::
The graph of a polyhedron with lines has no vertices,
Expand Down Expand Up @@ -184,7 +196,7 @@ def vertex_graph(self):
sage: polytopes.simplex(1).graph().edges()
[(A vertex at (0, 1), A vertex at (1, 0), None)]
"""
return self.combinatorial_polyhedron().vertex_graph()
return self.combinatorial_polyhedron().vertex_graph(**kwds)

graph = vertex_graph

Expand Down
Expand Up @@ -51,13 +51,14 @@ cdef class CombinatorialPolyhedron(SageObject):
cdef ListOfFaces bitrep_facets(self)
cdef ListOfFaces bitrep_Vrep(self)
cdef tuple far_face_tuple(self)
cdef int _algorithm_to_dual(self, algorithm) except -2

# Methods to obtain a different combinatorial polyhedron.
cpdef CombinatorialPolyhedron dual(self)
cpdef CombinatorialPolyhedron pyramid(self, new_vertex=*, new_facet=*)

cdef FaceIterator _face_iter(self, bint dual, int dimension)
cdef int _compute_f_vector(self, size_t num_threads, size_t parallelization_depth) except -1
cdef int _compute_f_vector(self, size_t num_threads, size_t parallelization_depth, int dual) except -1

cdef inline int _compute_edges(self, dual) except -1:
return self._compute_edges_or_ridges(dual, True)
Expand Down

0 comments on commit dd05cc2

Please sign in to comment.