Factory<FinalNode> vertexFactory = new Factory<FinalNode>() {
int ID;
public FinalNode create() {
return new FinalNode(ID++, "239829834298374", "Bla");
}};
Factory<FinalLink> edgeFactory = new Factory<FinalLink>() {
int ID;
public FinalLink create() {
return new FinalLink(ID++, "123", "2323", "4444", "22");
}};
WeightedNIPaths<FinalNode, FinalLink> WDranker = new WeightedNIPaths<FinalNode, FinalLink>(graph3,vertexFactory, edgeFactory, 2.0,5,rootset);
WDranker.evaluate();
and i get this error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ClassCastException: FinalLink cannot be cast to FinalNode
at FinalNode.equals(SocialNetworkAnalysis.java:5943)
at java.util.HashMap.put(HashMap.java:393)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.newVertexEncountered(WeightedNIPaths.java:165)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.computeWeightedPathsFromSource(WeightedNIPaths.java:137)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.step(WeightedNIPaths.java:171)
at edu.uci.ics.jung.algorithms.util.IterativeProcess.evaluate(IterativeProcess.java:68)
In 165 line
roots.put(dest, root);
it tries to add dest which is FinalNode whereas everywhere before used roots to map FinalEdge/FinalNode and not 2 FinalNodes. In the test of the algorithm it works fine.. am i doing something wrong? or is problem of the algorithm?
Any help is appreciated.
Best,
John
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, I'd start by looking at the place where you've defined
FinalNode.equals(). If it works with out-of-the-box classes for edge
and vertex classes, and not with yours, that is a fairly strong
indicator of where the problem probably is. :)
Joshua
PS: Posts to the forum are echoed to jung-support; please don't post questions in both places.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(1) Did you override hashCode() as well? If you override one, you generally need to override the other. This is a general Java problem, not a JUNG-specific one.
(2) If Final{Edge,Node} just contain names, and you want to guarantee that they're unique, why not just use Strings instead? That would enforce uniqueness (since you can't add successfully add two different vertices (or edges) x, y where x.equals(y); you can check the return value of the add() methods to make sure that you didn't accidentally try to add non-unique values).
Joshua
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Override public int hashCode() {
return this.ID;
}
@Override public boolean equals(Object that) {
FinalNode that2 = (FinalNode) that;
if ( this.Name.equals(that2.Name)) return true;
else return false;
}
The ID is the hashCode of Name when i create a new node.
For the second question, I could use just string, but i make information network with the graph so i want each edge and node to be associated with several metadata, so i need to have a class for Node and Edge. (i could use a hash map for this association.. but i thought i easier to have all info on the graph).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am running this code
Factory<FinalNode> vertexFactory = new Factory<FinalNode>() {
int ID;
public FinalNode create() {
return new FinalNode(ID++, "239829834298374", "Bla");
}};
Factory<FinalLink> edgeFactory = new Factory<FinalLink>() {
int ID;
public FinalLink create() {
return new FinalLink(ID++, "123", "2323", "4444", "22");
}};
WeightedNIPaths<FinalNode, FinalLink> WDranker = new WeightedNIPaths<FinalNode, FinalLink>(graph3,vertexFactory, edgeFactory, 2.0,5,rootset);
WDranker.evaluate();
and i get this error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.ClassCastException: FinalLink cannot be cast to FinalNode
at FinalNode.equals(SocialNetworkAnalysis.java:5943)
at java.util.HashMap.put(HashMap.java:393)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.newVertexEncountered(WeightedNIPaths.java:165)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.computeWeightedPathsFromSource(WeightedNIPaths.java:137)
at edu.uci.ics.jung.algorithms.importance.WeightedNIPaths.step(WeightedNIPaths.java:171)
at edu.uci.ics.jung.algorithms.util.IterativeProcess.evaluate(IterativeProcess.java:68)
In 165 line
roots.put(dest, root);
it tries to add dest which is FinalNode whereas everywhere before used roots to map FinalEdge/FinalNode and not 2 FinalNodes. In the test of the algorithm it works fine.. am i doing something wrong? or is problem of the algorithm?
Any help is appreciated.
Best,
John
John:
Well, I'd start by looking at the place where you've defined
FinalNode.equals(). If it works with out-of-the-box classes for edge
and vertex classes, and not with yours, that is a fairly strong
indicator of where the problem probably is. :)
Joshua
PS: Posts to the forum are echoed to jung-support; please don't post questions in both places.
Thanks for your reply Joshua.
@Override public boolean equals(Object that) {
FinalNode that2 = (FinalNode) that;
if ( this.Name.equals(that2.Name)) return true;
else return false;
}
I need to have unique nodes in my graph, so i defined in such way my node's .equals function. Any clue why is it wrong? Other algorithms are working..
Could i define somehow else unique nodes? (no nodes with the same name).
Two questions:
(1) Did you override hashCode() as well? If you override one, you generally need to override the other. This is a general Java problem, not a JUNG-specific one.
(2) If Final{Edge,Node} just contain names, and you want to guarantee that they're unique, why not just use Strings instead? That would enforce uniqueness (since you can't add successfully add two different vertices (or edges) x, y where x.equals(y); you can check the return value of the add() methods to make sure that you didn't accidentally try to add non-unique values).
Joshua
Hey,
For the first question yes i override both:
@Override public int hashCode() {
return this.ID;
}
@Override public boolean equals(Object that) {
FinalNode that2 = (FinalNode) that;
if ( this.Name.equals(that2.Name)) return true;
else return false;
}
The ID is the hashCode of Name when i create a new node.
For the second question, I could use just string, but i make information network with the graph so i want each edge and node to be associated with several metadata, so i need to have a class for Node and Edge. (i could use a hash map for this association.. but i thought i easier to have all info on the graph).