5

I want to know there is some algorithm that make a graph into planar graph ? I searched in Google I didn't find something that can help me enter image description here

HinoHara
  • 562
  • 2
  • 12
  • 24
  • 4
    What exactly do you mean by "making" it planar? – NPE Jan 02 '14 at 20:56
  • I updated my question look the picture – HinoHara Jan 02 '14 at 21:08
  • Google "graph visualization". – NPE Jan 02 '14 at 21:11
  • What you are looking for is a **plane embedding** of a planar graph. A graph is planar if you can draw it on a plane without any crossing of edges. There are alogirithm to check planarity. And once given the guarantee that it is planar, *there are linear time algorithms to find a such a drawing* (called a plane embedding). Please reword your question so that people can pour in answers. :) – Cyriac Antony May 28 '18 at 05:29

2 Answers2

3

There is an Eulers Theorem that applies to every planar graph.

Definiton: A Planar Graph is a graph that can be drawn on the plane so that the edges do not cross each other. Any planar graph partitions the plane into a number of disjoint regions called the faces of the graph.

Euler's Theorem: V-E+F=2 where:

  1. – V is the number of vertices,
  2. – E is the number of edges,
  3. – F is the number of faces

However, I can not provide a solution in java since its not clear the way you want to implement that. For instance, if you want to transform a graph into planar graph; visually, you might need a canvas and elements rearrangement, which will be kind of complicated to implement. In general think algorithmic wise, creating the solution first in pseudocode.

For example, since we have Euler's theorem that applies to every planar graph, you need to find a way to apply this theorem to your existing non planar graph and then test it.

Steps: (probably some of them will require coordinates)

  • Determine what are the vertices
  • Determine what are the edges
  • Determine what are the faces
  • Find a way to count the vertices
  • Find a way to count the edges
  • Find a way to count the faces
  • Rearrange all those in a canvas
  • Test the theorem, if it applies then your graph is planar, otherwise, rearrange again.
  • Note that, by the use of coordinates you can determine from the beginning if the graph can be drawn planar, however, when you draw it you should not allowed any line edges to cross.
nmargaritis
  • 819
  • 7
  • 21
  • thank you for the help but I don't know how I will rearrange the vertices , if you look the picture you can understand the problem ,and yes I must code the algorithm with java – HinoHara Jan 02 '14 at 21:37
  • 1
    You are welcome, If your program does as the picture shows then it works properly since both graphs are planar. The way they look like doesnt effect the rule, check this for the explanation: !(https://thecafe.me/image/1/Nicholas_uOpsc.jpg). – nmargaritis Jan 02 '14 at 22:28
  • Thanks for the picture i understand now you're explication . For the code i will update my question soon but the graph that my code made is not planar it was a misetake in the picture i m sorry – HinoHara Jan 03 '14 at 02:05
  • I don't think you can use Euler's formula to determine if a graph is planar, because the only way you can count the faces is by making a planar representation first. You would need to code up Kuratowski's theorem, see http://en.wikipedia.org/wiki/Kuratowski%27s_theorem to determine if the graph is planar (ie whether the problem is solvable at all). Naïve brute force is easy but incredibly inefficient. I doubt a high school assignment would require this sort of coding/algorithm knowledge anyway. As I said in my answer, its not clear to me what the actual problem is. – Peter Webb Jan 03 '14 at 08:11
  • You can use Euler's formula if you know how to determine what is what and prove that a graph could be drawn in a planar way before you actually draw it. Regarding the naive way of solving it, it should be random until you generate cases that you could store and arrive to a result directly after that. For example, if you find once how a grapgh with 4 vertices, 6 edges and 4 faces could be drawn planar all you have to do is store it. Because it will apply for all the graphs with similar characteristics. – nmargaritis Jan 06 '14 at 04:08
  • Implementation wise now, something useful is: You need to use coordinates to determine what is what. For example, the faces that you will need to count at are always a triangle between 3 vertices, otherwise its not a face(+1 for the general case of the outer at the end). – nmargaritis Jan 06 '14 at 04:09
3

This is too long for a comment. So excuse me providing an answer.

Your question is unclear to me. Whether a graph is planar is a function of the graph itself, not how it is drawn. "In graph theory, a planar graph is a graph that can be embedded in the plane, i.e., it can be drawn on the plane in such a way that its edges intersect only at their endpoints." from http://en.wikipedia.org/wiki/Planar_graph).

Do you need to work out/check if the graph is planar?

Do you need to draw it in planar form?

In the example you provide, why is the second drawing somehow more correct than the first drawing? Is it only because their are no intersecting edges?

Assuming you need to do this with other graphs, what rule is used to determine whether some representation is better than some other, how does your diagram generalise to other graphs?

Why are you doing this? What is the point? If its homework, what exactly is the problem statement? If its real-life, maybe an explanation of what you are really trying to do would help.

Peter Webb
  • 663
  • 4
  • 14
  • I'm so sorry I Know I don't explain so good (my english is so bad but I understand answers ),for the example I gave the first exemple was a mistake you can Look the update ! , I want to draw a simple graph (using adjacency matrix) and turn it into planar graph( edges intersect only at their endpoints) it's not a homework but a complete project of school , and again I'm so sorry for my bad explication and thank you so much for you're answer . – HinoHara Jan 03 '14 at 03:07
  • Please post the requirements of the project. (Hopefully translated into English). Parts of this are hard. Working out if a graph is planar is hard. (I don't think you can simply use Euler's formula, because by the time you have calculated the number of faces you must already have a planar representation). Making arbitrary graphs "look nice" when drawn is also hard. The general problem is way harder than I would expect a high school project to be. What exactly are they asking you to do? – Peter Webb Jan 03 '14 at 07:21
  • I m not in a high school this is what I must do : my program must draw planar graph in a way that its edges intersect only at their endpoints. By using a random adjacency matrix . Coding with java awt et swing . – HinoHara Jan 03 '14 at 13:46
  • So they give you an adjacency matrix which they guarantee represents a planar graph, and you have to provide a planar representation? http://cs.brown.edu/~rt/gdhandbook/chapters/straightline.pdf describes some algorithms to do this. Or simply Google "algorithm planar representation of graph". All of these algorithms are far more complicated than I would expect for a high school assignment. Isn't there some other project you can pick instead? – Peter Webb Jan 04 '14 at 02:54
  • Thank you so much for you're answers , yes the program transform the adjacency matrix into a planar graph (by using some algorithms) , and no I cannot change the project :x – HinoHara Jan 04 '14 at 16:23
  • @PeterWebb Checking whether a graph is planar is not hard. It can be done in polynomial time. I appreciate your effort to help the OP. – Cyriac Antony May 28 '18 at 05:34