I want to know how to check if two vertices are connected in a graph using Jung Framework. Thanks.
Asked
Active
Viewed 833 times
0
-
In JUNG, two vertices V1, V2 are "connected" by its edge E(V1, V2) in a given direction. If you maintain an edge list/map (some JUNG samples use the idea of storing vertices and edges information in a map like in the shortest path graph demo), it will be easy to iterate. – ee. Aug 30 '12 at 02:27
-
[findEdge(V v1, V v2)](http://jung.sourceforge.net/doc/api/edu/uci/ics/jung/graph/Hypergraph.html#findEdge%28V,%20V%29) is not null if v2 is connected to v1 by an edge – ee. Aug 30 '12 at 02:42
-
1Your question is not clearly phrased, as your response to the first answer indicates. What you want could be phrased as "in the same [strongly/weakly] connected component", or "vertex v is reachable from vertex u", or "there is a path from u to v". But "are connected" usually means "there is an edge between u and v". – Joshua O'Madadhain Aug 30 '12 at 06:31
1 Answers
0
If the graph is undirected (you haven't specified) or if you don't care about edge direction, use WeakComponentClusterer to split the graph into its (weakly) connected components, and then check to see if the vertices are in the same component. (BicomponentClusterer is not correct for this case if I understood your question correctly.)

Joshua O'Madadhain
- 2,704
- 1
- 14
- 18