javagraphjgraphtjgraph

Getting all edges going out from a node in jgrapht


I am trying to randomly traverse through the graph in jgrapht (until I find some target node). To do it, I need to start at the sourceNode, randomly pick any coming out edge and follow it.

I know there there is a method getAllEdges(sourceVertex, targetVertex) that returns all the edges between two given nodes. But how can I get all edges while having only sourceNode, without the target one?


Solution

  • You can use Graphs.predecessorListOf and Graphs.successorListOf apis directly.