Firstly, sorry if I am missing something obvious. Please let me know in that case with a pointer, and I'll take it from there. But here's what I am facing:
dijkstra's shortestpath getPath() returns an exception with message: "Edges: ......." where the dots are actually a list of all edge and node objects in the memory printed alternately. This exception happens at edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath.getPath(DijkstraShortestPath.java:164)
I don't have a way to know what is going on? Is this because there is (probably) not a path between the nodes I am specifying?
Thanks in anticipation for help!
You can easily test to see whether there is a path by calculating the shortest paths from your source vertex and trying to retrieve the distance to the destination vertex. If the answer is "null" then you can't get there from here.
Please post the entire stack trace. getPath() itself shouldn't be throwing that exception.
Thanks for your reply. Actually, I didn't see any of your comments until my page reloaded with mine, just a few moments ago.
The graph is directed, and I know there is a directed path between the two nodes I am passing as argument to getPath(). I confirmed it just before I posted my last comment. I am generating the stack trace again (starting the server and processes and regenerating the exception), and will post it here. Till then -
All I see in the stack trace is "Edges: myedge@hashCode mynode@hashCode myedge@hashCode mynode@hashCode...." and so on .. a long list. And where is spits this is at edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath.getPath(DijkstraShortestPath.java:164) . Every call after this in the stack trace are my methods (just invocations with arguments, as it runs fine with other pairs of nodes).
Could this long list be because the graph finds a cycle?
Alright, it seems the messages were stripped randomly in the earlier logs :-O. I don't know why. It now says (on the eclipse output) I'm passing a vertex that's not a part of the graph. But the earlier logs didn't show this line (and many others) printed before the Edges:..... list; may be a broken logger.
So I know the cause now.
Sorry for taking your time, and apologies for a problem on our side created this confusion over getPath()/api.
We probably ought to be more conservative either about how the toString() is constructed for a Graph, or about when we include the toString() in a message. For large graphs just generating that message could be problematic. :P
Thanks for bringing that to our attention (even if that wasn't your original intent). :)
Good point. And nice of you to pick that up!
I thought instead of printing objects (name@hashCode), probably let the user extend toString or some other method (say, name()) for edges and nodes and use that for printing the graph. That might be more helpful since I can relate better to it, if a list of nodes (I guess from toString() of the graph) be included in the message. Again, I haven't looked at the code, so I don't know if this is already there :D. Yet, just a thought.