graphstream / gs-core

Graphstream core
http://graphstream-project.org/
Other
399 stars 108 forks source link

Problem in finding Betweenness Centrality #228

Open pranavgaba11 opened 7 years ago

pranavgaba11 commented 7 years ago

I am using Graphstream library in java to implement and find betweenness centrality of the nodes in the graph. When I specifically find out for a node like nodeA.getAttribute("Cb") it works fine. But when I calculate it for the whole graph using a for loop it gives error

 for(Node n: g){
        hm2.put(n.getId(),n.getDegree());
        float x=n.getAttribute("Cb");
        hm1.put(n.getId(),n.getAttribute("Cb"));
        double bet=n.getAttribute("Cb");
        double a=(double)n.getDegree()+bet;
        hm3.put(n.getId(),a);
    }

This is a loop where I will find degree centrality and betweenness centrality and combine both and put them in a hash map. So, I am getting error in float x=n.getAttribute("Cb"); The error is-

Exception in thread "main" java.lang.NullPointerException
at Test.main(Test.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Whereas when I find it for only a single node like if the node in the graphs are A,B,C,D,E

 System.out.println("A="+ A.getAttribute("Cb"));
    System.out.println("B="+ B.getAttribute("Cb"));
    System.out.println("C="+ C.getAttribute("Cb"));
    System.out.println("D="+ D.getAttribute("Cb"));
    System.out.println("E="+ E.getAttribute("Cb"));

This way it works perfectly fine.

Can please someone help fix my code. Thanks in advance.

talhajunaidd commented 6 years ago

It looks like you are missing cast try x=(Double) n.getAttribute("Cb");

pigne commented 6 years ago

Please provide us a simple and self contained example (SSCCE) so we can try to help you.

akankshachandel commented 6 years ago

Were you able to solve the problem and get the betweeness centrality of each node @pranavgaba11 ?? I am stuck with the same problem. Please let me know if you found a solution.