Skip to content

Commit

Permalink
Committing to work across machines
Browse files Browse the repository at this point in the history
  • Loading branch information
sayoder committed May 12, 2015
1 parent 397d903 commit a4f4893
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ module Main where
import GraphTheory.Graph
import GraphTheory.SpecialGraphs
import qualified Data.Map as M

infinity = 1/0
import Data.Maybe (fromJust)

g1 :: Graph Integer Integer
g1 = uwGraph [1, 2, 3, 4, 5, 6] [((1,2),0), ((3,2),0),((5,3),6),((4,1),10),((5,6),1)]

--dijkstra :: Graph v e -> [(v,e)]
--dijkstra g = dijkstra' g (Hash.new (==) (Hash.hashString . show))
dijkstra :: (Integral e, Bounded e, Ord v) => Graph v e -> [(v,e)]
dijkstra g = dijkstra' g (infTable g) []

infTable :: (Integral e, Bounded e, Ord v) => Graph v e -> M.Map v e
infTable g = foldl (\m v -> M.insert v maxBound m) M.empty (vertices g)

dijkstra' :: (Integral e, Ord v) => Graph v e -> M.Map v e -> [v] -> [(v,e)]
dijkstra' g l t
| M.size l == length (vertices g) = map (\v -> (v, fromJust $ M.lookup v l)) $ vertices g
| otherwise = [(head $ vertices g, snd . head $ edges g)]

main = putStrLn $ show g1

0 comments on commit a4f4893

Please sign in to comment.