JGraphT Library如何访问边的顶点

时间:2015-01-05 20:41:23

标签: java routing jgrapht

我有一个返回边列表的函数但是我想访问边的顶点。

DijkstraShortestPath.findPathBetween(graph,start,end)这是返回边列表的函数。

我想访问每条边的顶点。

我试图寻找一种方法,但我找不到任何方法。

1 个答案:

答案 0 :(得分:1)

如果你有所有边缘,你可以使用这里提到的方法: http://jgrapht.org/javadoc/org/jgrapht/Graph.html

取自API:

V getEdgeSource(E e)

//Returns the source vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).

    Parameters:
        e - edge of interest 
    Returns:
        source vertex


V getEdgeTarget(E e)

    //Returns the target vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).

    Parameters:
        e - edge of interest 
    Returns:
        target vertex

因此,对于列表中的每个Edge,只需获取源/目标顶点