algebraic-graphs-0.7: A library for algebraic graph construction and transformation

Copyright | (c) Andrey Mokhov 2016-2022
License | MIT (see the file LICENSE)
Maintainer | andrey.mokhov@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Algebra.Graph.ToGraph

Contents

- Type class
- Derived functions

Description

Alga is a library for algebraic construction and manipulation of graphs in Haskell. See this paper for the motivation behind the library, the underlying theory, and implementation details.

This module defines the type class `ToGraph` for capturing data types that can be converted to algebraic graphs. To make an instance of this class you need to define just a single method (`toGraph` or `foldg`), which gives you access to many other useful methods for free (although note that the default implementations may be suboptimal performance-wise).

This type class is similar to the standard type class `Foldable` defined for lists. Furthermore, one can define `Foldable` methods `foldMap` and `toList` using `ToGraph`.`foldg`:

    foldMap f = foldg mempty f    (<>) (<>)
    toList    = foldg []     pure (++) (++)

However, the resulting `Foldable` instance is problematic. For example, folding equivalent algebraic graphs `1` and `1` + `1` leads to different results:

    toList (1    ) == [1]
    toList (1 + 1) == [1, 1]

To avoid such cases, we do not provide `Foldable` instances for algebraic graph datatypes. Furthermore, we require that the four arguments passed to `foldg` satisfy the laws of the algebra of graphs. The above definitions of `foldMap` and `toList` violate this requirement, for example `[1] ++ [1] /= [1]`, and are therefore disallowed.

Synopsis

- class ToGraph t where
  - type ToVertex t
  - toGraph :: t -> Graph (ToVertex t)
  - foldg :: r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r
  - isEmpty :: t -> Bool
  - hasVertex :: ToVertex t -> t -> Bool
  - hasEdge :: ToVertex t -> ToVertex t -> t -> Bool
  - vertexCount :: t -> Int
  - edgeCount :: t -> Int
  - vertexList :: t -> [ToVertex t]
  - edgeList :: t -> [(ToVertex t, ToVertex t)]
  - vertexSet :: t -> Set (ToVertex t)
  - vertexIntSet :: t -> IntSet
  - edgeSet :: t -> Set (ToVertex t, ToVertex t)
  - preSet :: ToVertex t -> t -> Set (ToVertex t)
  - preIntSet :: Int -> t -> IntSet
  - postSet :: ToVertex t -> t -> Set (ToVertex t)
  - postIntSet :: Int -> t -> IntSet
  - adjacencyList :: t -> [(ToVertex t, [ToVertex t])]
  - dfsForest :: t -> Forest (ToVertex t)
  - dfsForestFrom :: t -> [ToVertex t] -> Forest (ToVertex t)
  - dfs :: t -> [ToVertex t] -> [ToVertex t]
  - reachable :: t -> ToVertex t -> [ToVertex t]
  - topSort :: t -> Either (Cycle (ToVertex t)) [ToVertex t]
  - isAcyclic :: t -> Bool
  - toAdjacencyMap :: t -> AdjacencyMap (ToVertex t)
  - toAdjacencyMapTranspose :: t -> AdjacencyMap (ToVertex t)
  - toAdjacencyIntMap :: t -> AdjacencyIntMap
  - toAdjacencyIntMapTranspose :: t -> AdjacencyIntMap
  - isDfsForestOf :: Forest (ToVertex t) -> t -> Bool
  - isTopSortOf :: [ToVertex t] -> t -> Bool
- adjacencyMap :: (ToGraph t, Ord (ToVertex t)) => t -> Map (ToVertex t) (Set (ToVertex t))
- adjacencyIntMap :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet
- adjacencyMapTranspose :: (ToGraph t, Ord (ToVertex t)) => t -> Map (ToVertex t) (Set (ToVertex t))
- adjacencyIntMapTranspose :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet

# Type class

class ToGraph t where #

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.

Minimal complete definition

toGraph | foldg

Associated Types

type ToVertex t #

The type of vertices of the resulting graph.

Methods

toGraph :: t -> Graph (ToVertex t) #

Convert a value to the corresponding algebraic graph, see Algebra.Graph.

    toGraph == foldg Empty Vertex Overlay Connect

foldg :: r -> (ToVertex t -> r) -> (r -> r -> r) -> (r -> r -> r) -> t -> r #

The 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 . toGraph

isEmpty :: t -> Bool #

Check if a graph is empty.

    isEmpty == foldg True (const False) (&&) (&&)

hasVertex :: ToVertex t -> t -> Bool #

Check if a graph contains a given vertex.

    hasVertex x == foldg False (==x) (||) (||)

hasEdge :: ToVertex t -> ToVertex t -> t -> Bool #

Check if a graph contains a given edge.

    hasEdge x y == Algebra.Graph.hasEdge x y . toGraph

vertexCount :: t -> Int #

The number of vertices in a graph.

    vertexCount == Set.size . vertexSet

edgeCount :: t -> Int #

The number of edges in a graph.

    edgeCount == Set.size . edgeSet

vertexList :: t -> [ToVertex t] #

The sorted list of vertices of a given graph.

    vertexList == Set.toAscList . vertexSet

edgeList :: t -> [(ToVertex t, ToVertex t)] #

The sorted list of edges of a graph.

    edgeList == Set.toAscList . edgeSet

vertexSet :: t -> Set (ToVertex t) #

The set of vertices of a graph.

    vertexSet == foldg Set.empty Set.singleton Set.union Set.union

vertexIntSet :: t -> IntSet #

The set of vertices of a graph. Like `vertexSet` but specialised for graphs with vertices of type `Int`.

    vertexIntSet == foldg IntSet.empty IntSet.singleton IntSet.union IntSet.union

edgeSet :: t -> Set (ToVertex t, ToVertex t) #

The set of edges of a graph.

    edgeSet == Algebra.Graph.AdjacencyMap.edgeSet . toAdjacencyMap

preSet :: 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 . toAdjacencyMap

preIntSet :: Int -> t -> IntSet #

The 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 . toAdjacencyIntMap

postSet :: 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 . toAdjacencyMap

postIntSet :: Int -> t -> IntSet #

The 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 . toAdjacencyIntMap

adjacencyList :: t -> [(ToVertex t, [ToVertex t])] #

The sorted adjacency list of a graph.

    adjacencyList == Algebra.Graph.AdjacencyMap.adjacencyList . toAdjacencyMap

dfsForest :: t -> Forest (ToVertex t) #

Compute the depth-first search forest of a graph that corresponds to searching from each of the graph vertices in the `Ord` `a` order.

    dfsForest == Algebra.Graph.AdjacencyMap.dfsForest . toAdjacencyMap

dfsForestFrom :: 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 . toAdjacencyMap

dfs :: 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 . toAdjacencyMap

reachable :: 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 . toAdjacencyMap

topSort :: t -> Either (Cycle (ToVertex t)) [ToVertex t] #

Compute the topological sort of a graph or a `AM.Cycle` if the graph is cyclic.

    topSort == Algebra.Graph.AdjacencyMap.topSort . toAdjacencyMap

isAcyclic :: t -> Bool #

Check if a given graph is acyclic.

    isAcyclic == Algebra.Graph.AdjacencyMap.isAcyclic . toAdjacencyMap

toAdjacencyMap :: t -> AdjacencyMap (ToVertex t) #

Convert a value to the corresponding `AdjacencyMap`.

    toAdjacencyMap == foldg empty vertex overlay connect

toAdjacencyMapTranspose :: t -> AdjacencyMap (ToVertex t) #

Convert a value to the corresponding `AdjacencyMap` and transpose the result.

    toAdjacencyMapTranspose == foldg empty vertex overlay (flip connect)

toAdjacencyIntMap :: t -> AdjacencyIntMap #

Convert a value to the corresponding `AdjacencyIntMap`.

    toAdjacencyIntMap == foldg empty vertex overlay connect

toAdjacencyIntMapTranspose :: t -> AdjacencyIntMap #

Convert a value to the corresponding `AdjacencyIntMap` and transpose the result.

    toAdjacencyIntMapTranspose == foldg empty vertex overlay (flip connect)

isDfsForestOf :: Forest (ToVertex t) -> t -> Bool #

Check if a given forest is a valid depth-first search forest of a graph.

    isDfsForestOf f == Algebra.Graph.AdjacencyMap.isDfsForestOf f . toAdjacencyMap

isTopSortOf :: [ToVertex t] -> t -> Bool #

Check if a given list of vertices is a valid topological sort of a graph.

    isTopSortOf vs == Algebra.Graph.AdjacencyMap.isTopSortOf vs . toAdjacencyMap

#### Instances

Instances details

ToGraph AdjacencyIntMap # | See Algebra.Graph.AdjacencyIntMap.
Instance details Defined in Algebra.Graph.ToGraph Associated Types
type ToVertex AdjacencyIntMap |
Instance details Defined in Algebra.Graph.ToGraph type ToVertex AdjacencyIntMap = Int
Methods toGraph :: AdjacencyIntMap -> Graph (ToVertex AdjacencyIntMap) # foldg :: r -> (ToVertex AdjacencyIntMap -> r) -> (r -> r -> r) -> (r -> r -> r) -> AdjacencyIntMap -> r # isEmpty :: AdjacencyIntMap -> Bool # hasVertex :: ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Bool # hasEdge :: ToVertex AdjacencyIntMap -> ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Bool # vertexCount :: AdjacencyIntMap -> Int # edgeCount :: AdjacencyIntMap -> Int # vertexList :: AdjacencyIntMap -> [ToVertex AdjacencyIntMap] # edgeList :: AdjacencyIntMap -> [(ToVertex AdjacencyIntMap, ToVertex AdjacencyIntMap)] # vertexSet :: AdjacencyIntMap -> Set (ToVertex AdjacencyIntMap) # vertexIntSet :: AdjacencyIntMap -> IntSet # edgeSet :: AdjacencyIntMap -> Set (ToVertex AdjacencyIntMap, ToVertex AdjacencyIntMap) # preSet :: ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Set (ToVertex AdjacencyIntMap) # preIntSet :: Int -> AdjacencyIntMap -> IntSet # postSet :: ToVertex AdjacencyIntMap -> AdjacencyIntMap -> Set (ToVertex AdjacencyIntMap) # postIntSet :: Int -> AdjacencyIntMap -> IntSet # adjacencyList :: AdjacencyIntMap -> [(ToVertex AdjacencyIntMap, [ToVertex AdjacencyIntMap])] # dfsForest :: AdjacencyIntMap -> Forest (ToVertex AdjacencyIntMap) # dfsForestFrom :: AdjacencyIntMap -> [ToVertex AdjacencyIntMap] -> Forest (ToVertex AdjacencyIntMap) # dfs :: AdjacencyIntMap -> [ToVertex AdjacencyIntMap] -> [ToVertex AdjacencyIntMap] # reachable :: AdjacencyIntMap -> ToVertex AdjacencyIntMap -> [ToVertex AdjacencyIntMap] # topSort :: AdjacencyIntMap -> Either (Cycle (ToVertex AdjacencyIntMap)) [ToVertex AdjacencyIntMap] # isAcyclic :: AdjacencyIntMap -> Bool # toAdjacencyMap :: AdjacencyIntMap -> AdjacencyMap (ToVertex AdjacencyIntMap) # toAdjacencyMapTranspose :: AdjacencyIntMap -> AdjacencyMap (ToVertex AdjacencyIntMap) # toAdjacencyIntMap :: AdjacencyIntMap -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: AdjacencyIntMap -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex AdjacencyIntMap) -> AdjacencyIntMap -> Bool # isTopSortOf :: [ToVertex AdjacencyIntMap] -> AdjacencyIntMap -> Bool #
Ord a => ToGraph (Graph a) # | See Algebra.Graph.
Instance details Defined in Algebra.Graph.ToGraph Associated Types
type ToVertex (Graph a) |
Instance details Defined in Algebra.Graph.ToGraph type ToVertex (Graph a) = a
Methods toGraph :: Graph a -> Graph (ToVertex (Graph a)) # foldg :: r -> (ToVertex (Graph a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> Graph a -> r # isEmpty :: Graph a -> Bool # hasVertex :: ToVertex (Graph a) -> Graph a -> Bool # hasEdge :: ToVertex (Graph a) -> ToVertex (Graph a) -> Graph a -> Bool # vertexCount :: Graph a -> Int # edgeCount :: Graph a -> Int # vertexList :: Graph a -> [ToVertex (Graph a)] # edgeList :: Graph a -> [(ToVertex (Graph a), ToVertex (Graph a))] # vertexSet :: Graph a -> Set (ToVertex (Graph a)) # vertexIntSet :: Graph a -> IntSet # edgeSet :: Graph a -> Set (ToVertex (Graph a), ToVertex (Graph a)) # preSet :: ToVertex (Graph a) -> Graph a -> Set (ToVertex (Graph a)) # preIntSet :: Int -> Graph a -> IntSet # postSet :: ToVertex (Graph a) -> Graph a -> Set (ToVertex (Graph a)) # postIntSet :: Int -> Graph a -> IntSet # adjacencyList :: Graph a -> [(ToVertex (Graph a), [ToVertex (Graph a)])] # dfsForest :: Graph a -> Forest (ToVertex (Graph a)) # dfsForestFrom :: Graph a -> [ToVertex (Graph a)] -> Forest (ToVertex (Graph a)) # dfs :: Graph a -> [ToVertex (Graph a)] -> [ToVertex (Graph a)] # reachable :: Graph a -> ToVertex (Graph a) -> [ToVertex (Graph a)] # topSort :: Graph a -> Either (Cycle (ToVertex (Graph a))) [ToVertex (Graph a)] # isAcyclic :: Graph a -> Bool # toAdjacencyMap :: Graph a -> AdjacencyMap (ToVertex (Graph a)) # toAdjacencyMapTranspose :: Graph a -> AdjacencyMap (ToVertex (Graph a)) # toAdjacencyIntMap :: Graph a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: Graph a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (Graph a)) -> Graph a -> Bool # isTopSortOf :: [ToVertex (Graph a)] -> Graph a -> Bool #
Ord a => ToGraph (AdjacencyMap a) # | See Algebra.Graph.AdjacencyMap.
Instance details Defined in Algebra.Graph.ToGraph Associated Types
type ToVertex (AdjacencyMap a) |
Instance details Defined in Algebra.Graph.ToGraph type ToVertex (AdjacencyMap a) = a
Methods toGraph :: AdjacencyMap a -> Graph (ToVertex (AdjacencyMap a)) # foldg :: r -> (ToVertex (AdjacencyMap a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> AdjacencyMap a -> r # isEmpty :: AdjacencyMap a -> Bool # hasVertex :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool # hasEdge :: ToVertex (AdjacencyMap a) -> ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool # vertexCount :: AdjacencyMap a -> Int # edgeCount :: AdjacencyMap a -> Int # vertexList :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] # edgeList :: AdjacencyMap a -> [(ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))] # vertexSet :: AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # vertexIntSet :: AdjacencyMap a -> IntSet # edgeSet :: AdjacencyMap a -> Set (ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a)) # preSet :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # preIntSet :: Int -> AdjacencyMap a -> IntSet # postSet :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # postIntSet :: Int -> AdjacencyMap a -> IntSet # adjacencyList :: AdjacencyMap a -> [(ToVertex (AdjacencyMap a), [ToVertex (AdjacencyMap a)])] # dfsForest :: AdjacencyMap a -> Forest (ToVertex (AdjacencyMap a)) # dfsForestFrom :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] -> Forest (ToVertex (AdjacencyMap a)) # dfs :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] -> [ToVertex (AdjacencyMap a)] # reachable :: AdjacencyMap a -> ToVertex (AdjacencyMap a) -> [ToVertex (AdjacencyMap a)] # topSort :: AdjacencyMap a -> Either (Cycle (ToVertex (AdjacencyMap a))) [ToVertex (AdjacencyMap a)] # isAcyclic :: AdjacencyMap a -> Bool # toAdjacencyMap :: AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a)) # toAdjacencyMapTranspose :: AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a)) # toAdjacencyIntMap :: AdjacencyMap a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: AdjacencyMap a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (AdjacencyMap a)) -> AdjacencyMap a -> Bool # isTopSortOf :: [ToVertex (AdjacencyMap a)] -> AdjacencyMap a -> Bool #
ToGraph (Graph a) # |
Instance details Defined in Algebra.Graph.NonEmpty Associated Types
type ToVertex (Graph a) |
Instance details Defined in Algebra.Graph.NonEmpty type ToVertex (Graph a) = a
Methods toGraph :: Graph a -> Graph (ToVertex (Graph a)) # foldg :: r -> (ToVertex (Graph a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> Graph a -> r # isEmpty :: Graph a -> Bool # hasVertex :: ToVertex (Graph a) -> Graph a -> Bool # hasEdge :: ToVertex (Graph a) -> ToVertex (Graph a) -> Graph a -> Bool # vertexCount :: Graph a -> Int # edgeCount :: Graph a -> Int # vertexList :: Graph a -> [ToVertex (Graph a)] # edgeList :: Graph a -> [(ToVertex (Graph a), ToVertex (Graph a))] # vertexSet :: Graph a -> Set (ToVertex (Graph a)) # vertexIntSet :: Graph a -> IntSet # edgeSet :: Graph a -> Set (ToVertex (Graph a), ToVertex (Graph a)) # preSet :: ToVertex (Graph a) -> Graph a -> Set (ToVertex (Graph a)) # preIntSet :: Int -> Graph a -> IntSet # postSet :: ToVertex (Graph a) -> Graph a -> Set (ToVertex (Graph a)) # postIntSet :: Int -> Graph a -> IntSet # adjacencyList :: Graph a -> [(ToVertex (Graph a), [ToVertex (Graph a)])] # dfsForest :: Graph a -> Forest (ToVertex (Graph a)) # dfsForestFrom :: Graph a -> [ToVertex (Graph a)] -> Forest (ToVertex (Graph a)) # dfs :: Graph a -> [ToVertex (Graph a)] -> [ToVertex (Graph a)] # reachable :: Graph a -> ToVertex (Graph a) -> [ToVertex (Graph a)] # topSort :: Graph a -> Either (Cycle (ToVertex (Graph a))) [ToVertex (Graph a)] # isAcyclic :: Graph a -> Bool # toAdjacencyMap :: Graph a -> AdjacencyMap (ToVertex (Graph a)) # toAdjacencyMapTranspose :: Graph a -> AdjacencyMap (ToVertex (Graph a)) # toAdjacencyIntMap :: Graph a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: Graph a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (Graph a)) -> Graph a -> Bool # isTopSortOf :: [ToVertex (Graph a)] -> Graph a -> Bool #
Ord a => ToGraph (AdjacencyMap a) # | See Algebra.Graph.NonEmpty.AdjacencyMap.
Instance details Defined in Algebra.Graph.ToGraph Associated Types
type ToVertex (AdjacencyMap a) |
Instance details Defined in Algebra.Graph.ToGraph type ToVertex (AdjacencyMap a) = a
Methods toGraph :: AdjacencyMap a -> Graph (ToVertex (AdjacencyMap a)) # foldg :: r -> (ToVertex (AdjacencyMap a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> AdjacencyMap a -> r # isEmpty :: AdjacencyMap a -> Bool # hasVertex :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool # hasEdge :: ToVertex (AdjacencyMap a) -> ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Bool # vertexCount :: AdjacencyMap a -> Int # edgeCount :: AdjacencyMap a -> Int # vertexList :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] # edgeList :: AdjacencyMap a -> [(ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a))] # vertexSet :: AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # vertexIntSet :: AdjacencyMap a -> IntSet # edgeSet :: AdjacencyMap a -> Set (ToVertex (AdjacencyMap a), ToVertex (AdjacencyMap a)) # preSet :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # preIntSet :: Int -> AdjacencyMap a -> IntSet # postSet :: ToVertex (AdjacencyMap a) -> AdjacencyMap a -> Set (ToVertex (AdjacencyMap a)) # postIntSet :: Int -> AdjacencyMap a -> IntSet # adjacencyList :: AdjacencyMap a -> [(ToVertex (AdjacencyMap a), [ToVertex (AdjacencyMap a)])] # dfsForest :: AdjacencyMap a -> Forest (ToVertex (AdjacencyMap a)) # dfsForestFrom :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] -> Forest (ToVertex (AdjacencyMap a)) # dfs :: AdjacencyMap a -> [ToVertex (AdjacencyMap a)] -> [ToVertex (AdjacencyMap a)] # reachable :: AdjacencyMap a -> ToVertex (AdjacencyMap a) -> [ToVertex (AdjacencyMap a)] # topSort :: AdjacencyMap a -> Either (Cycle (ToVertex (AdjacencyMap a))) [ToVertex (AdjacencyMap a)] # isAcyclic :: AdjacencyMap a -> Bool # toAdjacencyMap :: AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a)) # toAdjacencyMapTranspose :: AdjacencyMap a -> AdjacencyMap (ToVertex (AdjacencyMap a)) # toAdjacencyIntMap :: AdjacencyMap a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: AdjacencyMap a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (AdjacencyMap a)) -> AdjacencyMap a -> Bool # isTopSortOf :: [ToVertex (AdjacencyMap a)] -> AdjacencyMap a -> Bool #
Ord a => ToGraph (Relation a) # |
Instance details Defined in Algebra.Graph.Relation Associated Types
type ToVertex (Relation a) |
Instance details Defined in Algebra.Graph.Relation type ToVertex (Relation a) = a
Methods toGraph :: Relation a -> Graph (ToVertex (Relation a)) # foldg :: r -> (ToVertex (Relation a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> Relation a -> r # isEmpty :: Relation a -> Bool # hasVertex :: ToVertex (Relation a) -> Relation a -> Bool # hasEdge :: ToVertex (Relation a) -> ToVertex (Relation a) -> Relation a -> Bool # vertexCount :: Relation a -> Int # edgeCount :: Relation a -> Int # vertexList :: Relation a -> [ToVertex (Relation a)] # edgeList :: Relation a -> [(ToVertex (Relation a), ToVertex (Relation a))] # vertexSet :: Relation a -> Set (ToVertex (Relation a)) # vertexIntSet :: Relation a -> IntSet # edgeSet :: Relation a -> Set (ToVertex (Relation a), ToVertex (Relation a)) # preSet :: ToVertex (Relation a) -> Relation a -> Set (ToVertex (Relation a)) # preIntSet :: Int -> Relation a -> IntSet # postSet :: ToVertex (Relation a) -> Relation a -> Set (ToVertex (Relation a)) # postIntSet :: Int -> Relation a -> IntSet # adjacencyList :: Relation a -> [(ToVertex (Relation a), [ToVertex (Relation a)])] # dfsForest :: Relation a -> Forest (ToVertex (Relation a)) # dfsForestFrom :: Relation a -> [ToVertex (Relation a)] -> Forest (ToVertex (Relation a)) # dfs :: Relation a -> [ToVertex (Relation a)] -> [ToVertex (Relation a)] # reachable :: Relation a -> ToVertex (Relation a) -> [ToVertex (Relation a)] # topSort :: Relation a -> Either (Cycle (ToVertex (Relation a))) [ToVertex (Relation a)] # isAcyclic :: Relation a -> Bool # toAdjacencyMap :: Relation a -> AdjacencyMap (ToVertex (Relation a)) # toAdjacencyMapTranspose :: Relation a -> AdjacencyMap (ToVertex (Relation a)) # toAdjacencyIntMap :: Relation a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: Relation a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (Relation a)) -> Relation a -> Bool # isTopSortOf :: [ToVertex (Relation a)] -> Relation a -> Bool #
Ord a => ToGraph (Relation a) # | Defined via `fromSymmetric` and the `ToGraph` instance of `Relation`.
Instance details Defined in Algebra.Graph.Relation.Symmetric Associated Types
type ToVertex (Relation a) |
Instance details Defined in Algebra.Graph.Relation.Symmetric type ToVertex (Relation a) = a
Methods toGraph :: Relation a -> Graph (ToVertex (Relation a)) # foldg :: r -> (ToVertex (Relation a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> Relation a -> r # isEmpty :: Relation a -> Bool # hasVertex :: ToVertex (Relation a) -> Relation a -> Bool # hasEdge :: ToVertex (Relation a) -> ToVertex (Relation a) -> Relation a -> Bool # vertexCount :: Relation a -> Int # edgeCount :: Relation a -> Int # vertexList :: Relation a -> [ToVertex (Relation a)] # edgeList :: Relation a -> [(ToVertex (Relation a), ToVertex (Relation a))] # vertexSet :: Relation a -> Set (ToVertex (Relation a)) # vertexIntSet :: Relation a -> IntSet # edgeSet :: Relation a -> Set (ToVertex (Relation a), ToVertex (Relation a)) # preSet :: ToVertex (Relation a) -> Relation a -> Set (ToVertex (Relation a)) # preIntSet :: Int -> Relation a -> IntSet # postSet :: ToVertex (Relation a) -> Relation a -> Set (ToVertex (Relation a)) # postIntSet :: Int -> Relation a -> IntSet # adjacencyList :: Relation a -> [(ToVertex (Relation a), [ToVertex (Relation a)])] # dfsForest :: Relation a -> Forest (ToVertex (Relation a)) # dfsForestFrom :: Relation a -> [ToVertex (Relation a)] -> Forest (ToVertex (Relation a)) # dfs :: Relation a -> [ToVertex (Relation a)] -> [ToVertex (Relation a)] # reachable :: Relation a -> ToVertex (Relation a) -> [ToVertex (Relation a)] # topSort :: Relation a -> Either (Cycle (ToVertex (Relation a))) [ToVertex (Relation a)] # isAcyclic :: Relation a -> Bool # toAdjacencyMap :: Relation a -> AdjacencyMap (ToVertex (Relation a)) # toAdjacencyMapTranspose :: Relation a -> AdjacencyMap (ToVertex (Relation a)) # toAdjacencyIntMap :: Relation a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: Relation a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (Relation a)) -> Relation a -> Bool # isTopSortOf :: [ToVertex (Relation a)] -> Relation a -> Bool #
(Eq e, Monoid e, Ord a) => ToGraph (Graph e a) # |
Instance details Defined in Algebra.Graph.Labelled Associated Types
type ToVertex (Graph e a) |
Instance details Defined in Algebra.Graph.Labelled type ToVertex (Graph e a) = a
Methods toGraph :: Graph e a -> Graph (ToVertex (Graph e a)) # foldg :: r -> (ToVertex (Graph e a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> Graph e a -> r # isEmpty :: Graph e a -> Bool # hasVertex :: ToVertex (Graph e a) -> Graph e a -> Bool # hasEdge :: ToVertex (Graph e a) -> ToVertex (Graph e a) -> Graph e a -> Bool # vertexCount :: Graph e a -> Int # edgeCount :: Graph e a -> Int # vertexList :: Graph e a -> [ToVertex (Graph e a)] # edgeList :: Graph e a -> [(ToVertex (Graph e a), ToVertex (Graph e a))] # vertexSet :: Graph e a -> Set (ToVertex (Graph e a)) # vertexIntSet :: Graph e a -> IntSet # edgeSet :: Graph e a -> Set (ToVertex (Graph e a), ToVertex (Graph e a)) # preSet :: ToVertex (Graph e a) -> Graph e a -> Set (ToVertex (Graph e a)) # preIntSet :: Int -> Graph e a -> IntSet # postSet :: ToVertex (Graph e a) -> Graph e a -> Set (ToVertex (Graph e a)) # postIntSet :: Int -> Graph e a -> IntSet # adjacencyList :: Graph e a -> [(ToVertex (Graph e a), [ToVertex (Graph e a)])] # dfsForest :: Graph e a -> Forest (ToVertex (Graph e a)) # dfsForestFrom :: Graph e a -> [ToVertex (Graph e a)] -> Forest (ToVertex (Graph e a)) # dfs :: Graph e a -> [ToVertex (Graph e a)] -> [ToVertex (Graph e a)] # reachable :: Graph e a -> ToVertex (Graph e a) -> [ToVertex (Graph e a)] # topSort :: Graph e a -> Either (Cycle (ToVertex (Graph e a))) [ToVertex (Graph e a)] # isAcyclic :: Graph e a -> Bool # toAdjacencyMap :: Graph e a -> AdjacencyMap (ToVertex (Graph e a)) # toAdjacencyMapTranspose :: Graph e a -> AdjacencyMap (ToVertex (Graph e a)) # toAdjacencyIntMap :: Graph e a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: Graph e a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (Graph e a)) -> Graph e a -> Bool # isTopSortOf :: [ToVertex (Graph e a)] -> Graph e a -> Bool #
(Eq e, Monoid e, Ord a) => ToGraph (AdjacencyMap e a) # | Defined via `skeleton` and the `ToGraph` instance of `AdjacencyMap`.
Instance details Defined in Algebra.Graph.Labelled.AdjacencyMap Associated Types
type ToVertex (AdjacencyMap e a) |
Instance details Defined in Algebra.Graph.Labelled.AdjacencyMap type ToVertex (AdjacencyMap e a) = a
Methods toGraph :: AdjacencyMap e a -> Graph (ToVertex (AdjacencyMap e a)) # foldg :: r -> (ToVertex (AdjacencyMap e a) -> r) -> (r -> r -> r) -> (r -> r -> r) -> AdjacencyMap e a -> r # isEmpty :: AdjacencyMap e a -> Bool # hasVertex :: ToVertex (AdjacencyMap e a) -> AdjacencyMap e a -> Bool # hasEdge :: ToVertex (AdjacencyMap e a) -> ToVertex (AdjacencyMap e a) -> AdjacencyMap e a -> Bool # vertexCount :: AdjacencyMap e a -> Int # edgeCount :: AdjacencyMap e a -> Int # vertexList :: AdjacencyMap e a -> [ToVertex (AdjacencyMap e a)] # edgeList :: AdjacencyMap e a -> [(ToVertex (AdjacencyMap e a), ToVertex (AdjacencyMap e a))] # vertexSet :: AdjacencyMap e a -> Set (ToVertex (AdjacencyMap e a)) # vertexIntSet :: AdjacencyMap e a -> IntSet # edgeSet :: AdjacencyMap e a -> Set (ToVertex (AdjacencyMap e a), ToVertex (AdjacencyMap e a)) # preSet :: ToVertex (AdjacencyMap e a) -> AdjacencyMap e a -> Set (ToVertex (AdjacencyMap e a)) # preIntSet :: Int -> AdjacencyMap e a -> IntSet # postSet :: ToVertex (AdjacencyMap e a) -> AdjacencyMap e a -> Set (ToVertex (AdjacencyMap e a)) # postIntSet :: Int -> AdjacencyMap e a -> IntSet # adjacencyList :: AdjacencyMap e a -> [(ToVertex (AdjacencyMap e a), [ToVertex (AdjacencyMap e a)])] # dfsForest :: AdjacencyMap e a -> Forest (ToVertex (AdjacencyMap e a)) # dfsForestFrom :: AdjacencyMap e a -> [ToVertex (AdjacencyMap e a)] -> Forest (ToVertex (AdjacencyMap e a)) # dfs :: AdjacencyMap e a -> [ToVertex (AdjacencyMap e a)] -> [ToVertex (AdjacencyMap e a)] # reachable :: AdjacencyMap e a -> ToVertex (AdjacencyMap e a) -> [ToVertex (AdjacencyMap e a)] # topSort :: AdjacencyMap e a -> Either (Cycle (ToVertex (AdjacencyMap e a))) [ToVertex (AdjacencyMap e a)] # isAcyclic :: AdjacencyMap e a -> Bool # toAdjacencyMap :: AdjacencyMap e a -> AdjacencyMap (ToVertex (AdjacencyMap e a)) # toAdjacencyMapTranspose :: AdjacencyMap e a -> AdjacencyMap (ToVertex (AdjacencyMap e a)) # toAdjacencyIntMap :: AdjacencyMap e a -> AdjacencyIntMap # toAdjacencyIntMapTranspose :: AdjacencyMap e a -> AdjacencyIntMap # isDfsForestOf :: Forest (ToVertex (AdjacencyMap e a)) -> AdjacencyMap e a -> Bool # isTopSortOf :: [ToVertex (AdjacencyMap e a)] -> AdjacencyMap e a -> Bool #

# Derived functions

adjacencyMap :: (ToGraph t, Ord (ToVertex t)) => t -> Map (ToVertex t) (Set (ToVertex t)) #

The adjacency map of a graph: each vertex is associated with a set of its direct successors.

    adjacencyMap == Algebra.Graph.AdjacencyMap.adjacencyMap . toAdjacencyMap

adjacencyIntMap :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet #

The adjacency map of a graph: each vertex is associated with a set of its direct successors. Like `adjacencyMap` but specialised for graphs with vertices of type `Int`.

    adjacencyIntMap == Algebra.Graph.AdjacencyIntMap.adjacencyIntMap . toAdjacencyIntMap

adjacencyMapTranspose :: (ToGraph t, Ord (ToVertex t)) => t -> Map (ToVertex t) (Set (ToVertex t)) #

The transposed adjacency map of a graph: each vertex is associated with a set of its direct predecessors.

    adjacencyMapTranspose == Algebra.Graph.AdjacencyMap.adjacencyMap . toAdjacencyMapTranspose

adjacencyIntMapTranspose :: (ToGraph t, ToVertex t ~ Int) => t -> IntMap IntSet #

The transposed adjacency map of a graph: each vertex is associated with a set of its direct predecessors. Like `adjacencyMapTranspose` but specialised for graphs with vertices of type `Int`.

    adjacencyIntMapTranspose == Algebra.Graph.AdjacencyIntMap.adjacencyIntMap . toAdjacencyIntMapTranspose