Hello everyone;
I have a project in which i need to implement a graph (directed &
weighted), and i found your work which helped me a lot, but i have a
problem and i want you to help me out.
When i create my SimpleDirectedWeightedGraph object "graph" and insret the
vertexes (type Site in my case) and edges (Type Lien in my case) and apply
the "incomingEdgesOf(Vertex v)" method to the "graph", i put the result in
a Set<Lien> and i find that the size (number of incoming edges) is correct
but when i apply the method again on the resulting set of edges "so that i
can calculate the number of descendants of an Edge" an exception in thrown
which says java.lang.NullPointerException .
-------------------------------------------------------------------------------
Here is my code:
//CALCULATE THE NUMBER OF DESCENDANTS OF AN EDGE (WHERE SITE S IS THE
DESTINATION VERTEX) IN THE GRAPH
public int nbrDescendants(Site s)
{
int i=0;
Set<Lien> children = graph.incomingEdgesOf(s);
Iterator<Lien> it = children.iterator();
while(it.hasNext())
{
i+= graph.incomingEdgesOf(it.next().getSlave()).size();
//getSlave() returs in my case the destination vertex of the edge
}
i+=children.size();
return i;
}
-----------------------------------------------------------------------------------
Here is the error message:
java.lang.NullPointerException
at
org.jgrapht.graph.AbstractGraph.assertVertexExist(AbstractGraph.java:156)
at
org.jgrapht.graph.AbstractBaseGraph$DirectedSpecifics.getEdgeContainer(AbstractBaseGraph.java:925)
at
org.jgrapht.graph.AbstractBaseGraph$DirectedSpecifics.incomingEdgesOf(AbstractBaseGraph.java:885)
at
org.jgrapht.graph.AbstractBaseGraph.incomingEdgesOf(AbstractBaseGraph.java:411)
at inwi.capacite.calcul.Reseau.nbrDescendants(Reseau.java:62)
at inwi.capacite.calcul.Rapport.main(Rapport.java:86)
------------------------------------------------------------------------------------
And finally i'm not sure but i think that the error comes from the
AbstractBaseGraph.java file, where i found this:
*/
public Set<EE> getUnmodifiableOutgoingEdges()
{
if (unmodifiableOutgoing == null) {
unmodifiableOutgoing =
Collections.unmodifiableSet(outgoing);
}
return unmodifiableOutgoing;
}
i think this methode must return Set<E> and not Set<EE>.
|