I'm using Martin Erwig's Functional Graph Library (FGL) to represent the following simple directed weighted graph.
genLNodes :: [LNode String]
genLNodes = zip [1..5] ["A","B","C","D","E"]
genLEdges :: [LEdge Int]
genLEdges = [(1,2,4),(1,3,1),(2,4,2),(3,4,2),(2,5,1),(4,5,1),
(2,1,4),(3,1,1),(4,2,2),(4,3,2),(5,2,1),(5,4,1)]
mygraph :: Gr String Int
mygraph = mkGraph genLNodes genLEdges
Now I want to find the shortest path from one node to another e.g. A
to E
using dijkstra's algorithm. There seems to be a function to do that in Data.Graph.Inductive.Query.SP
:
dijkstra :: (Graph gr, Real b) => Heap b (LPath b) -> gr a b -> LRTree b
But I'm not able to figure out how to use it from the interface provided. Any help would be much appreciated. I would also like to hear any other suggestions, if I'm creating the directed weighted graph the right way, or if there's any other (better) package to do so?