[jgrapht-users] add edge to directed graph in both directions
Brought to you by:
barak_naveh,
perfecthash
From: Joris K. <de...@gm...> - 2015-06-23 16:30:09
|
Say I have a list of directed and undirected edges which I would like to represent in the same graph. Every undirected edge (i,j) can be represented in a directed graph by adding two arcs: (i,j) and (j,i). The following code does however *not* achieve this: public static void main(String[] args){ DirectedGraph<Integer, String> directedGraph=new SimpleDirectedGraph<Integer, String>(String.class); String s="UndirectedEdge"; directedGraph.addVertex(1); directedGraph.addVertex(2); System.out.println(directedGraph.addEdge(1,2,s)); System.out.println(directedGraph.addEdge(2,1,s)); } The second addEdge call will return false because edge s is already in the graph. What would be a clean way to resolve this issue? Thanks, Joris |