如何制作星图?

时间:2015-05-29 09:59:37

标签: java jgrapht

我正在尝试使用JGraphT创建星图,但是我写的内容似乎对编译器来说是错误的。我得到的是标有NullPointerException的行NULL POINTER。那是为什么?

private static DefaultWeightedEdge edge(int i, int j) {
    DefaultWeightedEdge graphEdge = Graph.getEdge(i,j);
    return graphEdge;
}

private static int vertex(int i) {
    int vertex = VertexArray[i-1];
    return vertex;
}

private static void setWeight(DefaultWeightedEdge edge, double weight) {
    Graph.setEdgeWeight(edge, weight); //NULL POINTER
}


private static SimpleWeightedGraph<Integer, DefaultWeightedEdge> createWeightedGraph() {
    Graph = new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);

    for (int i = 0; i < numberOfVertices; i++) {
        VertexArray[i] = i+1;
        Graph.addVertex(vertex(i+1));
    }

    for (int i = 1; i <= numberOfEdges; i++) {
        DefaultWeightedEdge edge = Graph.addEdge(vertex(1), vertex(i+1)); 
    }

    for (int i = 1; i <= numberOfEdges; i++) {
        setWeight(edge(1, i), 0.95);} //NULL POINTER

   //I would like to start group of threads here
    service=Executors.newFixedThreadPool(manNum);
        for(int k=0; k < manNum; k++){
            ManufacturePattern manPat=new ManufacturePattern(k);
            service.submit(manPat);
        }

    return Graph;
}

0 个答案:

没有答案