The ToGraph type class captures data types that can be converted to algebraic graphs. Instances of this type class should satisfy the laws specified by the default method definitions.
Associated types
type family ToVertex tThe type of vertices of the resulting graph.
Methods
toGraph :: t -> Graph (ToVertex t)foldg :: r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> rThe method foldg is used for generalised graph folding. It collapses a given value by applying the provided graph construction primitives. The order of arguments is: empty, vertex, overlay and connect, and it is assumed that the arguments satisfy the axioms of the graph algebra.
foldg == Algebra.Graph.foldg . toGraphisEmpty :: t -> BoolhasVertex :: Eq (ToVertex t) => ToVertex t -> t -> BoolCheck if a graph contains a given vertex.
hasVertex x == foldg False (==x) (||) (||)hasEdge :: Eq (ToVertex t) => ToVertex t -> ToVertex t -> t -> BoolvertexCount :: Ord (ToVertex t) => t -> IntedgeCount :: Ord (ToVertex t) => t -> IntvertexList :: Ord (ToVertex t) => t -> [ToVertex t]edgeList :: Ord (ToVertex t) => t -> [(ToVertex t, ToVertex t)]vertexSet :: Ord (ToVertex t) => t -> Set (ToVertex t)vertexIntSet :: ToVertex t ~ Int => t -> IntSetedgeSet :: Ord (ToVertex t) => t -> Set (ToVertex t, ToVertex t)The set of edges of a graph.
edgeSet == Algebra.Graph.AdjacencyMap.edgeSet . toAdjacencyMappreSet :: Ord (ToVertex t) => ToVertex t -> t -> Set (ToVertex t)The preset of a vertex is the set of its direct predecessors.
preSet x == Algebra.Graph.AdjacencyMap.preSet x . toAdjacencyMappreIntSet :: ToVertex t ~ Int => Int -> t -> IntSetThe preset (here
preIntSet) of a vertex is the set of its direct predecessors. Like preSet but specialised for graphs with vertices of type Int.preIntSet x == Algebra.Graph.AdjacencyIntMap.preIntSet x . toAdjacencyIntMappostSet :: Ord (ToVertex t) => ToVertex t -> t -> Set (ToVertex t)The postset of a vertex is the set of its direct successors.
postSet x == Algebra.Graph.AdjacencyMap.postSet x . toAdjacencyMappostIntSet :: ToVertex t ~ Int => Int -> t -> IntSetThe postset (here
postIntSet) of a vertex is the set of its direct successors. Like postSet but specialised for graphs with vertices of type Int.postIntSet x == Algebra.Graph.AdjacencyIntMap.postIntSet x . toAdjacencyIntMapadjacencyList :: Ord (ToVertex t) => t -> [(ToVertex t, [ToVertex t])]The sorted adjacency list of a graph.
adjacencyList == Algebra.Graph.AdjacencyMap.adjacencyList . toAdjacencyMapdfsForest :: Ord (ToVertex t) => t -> Forest (ToVertex t)dfsForestFrom :: Ord (ToVertex t) => t -> [ToVertex t] -> Forest (ToVertex t)Compute the depth-first search forest of a graph, searching from each of the given vertices in order. Note that the resulting forest does not necessarily span the whole graph, as some vertices may be unreachable.
dfsForestFrom == Algebra.Graph.AdjacencyMap.dfsForestFrom . toAdjacencyMapdfs :: Ord (ToVertex t) => t -> [ToVertex t] -> [ToVertex t]Compute the list of vertices visited by the depth-first search in a graph, when searching from each of the given vertices in order.
dfs == Algebra.Graph.AdjacencyMap.dfs . toAdjacencyMapreachable :: Ord (ToVertex t) => t -> ToVertex t -> [ToVertex t]Compute the list of vertices that are reachable from a given source vertex in a graph. The vertices in the resulting list appear in the depth-first order.
reachable == Algebra.Graph.AdjacencyMap.reachable . toAdjacencyMaptopSort :: Ord (ToVertex t) => t -> Either (Cycle (ToVertex t)) [ToVertex t]Compute the topological sort of a graph or a
AM.Cycleif the graph is cyclic.topSort == Algebra.Graph.AdjacencyMap.topSort . toAdjacencyMapisAcyclic :: Ord (ToVertex t) => t -> BoolCheck if a given graph is acyclic.
isAcyclic == Algebra.Graph.AdjacencyMap.isAcyclic . toAdjacencyMaptoAdjacencyMap :: Ord (ToVertex t) => t -> AdjacencyMap (ToVertex t)toAdjacencyMapTranspose :: Ord (ToVertex t) => t -> AdjacencyMap (ToVertex t)toAdjacencyIntMap :: ToVertex t ~ Int => t -> AdjacencyIntMaptoAdjacencyIntMapTranspose :: ToVertex t ~ Int => t -> AdjacencyIntMapisDfsForestOf :: Ord (ToVertex t) => Forest (ToVertex t) -> t -> BoolCheck if a given forest is a valid depth-first search forest of a graph.
isDfsForestOf f == Algebra.Graph.AdjacencyMap.isDfsForestOf f . toAdjacencyMapisTopSortOf :: Ord (ToVertex t) => [ToVertex t] -> t -> BoolCheck if a given list of vertices is a valid topological sort of a graph.
isTopSortOf vs == Algebra.Graph.AdjacencyMap.isTopSortOf vs . toAdjacencyMap
Instances9ToGraph, …
ToGraph AdjacencyIntMapDefined in algebraic-graphs-0.8 · Algebra.Graph.ToGraphToGraph (Graph a)Defined in algebraic-graphs-0.8 · Algebra.Graph.NonEmptyOrd a => ToGraph (Graph a)Defined in algebraic-graphs-0.8 · Algebra.Graph.ToGraphSee Algebra.Graph.
Ord a => ToGraph (AdjacencyMap a)Defined in algebraic-graphs-0.8 · Algebra.Graph.ToGraphOrd a => ToGraph (AdjacencyMap a)Defined in algebraic-graphs-0.8 · Algebra.Graph.ToGraphOrd a => ToGraph (Relation a)Defined in algebraic-graphs-0.8 · Algebra.Graph.RelationOrd a => ToGraph (Relation a)Defined in algebraic-graphs-0.8 · Algebra.Graph.Relation.SymmetricDefined via fromSymmetric and the ToGraph instance of Relation.
(Eq e, Monoid e, Ord a) => ToGraph (Graph e a)Defined in algebraic-graphs-0.8 · Algebra.Graph.Labelled(Eq e, Monoid e, Ord a) => ToGraph (AdjacencyMap e a)Defined in algebraic-graphs-0.8 · Algebra.Graph.Labelled.AdjacencyMapDefined via skeleton and the ToGraph instance of AdjacencyMap.