Quantcast

Please, i need help concerning the SimpleDirectedWeightedGraph Class

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Please, i need help concerning the SimpleDirectedWeightedGraph Class

mokhtar aitbaomar
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>.​



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Please, i need help concerning the SimpleDirectedWeightedGraph Class

Joris Kinable
Without seeing more code it's difficult to check what goes wrong. It's very unlikely that there is a problem in the AbstractBaseGraph implementation. Check your implementation of your getSlave method first.

Why don't you use the following: 
public int nbrDescendants(Site s){
 int i=0;
 Set<Lien> children = graph.incomingEdgesOf(s);
  for(Lien lien: children){
    i+=graph.inDegreeOf(graph.getEdgeTarget(lien));
   }
  return i;
}

Btw, I don't really see the point of this code. If there are 5 incoming edges for a given site s, then this method will return 5*5=25? Unless I misunderstood what you mean with "destination vertex of an edge"?

best,

Joris


On Thu, Feb 26, 2015 at 3:39 PM, mokhtar aitbaomar <[hidden email]> wrote:
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>.​



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users



------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
jgrapht-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgrapht-users
Loading...