16

The graph

Graph[{1 <-> 2, 1 <-> 3, 1 <-> 4, 1 <-> 5, 2 <-> 6, 3 <-> 7, 4 <-> 8, 5 <-> 9, 6 <-> 10, 
       7 <-> 11, 8 <-> 12, 9 <-> 13, 10 <-> 14, 11 <-> 14, 12 <-> 14, 13 <-> 14, 2 <-> 3, 
       3 <-> 4, 4 <-> 5, 10 <-> 11, 11 <-> 12, 12 <-> 13, 6 <-> 8, 7 <-> 9}]

which looks like

nonplanar graph

is nonplanar, according to PlanarGraphQ

My question is, does Mathematica have commands which will help me find Kuratowski subdivisions in my graph, i.e. witnesses to its non-planarity ?

I would like to automate this using Mathematica, rather than do it by hand, because in future my graphs might be much larger.

I believe that the Open Graph Drawing Framework (OGDF), available on Github, can do this, but I would like to do it within Mathematica, if possible.

Other evidence of nonplanarity would also be useful, i.e. any sufficient condition for nonplanarity, that I can demonstrate using Mathematica.

Thank you.

EDIT:

I have already shown that there are no subgraphs isomorphic to $K_5$ or $K_{3,3}$, using Mathematica like this

subgraphsoforderfive =  Map[Subgraph[nonplanarminimalfourbyfournetwork, #] &, 
                           Subsets[Range[14], {5}]];
Map[IsomorphicGraphQ[CompleteGraph[5], #] &, subgraphsoforderfive]

and this

subgraphsofordersix = Map[Subgraph[nonplanarminimalfourbyfournetwork, #] &, 
                          Subsets[Range[14], {6}]];
Select[subgraphsofordersix, IsomorphicGraphQ[CompleteGraph[{3, 3}], #] &]

where nonplanarminimalfourbyfournetwork is the graph above.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Simon
  • 1,415
  • 8
  • 13
  • 2
    According to what I've learned from Wikipedia, several algorithms exist which will solve this problem in linear time. Many seem to use depth-first traversals of spanning trees for the graph. I would imagine that PlanarGraphQ uses state of the art algorithms in such a way that it could return the Kuratowski subdivisions in a nonplanar graph with ease. My question here is whether it is possible for users to access that part of PlanarGraphQ. If not, then I look forward to learning about some of those algorithms, and coding one myself in Mathematica, when I have more time ! – Simon Oct 10 '15 at 19:40
  • If you need faster subgraph isomorphism testing, IGraph/M has that. – Szabolcs Oct 10 '15 at 19:56
  • Thank you very much @Szabolcs. In fact for the time being the subgraph isomorphism testing is quite fast enough. The bigger problem is that I don't only want to know whether my graph has subgraphs isomorphic to $K_{3,3}$ or $K_5$ (it doesn't) but more generally, since it must have subgraphs isomorphic to subdivisions of $K_{3,3}$ or $K_5$, where are they in the big graph ? – Simon Oct 10 '15 at 20:02
  • https://en.wikipedia.org/wiki/Kuratowski%27s_theorem – Simon Oct 10 '15 at 20:04
  • Yep, I got that. Just mentioning since you showed a test using Subsets and Subgraph. – Szabolcs Oct 10 '15 at 20:14
  • Great ! Just making sure we are on the same page. That link is really interesting, thank you. I don't see generation of kuratowski subdivisions in the course of planarity checking as an available function, but the author does mention that he omits to list several functions, so maybe its in there. Does one need to be a hardcore C programmer to install and work with iGraph and iGraphM ? – Simon Oct 10 '15 at 20:16
  • igraph does not have planarity testing functionality, unfortunately. IGraph/M is a (partial) Mathematica interface for igraph, so it doesn't have this either. I just pointed out the subgraph isomorphism functions that it makes available. Installation should be straightforward: download, extract, place in Mathematica's application folder, and use. No compilation of knowledge of C is necessary. There should be a much improved IGraph/M release in 1-2 weeks which will include more isomorphism functions for coloured graphs and multigraphs. Disclosure: I'm the IGraph/M author. – Szabolcs Oct 10 '15 at 20:25
  • Great ! Aha - you are a person of more than one alias ! I am definitely going to have a go with your package. Looking forward to it ! I have always wanted to try linking C or compiling to make super fast code... Thank you ! – Simon Oct 10 '15 at 20:28
  • @Szabolcs, I downloaded the Igraph/M package but unfortunately was unable to use it, because I have version 9 of Mathematica, not version 10. Meanwhile someone on Mathematics SE has shown me a subdivision of $K_5$, found by hand. – Simon Oct 13 '15 at 23:34
  • 1
    The LTemplate package includes an example (Documentation/Examples) that exposes the Kuratowski subdivision finding functionality of the Boost Graph Library. However, the results it produces are often not very practical. – Szabolcs Nov 10 '17 at 12:14
  • Hi Szabolcs. I am still interested. Unfortunately your nice port of IGraph won't run on my machine, which uses ARM chips instead of Intel. – Simon Jun 14 '18 at 12:18
  • What kind of computer and operating system are you using? Does Mathematica run on it? I can produce a binary for the Raspberry Pi, but I guess that is not what you have (as it's quite slow). I'm curious about what other ARM machines Mathematica runs on. – Szabolcs Jun 14 '18 at 12:20
  • Bingo ! I am indeed running Mathematica on a Raspberry Pi ! It seems to be only about 3 times slower than my laptop used to be, on the particular tasks I'm giving it. Parallelising has helped a lot too since the four cores seem to afford a greater time saving factor than the (I think) 2 cores of my laptop used to. Plus of course my legendary skillz as a l33t haxor help a lot ;) If you were able to produce a binary for the Pi I'd be very interested to try it ! – Simon Jun 14 '18 at 12:33
  • Actually, I used to compile it for the RPi. I removed support recently because I believed that no one was using it. I'll try to produce an RPi-compatible paclet with the planar graph stuff during the weekend. – Szabolcs Jun 14 '18 at 12:34
  • Wow ! Thank you so much !!!!! – Simon Jun 14 '18 at 12:36

2 Answers2

7

Here is a (roughly?) quadratic algorithm (in the number of edges) making use of PlanarGraphQ as a black box. The strategy is to delete as many edges as possible while keeping the graph nonplanar. Each iteration of the While loop does the following: it removes edges starting from the last one until the graph becomes planar, then puts the last edge removed at the start of the edge list. This edge cannot be removed without making the graph planar. Doing the loop collects such unremovable edges until there is no other edge left to look at. Note that PlanarGraphQ is called Length[EdgeList[g]] times. The Unsubdivide function simply contracts vertices of degree 2 to get either $K_5$ or $K_{3,3}$ as an output. It's not entirely clear what information you want to keep at the end (e.g. the list of vertices in an edge of the contracted graph) so I've not kept anything (other than vertex names).

ClearAll[KuratowskiSubgraph, UnSubdivide];
Module[{edges, nfound, pos},
  KuratowskiSubgraph[g_Graph] := (
     edges = DeleteDuplicatesBy[EdgeList[g], Sort];
     nfound = 0;
     While[nfound < Length[edges],
      pos = SelectFirst[Range[Length[edges] - 1, nfound, -1],
        PlanarGraphQ[Graph[edges[[;; #]]]] &];
      edges = Join[{edges[[pos + 1]]}, edges[[;; pos]]];
      nfound += 1];
     Graph[edges]);
  ];
UnSubdivide[g_Graph] :=
  Graph[Fold[#1 /. {el1___, UndirectedEdge[a___, #2, b___],
        el2___, UndirectedEdge[c___, #2, d___], el3___} :>
       {el1, el2, el3, UndirectedEdge[a, b, c, d]} &,
    EdgeList[g],
    Select[VertexList[g], VertexDegree[g, #] == 2 &]]];

On the example you gave,

g = Graph[{1 <-> 2, 1 <-> 3, 1 <-> 4, 1 <-> 5, 2 <-> 6, 3 <-> 7, 
   4 <-> 8, 5 <-> 9, 6 <-> 10, 7 <-> 11, 8 <-> 12, 9 <-> 13, 
   10 <-> 14, 11 <-> 14, 12 <-> 14, 13 <-> 14, 2 <-> 3, 3 <-> 4, 
   4 <-> 5, 10 <-> 11, 11 <-> 12, 12 <-> 13, 6 <-> 8, 7 <-> 9}]
g2 = KuratowskiSubgraph[g]
g3 = UnSubdivide[g2]

gives $K_{3,3}$ with vertices 1,3,6 connected to vertices 2,4,14. Looking at InputForm[g2] we can see what edges of the original graph connect 1 to 14 for instance: 1-5-9-13-14.

Bruno Le Floch
  • 1,959
  • 10
  • 23
6

IGraph/M now has functionality to work with planar graphs. Raspberry Pi support is still missing in release 0.3.100, but it will be re-added soon.

g = Graph[{1 <-> 2, 1 <-> 3, 1 <-> 4, 1 <-> 5, 2 <-> 6, 3 <-> 7, 
   4 <-> 8, 5 <-> 9, 6 <-> 10, 7 <-> 11, 8 <-> 12, 9 <-> 13, 
   10 <-> 14, 11 <-> 14, 12 <-> 14, 13 <-> 14, 2 <-> 3, 3 <-> 4, 
   4 <-> 5, 10 <-> 11, 11 <-> 12, 12 <-> 13, 6 <-> 8, 7 <-> 9}]

enter image description here

Check that the graph is not planar:

IGPlanarQ[g]
(* False *)

We can find a Kuratowski subgraph as a set of edges:

kuratowski = IGKuratowskiEdges[g]
(* {11 \[UndirectedEdge] 12, 10 \[UndirectedEdge] 11, 
 8 \[UndirectedEdge] 12, 7 \[UndirectedEdge] 9, 
 7 \[UndirectedEdge] 11, 6 \[UndirectedEdge] 10, 
 5 \[UndirectedEdge] 9, 4 \[UndirectedEdge] 5, 4 \[UndirectedEdge] 8, 
 3 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 7, 2 \[UndirectedEdge] 6, 
 1 \[UndirectedEdge] 5, 1 \[UndirectedEdge] 3, 1 \[UndirectedEdge] 2} *)

If the graph were planar, the result would have been {}.

Highlight it in the original graph:

HighlightGraph[g, Graph[kuratowski]]

enter image description here

Is this homeomorphic to $K_{3,3}$ or to $K_5$? Let's reduce it:

IGSmoothen[Graph[kuratowski]]

It has 6 vertices, so it must be $K_{3,3}$. Let's make that a bit more obvious using an appropriate visualization:

IGLayoutBipartite[%]

enter image description here

Finally, let us also do an explicit test using IGHomeomorphicQ.

IGHomeomorphicQ[Graph[kuratowski], CompleteGraph[{3, 3}]]
(* True *)

As a side note, IGraph/M can also work with combinatorial embeddings of non-planar graphs.

Generate an embedding from the particular drawing of this graph:

emb = IGCoordinatesToEmbedding[g]
(* <|1 -> {4, 5, 2, 3}, 2 -> {3, 1, 6}, 3 -> {7, 4, 1, 2}, 
 4 -> {5, 1, 3, 8}, 5 -> {9, 1, 4}, 6 -> {10, 8, 2}, 7 -> {9, 3, 11}, 
 8 -> {12, 4, 6}, 9 -> {5, 7, 13}, 10 -> {14, 11, 6}, 
 11 -> {14, 12, 7, 10}, 12 -> {13, 8, 11, 14}, 13 -> {9, 12, 14}, 
 14 -> {13, 12, 11, 10}|> *)

The embedding is not planar:

IGPlanarQ[emb]
(* False *)

We can find the faces of this particular embedding:

IGFaces[emb]
(* {{1, 4, 5}, {1, 5, 9, 13, 14, 10, 6, 2}, {1, 2, 3}, {1, 3, 
  4}, {2, 6, 8, 4, 3, 7, 9, 5, 4, 8, 12, 13, 9, 7, 11, 12, 8, 6, 10, 
  11, 7, 3}, {10, 14, 11}, {11, 14, 12}, {12, 14, 13}} *)

It has 8 faces, which means that it can be drawn on a surface of genus 2 (according to Euler's formula):

genus[emb_?IGEmbeddingQ] := (2 + Total[Length /@ emb]/2 - Length[emb] - Length@IGFaces[emb])/2

genus[emb]
(* 2 *)

Of course, this doesn't prove that there isn't an embedding on a surface of smaller genus.

Also, we could have figured this out from looking at a 3D drawing of the graph:

Graph3D[g, VertexLabels -> Automatic]

enter image description here

From this 3D visualization it's clear that removing 3 <-> 4 and 11 <-> 12 would make a drawing on a spherical surface possible (which is the same as planarity).

IGPlanarQ@EdgeDelete[g, {3 <-> 4, 11 <-> 12}]
(* True *)
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263