[jgrapht-users] Problem with ListenableDirectedGraph with custom edge class
Brought to you by:
barak_naveh,
perfecthash
From: Andreea S. <and...@ya...> - 2014-05-18 22:17:10
|
Hi, I have a problem when using a ListenableDirectedGraph with a custom edge, as shown below: ListenableDirectedGraph<CypherBasicNode, CypherBasicEdge> dirGraph = new ListenableDirectedGraph<CypherBasicNode, CypherBasicEdge>(CypherBasicEdge.class); Everything is displayed fine in the Applet, but when I issue a dirGraph.edgeSet() the set is not correct. The first value in the set it is correct, while all the rest are null. I was researching and saw that when an addEdge is made, the empty constructor of the custom edge class is called (which I don't understand why, because I create the edge beforehand and I add it using: CypherBasicEdge edge = new CypherBasicEdge(relId); dirGraph.addEdge(firstNode, secondNode, edge); ). If I delete the empty constructor I get a "java.lang.RuntimeException: Edge factory failed" exception, because in add newInstance() is called (which is weird considering that an edge Object is given as an argument to addEdge ). If I run this code: CypherBasicEdge edge = new CypherBasicEdge(relId); dirGraph.addEdge(firstNode, secondNode, edge); System.out.println("first edge: " + edge); System.out.println("second edge: " + dirGraph.getEdge(firstNode, secondNode)); I get the following output: first edge: r2 {} second edge: null {} Which to me seems very unlikely to be correct. Meanwhile, the visual representation is correct. Also, if I change the graph from ListenableDirectedGraph to DefaultDirectedGraph, everything works correctly. I am not sure whether I have not understood how I should use the classes or there is some kind of bug. I would appreciated any help. Best regards, Andreea Sandu |