Skip to content

Commit

Permalink
Trac #6236: find the dual graph of a planar graph
Browse files Browse the repository at this point in the history
Working code is here: http://sagenb.org/home/pub/417/

The worksheet also includes code which lists the faces of a planar
embedding of a graph.

URL: https://trac.sagemath.org/6236
Reported by: jason
Ticket author(s): Moritz Firsching
Reviewer(s): David Coudert
  • Loading branch information
Release Manager authored and vbraun committed Aug 21, 2017
2 parents 5057c11 + 922b58b commit 035aa9f
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -4879,6 +4882,7 @@ def faces(self, embedding = None):
* :meth:`set_embedding`
* :meth:`get_embedding`
* :meth:`is_planar`
* :meth:`planar_dual`

EXAMPLES::

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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".

Expand Down

0 comments on commit 035aa9f

Please sign in to comment.