0

こんにちは、JGraphT を使用して大きなプロジェクトを構築しています。このために、JGraphT の Djikstra のクラスを使用して、2 つのノード セット間の最短パスを返すメソッドを作成しました。

パスまたはそのサブメソッドにアクセスしようとすると、NullPointerException が発生します。これの意味は

path = new DijkstraShortestPath(graph, v, y);

大丈夫ですが、

path.getPathLength()

例外をスローします。

これはコードです:

static GraphPath GraphsDistance(Graph graph, Set<CustomVertex> source, Set<CustomVertex> destination){
//returns the shortest path between 2 sets on nodes
DijkstraShortestPath path,solution;
double distance=Double.MAX_VALUE;
solution=null;

for(CustomVertex v:source){
    for(CustomVertex y:destination){
        path = new DijkstraShortestPath(graph, v, y);
        if (path.getPathLength()<distance){
            distance=path.getPathLength();
            solution=path;
        }
    }
}
System.out.println("source: "+source.toString()+ "\ndestination: "+destination.toString());
return solution.getPath();
}

それが何であるかの手がかりはありますか?

これは私のシステムです:

Product Version: NetBeans IDE 7.0.1 (Build 20121011-unknown-revn)
Java: 1.6.0_27; OpenJDK Client VM 20.0-b12
System: Linux version 3.5.0-17-generic running on i386; UTF-8; en_US (nb)
4

1 に答える 1

0

グラフが接続されていないようです。ノードの 1 つが null になると、パスの長さの値を評価する前であっても NullPointer が返されます。接続された小さなサンプル グラフと接続されていない別のサンプル グラフを使用して、JUnit テストでケースを試してみることをお勧めします。

于 2013-06-08T10:39:45.227 に答える