Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 758
TheMP Avatar asked Jun 16 '15 19:06

TheMP


3 Answers

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

like image 78
adarsh003 Avatar answered Oct 31 '22 17:10

adarsh003


You can access the outgoing edges of a node(vertex) with outgoingEdgesOf method of a graph object.

Set<MyEdge> edges = myGraph.outgoingEdgesOf(sourceNode);

Also, you can use incomingEdgesOf for the incoming edges.

If you want to access all edges of a node then use

graph.edgesOf(source)
like image 40
Memin Avatar answered Oct 31 '22 17:10

Memin


Any object that implements the interface Graph<V,E> should have the method edgesOf(V vertex), at least according to the API. Your TransportGraph should be able to do this.

like image 1
milez Avatar answered Oct 31 '22 18:10

milez