haskell-dijkstra icon indicating copy to clipboard operation
haskell-dijkstra copied to clipboard

Add two useful features: fromEdgeList, pathToNodeLength

Open fercsi opened this issue 2 years ago • 0 comments

I suggest you to add two functions to this lib. The names and the implementation can be different, of course, but something as follows:

-- Similar to `fromText`, but the input is list of tuples of a node name pair and the weight of the
-- edge between them instead of the string
fromEdgeList :: [((String, String), Float)] -> Bool -> Graph
fromEdgeList edgeList isDigraph =
  let allEs = if isDigraph then edgeList
              else appendReversed edgeList
  in fromList allEs

and

-- given a Dijkstra solution and a destination node, return the length of path
pathToNodeLength :: [Dnode] -> Node -> Float
pathToNodeLength dnodes dest = fst . snd . dnodeForNode dnodes $ dest

fercsi avatar Jun 14 '23 14:06 fercsi