Graph 平面图生成:欧拉公式不适用吗?

Graph 平面图生成:欧拉公式不适用吗?,graph,Graph,我试图建立一些平面图生成算法。我读了很多关于这个主题的资料,她的结果如下: public Graph graph; ... public Level(int numPoints, int numEdges, int levelID, int timeLim) { this.graph = new Graph(numPoints, numEdges); this.graph.GeneratePlanarGraph(); ... } **Here i w

我试图建立一些平面图生成算法。我读了很多关于这个主题的资料,她的结果如下:

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++;
    }
}
公共图形;
...
公共级别(int numPoints、int numEdges、int levelID、int timeLim)
{
this.graph=新图形(numPoints、numEdges);
this.graph.GeneratePlanarGraph();
...
}
**这里我写了一些函数来构建平面图**
public void GeneratePlanarGraph(){
if(this.edges\u num对于(int i=1;i首先,请确保,欧拉公式仍然成立

我发现您的算法存在一些问题(除了样式):

  • 对于奇数V(顶点数)和足够高的E(边数),它不起作用;更准确地说:对于V=2k+1和E>=2V,生成的图形将不是平面的
  • 对于E>2V,它不会像预期的那样工作。根据
    AddEdge
    的操作,它将生成一个在相同顶点之间具有更多边的多重图,或者生成一个边少于所需边的图
  • 它只产生(在它工作的情况下)一个非常特殊的平面图类,在我看来,不是一个非常有趣的类
for(int i = 0 ; i < 100 ; i++)
{
    levels[i] = new Level(numPoints, numEdges,  levelID,  timeLim);
}