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.