diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index 5c9f183c57f..1109bc5160e 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -262,6 +262,7 @@ :meth:`~GenericGraph.set_embedding` | Set a combinatorial embedding dictionary to ``_embedding`` attribute. :meth:`~GenericGraph.get_embedding` | Return the attribute _embedding if it exists. :meth:`~GenericGraph.faces` | Return the faces of an embedded graph. + :meth:`~GenericGraph.planar_dual` | Return the planar dual of an embedded graph. :meth:`~GenericGraph.get_pos` | Return the position dictionary :meth:`~GenericGraph.set_pos` | Set the position dictionary. :meth:`~GenericGraph.set_planar_positions` | Compute a planar layout for self using Schnyder's algorithm @@ -4119,6 +4120,8 @@ def is_planar(self, on_embedding=None, kuratowski=False, set_embedding=False, se .. SEEALSO:: - :meth:`~Graph.is_apex` + - :meth:`planar_dual` + - :meth:`faces` INPUT: @@ -4879,6 +4882,7 @@ def faces(self, embedding = None): * :meth:`set_embedding` * :meth:`get_embedding` * :meth:`is_planar` + * :meth:`planar_dual` EXAMPLES:: @@ -4970,6 +4974,76 @@ def num_faces(self,embedding=None): return len(self.faces(embedding)) + def planar_dual(self, embedding=None): + """ + Return the planar dual of an embedded graph. + + A combinatorial embedding of a graph is a clockwise ordering of the + neighbors of each vertex. From this information one can obtain + the dual of a plane graph, which is what the method returns. The + vertices of the dual graph correspond to faces of the primal graph. + + INPUT: + + - ``embedding`` - a combinatorial embedding dictionary. Format: + ``{v1:[v2, v3], v2:[v1], v3:[v1]}`` (clockwise ordering of neighbors at + each vertex). If set to ``None`` (default) the method will use the + embedding stored as ``self._embedding``. If none is stored, the method + will compute the set of faces from the embedding returned by + :meth:`is_planar` (if the graph is, of course, planar). + + EXAMPLES:: + + sage: C = graphs.CubeGraph(3) + sage: C.planar_dual() + Graph on 6 vertices + sage: graphs.IcosahedralGraph().planar_dual().is_isomorphic(graphs.DodecahedralGraph()) + True + + The planar dual of the planar dual is isomorphic to the graph itself:: + + sage: g = graphs.BuckyBall() + sage: g.planar_dual().planar_dual().is_isomorphic(g) + True + + .. SEEALSO:: + + * :meth:`faces` + * :meth:`set_embedding` + * :meth:`get_embedding` + * :meth:`is_planar` + + TESTS:: + + sage: G = graphs.CompleteMultipartiteGraph([3, 3]) + sage: G.planar_dual() + Traceback (most recent call last): + ... + ValueError: No embedding is provided and the graph is not planar. + sage: G = Graph([[1, 2, 3, 4], [[1, 2], [2, 3], [3, 1], [3, 2], [1, 4], [2, 4], [3, 4]]], multiedges=True) + sage: G.planar_dual() + Traceback (most recent call last): + ... + ValueError: This method is not known to work on graphs with multiedges. Perhaps this method can be updated to handle them, but in the meantime if you want to use it please disallow multiedges using allow_multiple_edges(). + sage: G = graphs.CompleteGraph(3) + sage: G.planar_dual() + Traceback (most recent call last): + ... + NotImplementedError: the graph must be 3-vertex-connected. + + .. TODO:: + + Implement the method for graphs that are not 3-vertex-connected + (or at least have a faster 3-vertex-connectivity test). + + """ + self._scream_if_not_simple() + + if self.vertex_connectivity() < 3: + raise NotImplementedError("the graph must be 3-vertex-connected.") + + from sage.graphs.graph import Graph + return Graph([[tuple(_) for _ in self.faces()], lambda f, g: not set([tuple(reversed(e)) for e in f]).isdisjoint(g)], loops=False) ### Connectivity @@ -18930,7 +19004,7 @@ def plot(self, **options): edge for each label l. Labels equal to None are not printed (to set edge labels, see set_edge_label). - - ``edge_labels_background`` - The color of the edge labels + - ``edge_labels_background`` - The color of the edge labels background. The default is "white". To achieve a transparent background use "transparent".