Haskell 06
Haskell 06
-- 1 ------------------------------------
isOrdinary :: Graph -> Bool
isOrdinary [] = error "Empty list was passed as an argument"
isOrdinary gr = checkTwoDirConn gr && checkNoLoops gr && checkNotMultigraph gr
-- 2 ------------------------------------
fromGraph :: Graph -> GraphS
fromGraph gr = (length gr - 1, [(ind, y) | (ind, xs) <- zip [0..] gr, y <- xs])
-- 3 ------------------------------------
toGraph :: GraphS -> Graph
toGraph grs = [[s | (v, s) <- snd grs, v == x] | x <- [0..(fst grs)]]
-- 4 ------------------------------------
allWays :: Graph -> Int -> [[[Int]]]
allWays gr v = until condW stepW [[[v]]]
where condW :: [[[Int]]] -> Bool
condW = null . head
stepW :: [[[Int]]] -> [[[Int]]]
stepW wss = [t:(p:ps) | (p:ps) <- head wss, notElem p ps, t <- gr !! p] :
wss
-- 5 ------------------------------------
goNodes :: Graph -> Int -> [Int]
goNodes gr v = snd $ until condN (oneStep gr) ([v],[])
-- 6 ------------------------------------
-- all vertex of Graph g
nodes :: Graph -> [Int]
nodes g = [0..(length g - 1)]
-- 7 ------------------------------------
eccentricity :: Graph -> Int -> Int
eccentricity gr v = maximum [length $ shortWay gr v x | x <- nodes gr] - 1
-- 8 ------------------------------------
allEccentricities :: Graph -> [Int]
allEccentricities gr = [eccentricity gr x | x <- nodes gr]
-- 9 ------------------------------------
allEccentricitiesWithNodes :: Graph -> [(Int, Int)]
allEccentricitiesWithNodes gr = [(eccentricity gr x, x) | x <- nodes gr]