收录日期:2020/10/23 11:05:04 时间:2013-09-30 18:20:08 标签:java,graph,jung,directed-graph,topological-sort

Does anyone know if the Java Jung2 graph library provides the in-built capability to traverse a Digraph (directed graph) given a start Vector? I did see that there's a BFSDistanceLabeler class that returns a map of distances, which could do, but I then need to sort the values (highest distance first) and iterate through the sorted set.

I'm creating a dependency management facility for Javascript using Maven and so I was thinking about using Jung2 to maintain my dependency graph.

I'm not sure what you mean by "traverse a digraph given a start vector". If you want to do a topological sort of a graph and then iterate through the vertices in that order, that's pretty easy:

(1) Calculate the breadth-first distances using BFSDistanceLabeler. (2) Create a Comparator for vertices that is aware of those distances (it will need to look up the distance for a vertex in the BFSDL data). (3) Get the collection of vertices from the graph and sort it using that Comparator.