4

I am looking for an algorithm for the following task:

We are playing the following game : There is a planar graph drawn in front of us, e.g. enter image description here

We can see the edges have intersected each other at 3 places. We are going to move the vertices without deleting any edge, so that the edges don't intersect each other any more. e.g. for the given graph we can do it in the following two steps, by first moving the vertex E, enter image description here

and then by moving the vertex B

enter image description here

This was an extremely easy example. The planar graph given can be much more complicated.

enter image description here

which has to be converted to

enter image description here

Anyone can do it by trial and error, but what is the general algorithm one needs to follow given any planar graph structure.

Any kind of hint or solution is welcome. Thanks in advance! :)

Community
  • 1
  • 1
QED
  • 143
  • 5
  • possible duplicate of [Edge crossing reduction in graph](http://stackoverflow.com/questions/13963073/edge-crossing-reduction-in-graph) – Steve Benett Aug 26 '14 at 18:10
  • @SteveBenett I don't believe this is a duplicate. In this question, there's a cost to moving nodes, so finding a way to reduce edge crossings in general isn't necessarily the right approach to solving this problem. – templatetypedef Aug 26 '14 at 18:12
  • @templatetypedef Agreed that there's no step for step solution. – Steve Benett Aug 26 '14 at 18:17
  • Questions about algorithms are more appropriate on http://programmers.stackexchange.com/ On StackOverflow we expect you to show the code that you are having trouble with, or ask about specific details of a programming language or tool. – Dale Wilson Aug 26 '14 at 18:46
  • @DaleWilson Then I am reposting there. – QED Aug 26 '14 at 18:47
  • 1
    Agreed, this should have been posted on Programmers. Unfortunately it wasn't, and it's now been answered here and the answer accepted. Cross posting in that situation is discouraged – david.pfx Aug 27 '14 at 11:48
  • 1
    By the way, I've played this game. Crazy Nodes, or something like that? – david.pfx Aug 27 '14 at 11:52

2 Answers2

5

If the complexity of the solution is of no concern, then there exists a linear-time algorithm to find coordinates for each vertex such that the drawing is straight-line planar. Unfortunately, it's rather involved; the first step is to find a combinatorial planar embedding using, e.g., Boyer--Myrvold (On the Cutting Edge: Simplified O(n) Planarity by Edge Addition, 2004), then converting this combinatorial embedding to a geometric one via Chrobak--Payne (A Linear-time Algorithm for Drawing a Planar Graph on the Grid, 1995). These algorithms are implemented in the Boost Graph Library.

A simpler algorithm that will work most of the time on well connected graphs like your samples is spectral layout. Compute the second and third eigenvectors of the Laplacian matrix and use them as X and Y coordinates.

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
  • 1
    I think that those algorithms will find a way of making the graph planar, but they don't necessarily find layouts minimizing the number of nodes that have to be moved. – templatetypedef Aug 26 '14 at 19:46
  • is there any other elegant method, that is more intuitive? – QED Aug 27 '14 at 05:03
  • @David_Eisenstat can you explain the spectral layout approach, is it also possible also to check weather the graph is planar(with spectral layout)? if Yes, how efficiently is that algorithm? – user1387682 Jul 05 '16 at 18:40
1

If you are interested in the lowest cost then the algorithm descibed in this thesis Planarity Testing By Path Addition will find the permutations possible to generate all possible planar embedding (in O(|Edges|) time and memory to geneate a data structure containing all the permutations of cyclic edge orderings to give a planar embedding and O(|Edges|) time and memory to generate an embedding for each individual permutation). You could then iterate through those permutations and find the lowest cost to reach.

If the graphs are always maximal planar then this is overkill (as there will only be one possible cyclic edge ordering) but you may still need to consider many possible outer faces.

[As an aside: the first graph can be re-arranged into a planar embedding in a single move - moving (C) to the mid-point between (A) and (E)]

MT0
  • 143,790
  • 11
  • 59
  • 117