Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inf = 100000
- dijkstra ::Int->Int->[(Int,Int,Int)]->[(Int,Int)]->[(Int,Int)]
- dijkstra s d adjList visited
- | (p,q) == (inf, inf) = visited
- | otherwise = dijkstra p d adjList ((p,q):visited)
- where (p,q) = exploreNeighbours s visited adjList
- exploreNeighbours ::Int->[(Int,Int)]->[(Int,Int,Int)]->(Int,Int)
- exploreNeighbours source visited adjList =
- retMinNode (relax [(x,y,z) | (x,y,z) <- [(s,d,e) | (s,d,e)<-adjList, (belongsTo source visited)], not (belongsTo y visited)] visited)
- belongsTo::Int->[(Int,Int)]->Bool
- belongsTo _ [] = False
- belongsTo s ((x,_):xs)
- | (x==s) = True
- | otherwise = belongsTo s xs
- relax :: [(Int,Int,Int)]->[(Int,Int)]->[(Int,Int)]
- relax [] visited = []
- relax ((x,y,z):ns) visited = (y, (currDist x) + z):relax ns visited
- where currDist n = foldl(\acc t -> if (fst t == n) then (snd t) else acc) inf visited
- retMinNode ::[(Int,Int)]->(Int,Int)
- retMinNode [] = (inf,inf)
- retMinNode arr = foldl (\acc t -> if ((snd t) < (snd acc)) then t else acc) (inf,inf) arr
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement