Data.Graph.Inductive.Query.DFS

fgl-5.7.0.1: Martin Erwig's Functional Graph Library

Safe Haskell | Safe
Language | Haskell98

Data.Graph.Inductive.Query.DFS

Contents

- Standard
- Undirected
- Reversed
- Applications of depth first search/forest
- Applications of undirected depth first search/forest

Description

Depth-first search algorithms.

Names consist of:

1. An optional direction parameter, specifying which nodes to visit next.

`u`
  undirectional: ignore edge direction
`r`
  reversed: walk edges in reverse
`x`
  user defined: speciy which paths to follow

1. "df" for depth-first

2. A structure parameter, specifying the type of the result.

   `s`
     Flat list of results
   `f`
     Structured `Tree` of results
3. An optional "With", which instead of putting the found nodes directly into the result, adds the result of a computation on them into it.
4. An optional prime character, in which case all nodes of the graph will be visited, instead of a user-given subset.

Synopsis

- type CFun a b c = Context a b -> c
- dfs :: Graph gr => [Node] -> gr a b -> [Node]
- dfs' :: Graph gr => gr a b -> [Node]
- dff :: Graph gr => [Node] -> gr a b -> [Tree Node]
- dff' :: Graph gr => gr a b -> [Tree Node]
- dfsWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [c]
- dfsWith' :: Graph gr => CFun a b c -> gr a b -> [c]
- dffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c]
- dffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c]
- xdfsWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> [c]
- xdfWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> ([Tree c], gr a b)
- xdffWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> [Tree c]
- udfs :: Graph gr => [Node] -> gr a b -> [Node]
- udfs' :: Graph gr => gr a b -> [Node]
- udff :: Graph gr => [Node] -> gr a b -> [Tree Node]
- udff' :: Graph gr => gr a b -> [Tree Node]
- udffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c]
- udffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c]
- rdff :: Graph gr => [Node] -> gr a b -> [Tree Node]
- rdff' :: Graph gr => gr a b -> [Tree Node]
- rdfs :: Graph gr => [Node] -> gr a b -> [Node]
- rdfs' :: Graph gr => gr a b -> [Node]
- rdffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c]
- rdffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c]
- topsort :: Graph gr => gr a b -> [Node]
- topsort' :: Graph gr => gr a b -> [a]
- scc :: Graph gr => gr a b -> [[Node]]
- reachable :: Graph gr => Node -> gr a b -> [Node]
- components :: Graph gr => gr a b -> [[Node]]
- noComponents :: Graph gr => gr a b -> Int
- isConnected :: Graph gr => gr a b -> Bool
- condensation :: Graph gr => gr a b -> gr [Node] ()

# Documentation

type CFun a b c = Context a b -> c #

# Standard

dfs :: Graph gr => [Node] -> gr a b -> [Node] #

Depth-first search.

dfs' :: Graph gr => gr a b -> [Node] #

dff :: Graph gr => [Node] -> gr a b -> [Tree Node] #

Directed depth-first forest.

dff' :: Graph gr => gr a b -> [Tree Node] #

dfsWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [c] #

dfsWith' :: Graph gr => CFun a b c -> gr a b -> [c] #

dffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c] #

dffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c] #

xdfsWith #

Arguments

:: Graph gr |
=> CFun a b [Node] | Mapping from a node to its neighbours to be visited as well. `suc'` for example makes `xdfsWith` traverse the graph following the edge directions, while `pre'` means reversed directions.
-> CFun a b c | Mapping from the `Context` of a node to a result value.
-> [Node] | Nodes to be visited.
-> gr a b |
-> [c] |

Most general DFS algorithm to create a list of results. The other list-returning functions such as `dfs` are all defined in terms of this one.

    xdfsWith d f vs = preorderF . xdffWith d f vs

xdfWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> ([Tree c], gr a b) #

Most general DFS algorithm to create a forest of results, otherwise very similar to `xdfsWith`. The other forest-returning functions such as `dff` are all defined in terms of this one.

xdffWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> [Tree c] #

Discard the graph part of the result of `xdfWith`.

    xdffWith d f vs g = fst (xdfWith d f vs g)

# Undirected

udfs :: Graph gr => [Node] -> gr a b -> [Node] #

Undirected depth-first search, obtained by following edges regardless of their direction.

udfs' :: Graph gr => gr a b -> [Node] #

udff :: Graph gr => [Node] -> gr a b -> [Tree Node] #

Undirected depth-first forest, obtained by following edges regardless of their direction.

udff' :: Graph gr => gr a b -> [Tree Node] #

udffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c] #

udffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c] #

# Reversed

rdff :: Graph gr => [Node] -> gr a b -> [Tree Node] #

Reverse depth-first forest, obtained by following predecessors.

rdff' :: Graph gr => gr a b -> [Tree Node] #

rdfs :: Graph gr => [Node] -> gr a b -> [Node] #

Reverse depth-first search, obtained by following predecessors.

rdfs' :: Graph gr => gr a b -> [Node] #

rdffWith :: Graph gr => CFun a b c -> [Node] -> gr a b -> [Tree c] #

rdffWith' :: Graph gr => CFun a b c -> gr a b -> [Tree c] #

# Applications of depth first search/forest

topsort :: Graph gr => gr a b -> [Node] #

Topological sorting, i.e. a list of `Node`s so that if there's an edge between a source and a target node, the source appears earlier in the result.

topsort' :: Graph gr => gr a b -> [a] #

`topsort`, returning only the labels of the nodes.

scc :: Graph gr => gr a b -> [[Node]] #

Collection of strongly connected components

reachable :: Graph gr => Node -> gr a b -> [Node] #

Collection of nodes reachable from a starting point.

# Applications of undirected depth first search/forest

components :: Graph gr => gr a b -> [[Node]] #

Collection of connected components

noComponents :: Graph gr => gr a b -> Int #

Number of connected components

isConnected :: Graph gr => gr a b -> Bool #

Is the graph connected?

condensation :: Graph gr => gr a b -> gr [Node] () #

The condensation of the given graph, i.e., the graph of its strongly connected components.