0

I am trying to build some algorithm for planar graphs generation. I have read a lot of materials about this subject and here are some results:

public Graph graph;
...

public Level(int numPoints, int numEdges, int levelID, int timeLim) 
{
        this.graph = new Graph(numPoints, numEdges);
    this.graph.GeneratePlanarGraph();
        ...
}

Here I wrote some functions that build planar graph...

public void GeneratePlanarGraph() {
    if(this.edges_num < this.vertices_num) {
        System.out.println("erroe: number of edges mast be\n "+
                    "bigger than number of vertices\n");
        return;
    }
        
    int edges = 0;
        
    // add vertices to graph
    for(int i = 0 ; i < this.vertices_num ; i++) 
            this.AddVertex(i+1);
        
    // connect all vertices to circular list 
    // ( from each vertex 2 connections )       
    for(int i = 1 ; i <= this.vertices_num ; i++) {
        if(i < this.vertices_num) this.AddEdge(i, i+1);
        else this.AddEdge(i, 1);
        edges++;
    }
        
    //connect other edges if its exist
    int step = 2;
    while(edges < this.edges_num) {
        for(int i = 1 ; i <= this.vertices_num ; i++) {
            if(i + step <= this.vertices_num) {
                this.AddEdge(i, i + step);
                edges++;
                if(edges == this.edges_num) break;
            }
            else {
                this.AddEdge(i, (i + step) - this.vertices_num);
                edges++;
                break;
            }
        }
        step++;
    }
}

When I start my program it generates a number of planar graphs in this way:

for(int i = 0 ; i < 100 ; i++)
{
    levels[i] = new Level(numPoints, numEdges,  levelID,  timeLim);
}

All these codes work but I have found that while testing graph (level) 24, 36, ..., are not planar.

I know about Euler's formula so I tried to generate my vertex/edges by Euler's formula but as I can see, it's not really working.

Ruli
  • 2,592
  • 12
  • 30
  • 40

1 Answers1

2

First, be assured, the Euler formula still holds.

I can see several problems with your algorithm (apart from the style):

  • It won't work for odd V (number of vertices) and high enough E (number of edges); more precisely: for V = 2k+1 and E >= 2V the resulting graph won't be planar
  • It won't work as expected for E > 2V. Depending on what your AddEdge does, it will either produce a multigraph with more edges between the same vertices, or produce a graph with less edges than required.
  • It only produces (in the cases it works) a very special class of planar graphs, and, in my opinion, not a very interesting class.
voidengine
  • 2,504
  • 1
  • 17
  • 29