Re: [jgrapht-users] Shortest path from a source
Brought to you by:
barak_naveh,
perfecthash
From: Adib R. <adi...@gm...> - 2017-11-27 16:11:36
|
Thanks. Actually, I realized that I should use labeled graph for my case which jGrapht supports properly. Thanks, Adib On Mon, Nov 27, 2017 at 10:52 AM, J Kinable <j.k...@gm...> wrote: > Without additional information, your question is impossible to answer. We > cannot see how your graph is constructed, or what the definition of your > TopoVertex is. > Common issues: > 1. Instead of an undirected graph, you create a *directed* graph with an > edge from a to b. Then you query the shortest path from b to a, but there > is no such path. > 2. You did not implement the hashcode/equals functions, see: > https://github.com/jgrapht/jgrapht/wiki/EqualsAndHashCode > > br, > > Joris > > On Sun, Nov 26, 2017 at 10:12 PM, Adib Rastegarnia < > adi...@gm...> wrote: > >> Hello, >> >> I created a graph using jGrapht library which is based on a network >> topology and printed the results as follows: >> >> of:0000000000000191:3,of:0000000000000003:1 >> of:0000000000000191:2,of:0000000000000002:1 >> of:0000000000000192:3,of:0000000000000003:2 >> of:0000000000000192:2,of:0000000000000002:2 >> of:0000000000000191:1,of:0000000000000001:1 >> of:0000000000000192:1,of:0000000000000001:2 >> of:0000000000000003:1,of:0000000000000191:3 >> of:0000000000000003:2,of:0000000000000192:3 >> of:0000000000000002:1,of:0000000000000191:2 >> of:0000000000000001:1,of:0000000000000191:1 >> of:0000000000000002:2,of:0000000000000192:2 >> of:0000000000000001:2,of:0000000000000192:1 >> >> Each vertex in my graph is defined as a device ID and a port number. I >> tried to run a shortest path algorithm to find the shortest path between >> two end points as follows: >> >> DijkstraShortestPath<TopoVertex, TopoEdge> dijkstraAlg = >> new DijkstraShortestPath<>(topoStore.getDirectedGraph()); >> >> TopoVertex src = new TopoVertex("of:0000000000000001", "2"); >> TopoVertex dst = new TopoVertex("of:0000000000000002", "2"); >> ShortestPathAlgorithm.SingleSourcePaths<TopoVertex, TopoEdge> iPaths = dijkstraAlg.getPaths(src); >> System.out.println(iPaths.getPath(dst) + "\n"); >> >> It prints null but there is a path between these two end points. >> >> Any suggestions? >> >> Thanks, >> >> Adib >> >> >> >> >> >> ------------------------------------------------------------ >> ------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> jgrapht-users mailing list >> jgr...@li... >> https://lists.sourceforge.net/lists/listinfo/jgrapht-users >> >> > |