module Algebra.Graph.Acyclic.AdjacencyMap (
AdjacencyMap, fromAcyclic,
empty, vertex, vertices, union, join,
isSubgraphOf,
isEmpty, hasVertex, hasEdge, vertexCount, edgeCount, vertexList, edgeList,
adjacencyList, vertexSet, edgeSet, preSet, postSet,
removeVertex, removeEdge, transpose, induce, induceJust,
box,
transitiveClosure,
topSort, scc,
toAcyclic, toAcyclicOrd, shrink,
consistent
) where
import Data.Set (Set)
import Data.Coerce (coerce)
import qualified Algebra.Graph.AdjacencyMap as AM
import qualified Algebra.Graph.AdjacencyMap.Algorithm as AM
import qualified Algebra.Graph.NonEmpty.AdjacencyMap as NAM
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.Map as Map
import qualified Data.Set as Set
newtype AdjacencyMap a = AAM {
AdjacencyMap a -> AdjacencyMap a
fromAcyclic :: AM.AdjacencyMap a
} deriving (AdjacencyMap a -> AdjacencyMap a -> Bool
(AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> Eq (AdjacencyMap a)
forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c/= :: forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
== :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c== :: forall a. Eq a => AdjacencyMap a -> AdjacencyMap a -> Bool
Eq, Eq (AdjacencyMap a)
Eq (AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a -> Ordering)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a)
-> Ord (AdjacencyMap a)
AdjacencyMap a -> AdjacencyMap a -> Bool
AdjacencyMap a -> AdjacencyMap a -> Ordering
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (AdjacencyMap a)
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Ordering
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
min :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
$cmin :: forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
max :: AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
$cmax :: forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
>= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c>= :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
> :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c> :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
<= :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c<= :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
< :: AdjacencyMap a -> AdjacencyMap a -> Bool
$c< :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
compare :: AdjacencyMap a -> AdjacencyMap a -> Ordering
$ccompare :: forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (AdjacencyMap a)
Ord)
instance (Ord a, Show a) => Show (AdjacencyMap a) where
showsPrec :: Int -> AdjacencyMap a -> ShowS
showsPrec Int
p aam :: AdjacencyMap a
aam@(AAM AdjacencyMap a
am)
| [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [a]
vs = String -> ShowS
showString String
"empty"
| [(a, a)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(a, a)]
es = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ [a] -> ShowS
forall a. Show a => [a] -> ShowS
vshow [a]
vs
| Bool
otherwise = Bool -> ShowS -> ShowS
showParen (Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$ String -> ShowS
showString String
"(fromJust . toAcyclic) ("
ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyMap a -> ShowS
forall a. Show a => a -> ShowS
shows AdjacencyMap a
am ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ShowS
showString String
")"
where
vs :: [a]
vs = AdjacencyMap a -> [a]
forall a. AdjacencyMap a -> [a]
vertexList AdjacencyMap a
aam
es :: [(a, a)]
es = AdjacencyMap a -> [(a, a)]
forall a. AdjacencyMap a -> [(a, a)]
edgeList AdjacencyMap a
aam
vshow :: [a] -> ShowS
vshow [a
x] = String -> ShowS
showString String
"vertex " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 a
x
vshow [a]
xs = String -> ShowS
showString String
"vertices " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [a] -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 [a]
xs
empty :: AdjacencyMap a
empty :: AdjacencyMap a
empty = AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a
forall a. AdjacencyMap a
AM.empty
vertex :: a -> AdjacencyMap a
vertex :: a -> AdjacencyMap a
vertex = (a -> AdjacencyMap a) -> a -> AdjacencyMap a
coerce a -> AdjacencyMap a
forall a. a -> AdjacencyMap a
AM.vertex
vertices :: Ord a => [a] -> AdjacencyMap a
vertices :: [a] -> AdjacencyMap a
vertices = ([a] -> AdjacencyMap a) -> [a] -> AdjacencyMap a
coerce [a] -> AdjacencyMap a
forall a. Ord a => [a] -> AdjacencyMap a
AM.vertices
union :: (Ord a, Ord b) => AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (Either a b)
union :: AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (Either a b)
union (AAM AdjacencyMap a
x) (AAM AdjacencyMap b
y) = AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a. AdjacencyMap a -> AdjacencyMap a
AAM (AdjacencyMap (Either a b) -> AdjacencyMap (Either a b))
-> AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a b. (a -> b) -> a -> b
$ AdjacencyMap (Either a b)
-> AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.overlay ((a -> Either a b) -> AdjacencyMap a -> AdjacencyMap (Either a b)
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap a -> Either a b
forall a b. a -> Either a b
Left AdjacencyMap a
x) ((b -> Either a b) -> AdjacencyMap b -> AdjacencyMap (Either a b)
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap b -> Either a b
forall a b. b -> Either a b
Right AdjacencyMap b
y)
join :: (Ord a, Ord b) => AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (Either a b)
join :: AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (Either a b)
join (AAM AdjacencyMap a
a) (AAM AdjacencyMap b
b) = AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a. AdjacencyMap a -> AdjacencyMap a
AAM (AdjacencyMap (Either a b) -> AdjacencyMap (Either a b))
-> AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a b. (a -> b) -> a -> b
$ AdjacencyMap (Either a b)
-> AdjacencyMap (Either a b) -> AdjacencyMap (Either a b)
forall a.
Ord a =>
AdjacencyMap a -> AdjacencyMap a -> AdjacencyMap a
AM.connect ((a -> Either a b) -> AdjacencyMap a -> AdjacencyMap (Either a b)
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap a -> Either a b
forall a b. a -> Either a b
Left AdjacencyMap a
a) ((b -> Either a b) -> AdjacencyMap b -> AdjacencyMap (Either a b)
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap b -> Either a b
forall a b. b -> Either a b
Right AdjacencyMap b
b)
isSubgraphOf :: Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
isSubgraphOf :: AdjacencyMap a -> AdjacencyMap a -> Bool
isSubgraphOf = (AdjacencyMap a -> AdjacencyMap a -> Bool)
-> AdjacencyMap a -> AdjacencyMap a -> Bool
coerce AdjacencyMap a -> AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a -> Bool
AM.isSubgraphOf
isEmpty :: AdjacencyMap a -> Bool
isEmpty :: AdjacencyMap a -> Bool
isEmpty = (AdjacencyMap a -> Bool) -> AdjacencyMap a -> Bool
coerce AdjacencyMap a -> Bool
forall a. AdjacencyMap a -> Bool
AM.isEmpty
hasVertex :: Ord a => a -> AdjacencyMap a -> Bool
hasVertex :: a -> AdjacencyMap a -> Bool
hasVertex = (a -> AdjacencyMap a -> Bool) -> a -> AdjacencyMap a -> Bool
coerce a -> AdjacencyMap a -> Bool
forall a. Ord a => a -> AdjacencyMap a -> Bool
AM.hasVertex
hasEdge :: Ord a => a -> a -> AdjacencyMap a -> Bool
hasEdge :: a -> a -> AdjacencyMap a -> Bool
hasEdge = (a -> a -> AdjacencyMap a -> Bool)
-> a -> a -> AdjacencyMap a -> Bool
coerce a -> a -> AdjacencyMap a -> Bool
forall a. Ord a => a -> a -> AdjacencyMap a -> Bool
AM.hasEdge
vertexCount :: AdjacencyMap a -> Int
vertexCount :: AdjacencyMap a -> Int
vertexCount = (AdjacencyMap a -> Int) -> AdjacencyMap a -> Int
coerce AdjacencyMap a -> Int
forall a. AdjacencyMap a -> Int
AM.vertexCount
edgeCount :: AdjacencyMap a -> Int
edgeCount :: AdjacencyMap a -> Int
edgeCount = (AdjacencyMap a -> Int) -> AdjacencyMap a -> Int
coerce AdjacencyMap a -> Int
forall a. AdjacencyMap a -> Int
AM.edgeCount
vertexList :: AdjacencyMap a -> [a]
vertexList :: AdjacencyMap a -> [a]
vertexList = (AdjacencyMap a -> [a]) -> AdjacencyMap a -> [a]
coerce AdjacencyMap a -> [a]
forall a. AdjacencyMap a -> [a]
AM.vertexList
edgeList :: AdjacencyMap a -> [(a, a)]
edgeList :: AdjacencyMap a -> [(a, a)]
edgeList = (AdjacencyMap a -> [(a, a)]) -> AdjacencyMap a -> [(a, a)]
coerce AdjacencyMap a -> [(a, a)]
forall a. AdjacencyMap a -> [(a, a)]
AM.edgeList
adjacencyList :: AdjacencyMap a -> [(a, [a])]
adjacencyList :: AdjacencyMap a -> [(a, [a])]
adjacencyList = (AdjacencyMap a -> [(a, [a])]) -> AdjacencyMap a -> [(a, [a])]
coerce AdjacencyMap a -> [(a, [a])]
forall a. AdjacencyMap a -> [(a, [a])]
AM.adjacencyList
vertexSet :: AdjacencyMap a -> Set a
vertexSet :: AdjacencyMap a -> Set a
vertexSet = (AdjacencyMap a -> Set a) -> AdjacencyMap a -> Set a
coerce AdjacencyMap a -> Set a
forall a. AdjacencyMap a -> Set a
AM.vertexSet
edgeSet :: Eq a => AdjacencyMap a -> Set (a, a)
edgeSet :: AdjacencyMap a -> Set (a, a)
edgeSet = (AdjacencyMap a -> Set (a, a)) -> AdjacencyMap a -> Set (a, a)
coerce AdjacencyMap a -> Set (a, a)
forall a. Eq a => AdjacencyMap a -> Set (a, a)
AM.edgeSet
preSet :: Ord a => a -> AdjacencyMap a -> Set a
preSet :: a -> AdjacencyMap a -> Set a
preSet = (a -> AdjacencyMap a -> Set a) -> a -> AdjacencyMap a -> Set a
coerce a -> AdjacencyMap a -> Set a
forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.preSet
postSet :: Ord a => a -> AdjacencyMap a -> Set a
postSet :: a -> AdjacencyMap a -> Set a
postSet = (a -> AdjacencyMap a -> Set a) -> a -> AdjacencyMap a -> Set a
coerce a -> AdjacencyMap a -> Set a
forall a. Ord a => a -> AdjacencyMap a -> Set a
AM.postSet
removeVertex :: Ord a => a -> AdjacencyMap a -> AdjacencyMap a
removeVertex :: a -> AdjacencyMap a -> AdjacencyMap a
removeVertex = (a -> AdjacencyMap a -> AdjacencyMap a)
-> a -> AdjacencyMap a -> AdjacencyMap a
coerce a -> AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => a -> AdjacencyMap a -> AdjacencyMap a
AM.removeVertex
removeEdge :: Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
removeEdge :: a -> a -> AdjacencyMap a -> AdjacencyMap a
removeEdge = (a -> a -> AdjacencyMap a -> AdjacencyMap a)
-> a -> a -> AdjacencyMap a -> AdjacencyMap a
coerce a -> a -> AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => a -> a -> AdjacencyMap a -> AdjacencyMap a
AM.removeEdge
transpose :: Ord a => AdjacencyMap a -> AdjacencyMap a
transpose :: AdjacencyMap a -> AdjacencyMap a
transpose = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transpose
induce :: (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
induce :: (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
induce = ((a -> Bool) -> AdjacencyMap a -> AdjacencyMap a)
-> (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
coerce (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
forall a. (a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
AM.induce
induceJust :: Ord a => AdjacencyMap (Maybe a) -> AdjacencyMap a
induceJust :: AdjacencyMap (Maybe a) -> AdjacencyMap a
induceJust = (AdjacencyMap (Maybe a) -> AdjacencyMap a)
-> AdjacencyMap (Maybe a) -> AdjacencyMap a
coerce AdjacencyMap (Maybe a) -> AdjacencyMap a
forall a. Ord a => AdjacencyMap (Maybe a) -> AdjacencyMap a
AM.induceJust
box :: (Ord a, Ord b) => AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
box :: AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
box = (AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b))
-> AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
coerce AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
forall a b.
(Ord a, Ord b) =>
AdjacencyMap a -> AdjacencyMap b -> AdjacencyMap (a, b)
AM.box
transitiveClosure :: Ord a => AdjacencyMap a -> AdjacencyMap a
transitiveClosure :: AdjacencyMap a -> AdjacencyMap a
transitiveClosure = (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a -> AdjacencyMap a
forall a. Ord a => AdjacencyMap a -> AdjacencyMap a
AM.transitiveClosure
topSort :: Ord a => AdjacencyMap a -> [a]
topSort :: AdjacencyMap a -> [a]
topSort AdjacencyMap a
g = case AdjacencyMap a -> Either (Cycle a) [a]
forall a. Ord a => AdjacencyMap a -> Either (Cycle a) [a]
AM.topSort (AdjacencyMap a -> AdjacencyMap a
coerce AdjacencyMap a
g) of
Right [a]
vs -> [a]
vs
Left Cycle a
_ -> String -> [a]
forall a. HasCallStack => String -> a
error String
"Internal error: the acyclicity invariant is violated in topSort"
scc :: (Ord a) => AM.AdjacencyMap a -> AdjacencyMap (NAM.AdjacencyMap a)
scc :: AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
scc = (AdjacencyMap a -> AdjacencyMap (AdjacencyMap a))
-> AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
coerce AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
forall a. Ord a => AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
AM.scc
toAcyclic :: Ord a => AM.AdjacencyMap a -> Maybe (AdjacencyMap a)
toAcyclic :: AdjacencyMap a -> Maybe (AdjacencyMap a)
toAcyclic AdjacencyMap a
x = if AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> Bool
AM.isAcyclic AdjacencyMap a
x then AdjacencyMap a -> Maybe (AdjacencyMap a)
forall a. a -> Maybe a
Just (AdjacencyMap a -> AdjacencyMap a
forall a. AdjacencyMap a -> AdjacencyMap a
AAM AdjacencyMap a
x) else Maybe (AdjacencyMap a)
forall a. Maybe a
Nothing
toAcyclicOrd :: Ord a => AM.AdjacencyMap a -> AdjacencyMap a
toAcyclicOrd :: AdjacencyMap a -> AdjacencyMap a
toAcyclicOrd = AdjacencyMap a -> AdjacencyMap a
forall a. AdjacencyMap a -> AdjacencyMap a
AAM (AdjacencyMap a -> AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
forall a.
Ord a =>
(a -> a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
filterEdges a -> a -> Bool
forall a. Ord a => a -> a -> Bool
(<)
shrink :: Ord a => AM.AdjacencyMap a -> AdjacencyMap a
shrink :: AdjacencyMap a -> AdjacencyMap a
shrink = AdjacencyMap a -> AdjacencyMap a
forall a. AdjacencyMap a -> AdjacencyMap a
AAM (AdjacencyMap a -> AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap a)
-> AdjacencyMap a
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AdjacencyMap a -> a)
-> AdjacencyMap (AdjacencyMap a) -> AdjacencyMap a
forall a b.
(Ord a, Ord b) =>
(a -> b) -> AdjacencyMap a -> AdjacencyMap b
AM.gmap (NonEmpty a -> a
forall a. NonEmpty a -> a
NonEmpty.head (NonEmpty a -> a)
-> (AdjacencyMap a -> NonEmpty a) -> AdjacencyMap a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyMap a -> NonEmpty a
forall a. AdjacencyMap a -> NonEmpty a
NAM.vertexList1) (AdjacencyMap (AdjacencyMap a) -> AdjacencyMap a)
-> (AdjacencyMap a -> AdjacencyMap (AdjacencyMap a))
-> AdjacencyMap a
-> AdjacencyMap a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
forall a. Ord a => AdjacencyMap a -> AdjacencyMap (AdjacencyMap a)
AM.scc
filterEdges :: Ord a => (a -> a -> Bool) -> AM.AdjacencyMap a -> AM.AdjacencyMap a
filterEdges :: (a -> a -> Bool) -> AdjacencyMap a -> AdjacencyMap a
filterEdges a -> a -> Bool
p AdjacencyMap a
m = [(a, Set a)] -> AdjacencyMap a
forall a. Ord a => [(a, Set a)] -> AdjacencyMap a
AM.fromAdjacencySets
[ (a
a, (a -> Bool) -> Set a -> Set a
forall a. (a -> Bool) -> Set a -> Set a
Set.filter (a -> a -> Bool
p a
a) Set a
bs) | (a
a, Set a
bs) <- Map a (Set a) -> [(a, Set a)]
forall k a. Map k a -> [(k, a)]
Map.toList (AdjacencyMap a -> Map a (Set a)
forall a. AdjacencyMap a -> Map a (Set a)
AM.adjacencyMap AdjacencyMap a
m) ]
consistent :: Ord a => AdjacencyMap a -> Bool
consistent :: AdjacencyMap a -> Bool
consistent (AAM AdjacencyMap a
m) = AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> Bool
AM.consistent AdjacencyMap a
m Bool -> Bool -> Bool
&& AdjacencyMap a -> Bool
forall a. Ord a => AdjacencyMap a -> Bool
AM.isAcyclic AdjacencyMap a
m