我试图为平面图生成构建一些算法。我阅读了很多关于这个主题的材料,她的结果是:
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++;
}
}
因此,当我启动程序时,它会以这种方式生成一些平面图:
for(int i = 0 ; i < 100 ; i++)
{
levels[i] = new Level(numPoints, numEdges, levelID, timeLim);
}
所有这些代码都非常好用,但我在测试图形时已找到(水平)24,36,...不是平面的:((
你帮我吗?我知道eulers公式,所以我通过eulers公式生成我的顶点/边缘,但我可以看到它不是真的有效答案 0 :(得分:2)
首先,请放心,欧拉公式仍然存在。
我可以看到你的算法有几个问题(除了风格):