Re: [jgrapht-users] Weighted graphs
Brought to you by:
barak_naveh,
perfecthash
From: John V. S. <js...@gm...> - 2010-06-12 20:28:07
|
The default edge implementations are optimized to be "intrusive"; that is, they contain direct references to their vertices. When the graph sees an edge class that extends a default edge, it assumes that it can use these references rather than maintaining the edge/vertex association indirectly via a HashMap (which is more expensive). In your case, you are creating a new edge on the fly, so when the graph examines it, the references are null. When you use a non-default implementation everything works because then the new GRFEdge probably Object.equals some existing edge in the graph. JVS Fabian K wrote: > my graph class: > public class GRFGraph extends DefaultDirectedWeightedGraph<GRFNode, GRFEdge> > > my Edge class: > public class GRFEdge extends DefaultWeightedEdge > > following method doesn't work anymore, it returns null. > GRFNode srcNode = graph.getEdgeTarget(new GRFEdge(1)); > > when my GRFEdge doesnt extend DefaultWeightedEdge it works fine. It will > return the node. > > What is wrong with this call? > > FYI: > in my GRFEdge class I override getWeight method already. > > @Override > public double getWeight() { > return weight; > } |