Library for inductive graphs (port of a Haskell library by Martin Erwig).
In this library, graphs are composed and decomposed in an inductive way.
The key idea is as follows:
A graph is either empty or it consists of node context
and a graph g' which
are put together by a constructor (:&).
This constructor (:&), however, is not a constructor in
the sense of abstract
data type, but more basically a defined constructing funtion.
A context is a node together withe the edges to and from this node into
the nodes in the graph g'.
For examples of how to use this library, cf. the module "GraphAlgorithms".
Author: Bernd Brassel
Version: May 2005
| Exported names: |
Datatypes:
Context
| Context'
| Decomp
| Edge
| GDecomp
| Graph
| LEdge
| LNode
| LPath
| MContext
| Node
| Path
| UContext
| UDecomp
| UEdge
| UGr
| UNode
| UPath
Functions:
:&
| buildGr
| context
| deg
| deg'
| delEdge
| delEdges
| delNode
| delNodes
| edges
| emap
| empty
| equal
| gelem
| gmap
| indeg
| indeg'
| inn
| inn'
| insEdge
| insEdges
| insNode
| insNodes
| isEmpty
| lab
| lab'
| labEdges
| labNode'
| labNodes
| labUEdges
| labUNodes
| lpre
| lpre'
| lsuc
| lsuc'
| match
| matchAny
| mkGraph
| mkUGraph
| neighbors
| neighbors'
| newNodes
| nmap
| node'
| nodeRange
| nodes
| noNodes
| out
| out'
| outdeg
| outdeg'
| pre
| pre'
| showGraph
| suc
| suc'
| ufold
| Summary of exported functions: |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
| Imported modules: |
| Exported datatypes: |
Nodes and edges themselves (in contrast to their labels) are coded as integers.
For both of them, there are variants as labeled, unlabelwd and quasi unlabeled
(labeled with ()).
Unlabeled node
Type synonym: Node = Int
Labeled node
Type synonym: LNode a = (Int,a)
Quasi-unlabeled node
Type synonym: UNode = (Int,())
Unlabeled edge
Type synonym: Edge = (Int,Int)
Labeled edge
Type synonym: LEdge a = (Int,Int,a)
Quasi-unlabeled edge
Type synonym: UEdge = (Int,Int,())
The context of a node is the node itself (along with label) and its adjacent nodes. Thus, a context is a quadrupel, for node n it is of the form (edges to n,node n,n's label,edges from n)
Type synonym: Context a b = ([(b,Int)],Int,a,[(b,Int)])
maybe context
Type synonym: MContext a b = Maybe ([(b,Int)],Int,a,[(b,Int)])
context with edges and node label only, without the node identifier itself
Type synonym: Context' a b = ([(b,Int)],a,[(b,Int)])
Unlabeled context.
Type synonym: UContext = ([Int],Int,[Int])
A graph decompostion is a context for a node n and the remaining graph without that node.
Type synonym: GDecomp a b = (([(b,Int)],Int,a,[(b,Int)]),Graph a b)
a decomposition with a maybe context
Type synonym: Decomp a b = (Maybe ([(b,Int)],Int,a,[(b,Int)]),Graph a b)
Unlabeled decomposition.
Type synonym: UDecomp a = (Maybe ([Int],Int,[Int]),a)
Unlabeled path
Type synonym: Path = [Int]
Labeled path
Type synonym: LPath a = [(Int,a)]
Quasi-unlabeled path
Type synonym: UPath = [(Int,())]
a graph without any labels
Type synonym: UGr = Graph () ()
The type variables of Graph are nodeLabel and edgeLabel. The internal representation of Graph is hidden.
Constructors:
| Exported functions: |
:: ([(a,Int)],Int,b,[(a,Int)]) -> Graph b a -> Graph b a
(:&) takes a node-context and a Graph and yields a new graph.
The according key idea is detailed at the beginning.
nl is the type of the node labels and el the edge labels.
Note that it is an error to induce a context for
a node already contained in the graph.
:: Graph a b -> (([(b,Int)],Int,a,[(b,Int)]),Graph a b)
decompose a graph into the 'Context' for an arbitrarily-chosen 'Node'
and the remaining 'Graph'.
In order to use graphs as abstract data structures, we also need means to
decompose a graph. This decompostion should work as much like pattern matching
as possible. The normal matching is done by the function matchAny, which takes
a graph and yields a graph decompostion.
According to the main idea, matchAny . (:&) should be an identity.
:: Graph a b
An empty 'Graph'.
:: [(Int,a)] -> [(Int,Int,b)] -> Graph a b
Create a 'Graph' from the list of 'LNode's and 'LEdge's.
:: [([(a,Int)],Int,b,[(a,Int)])] -> Graph b a
Build a 'Graph' from a list of 'Context's.
:: [Int] -> [(Int,Int)] -> Graph () ()
Build a quasi-unlabeled 'Graph' from the list of 'Node's and 'Edge's.
:: (Int,a) -> Graph a b -> Graph a b
Insert a 'LNode' into the 'Graph'.
:: (Int,Int,a) -> Graph b a -> Graph b a
Insert a 'LEdge' into the 'Graph'.
:: Int -> Graph a b -> Graph a b
Remove a 'Node' from the 'Graph'.
:: (Int,Int) -> Graph a b -> Graph a b
Remove an 'Edge' from the 'Graph'.
:: [(Int,a)] -> Graph a b -> Graph a b
Insert multiple 'LNode's into the 'Graph'.
:: [(Int,Int,a)] -> Graph b a -> Graph b a
Insert multiple 'LEdge's into the 'Graph'.
:: [Int] -> Graph a b -> Graph a b
Remove multiple 'Node's from the 'Graph'.
:: [(Int,Int)] -> Graph a b -> Graph a b
Remove multiple 'Edge's from the 'Graph'.
:: Graph a b -> Bool
test if the given 'Graph' is empty.
:: Int -> Graph a b -> (Maybe ([(b,Int)],Int,a,[(b,Int)]),Graph a b)
match is the complement side of (:&), decomposing a 'Graph' into the 'MContext' found for the given node and the remaining 'Graph'.
:: Graph a b -> Int
The number of 'Node's in a 'Graph'.
:: Graph a b -> (Int,Int)
The minimum and maximum 'Node' in a 'Graph'.
:: Graph a b -> Int -> ([(b,Int)],Int,a,[(b,Int)])
Find the context for the given 'Node'. In contrast to "match", "context" causes an error if the 'Node' is not present in the 'Graph'.
:: Graph a b -> Int -> Maybe a
Find the label for a 'Node'.
:: Graph a b -> Int -> [Int]
Find the neighbors for a 'Node'.
:: Graph a b -> Int -> [Int]
Find all 'Node's that have a link from the given 'Node'.
:: Graph a b -> Int -> [Int]
Find all 'Node's that link to to the given 'Node'.
:: Graph a b -> Int -> [(Int,b)]
Find all Nodes and their labels, which are linked from the given 'Node'.
:: Graph a b -> Int -> [(Int,b)]
Find all 'Node's that link to the given 'Node' and the label of each link.
:: Graph a b -> Int -> [(Int,Int,b)]
Find all outward-bound 'LEdge's for the given 'Node'.
:: Graph a b -> Int -> [(Int,Int,b)]
Find all inward-bound 'LEdge's for the given 'Node'.
:: Graph a b -> Int -> Int
The outward-bound degree of the 'Node'.
:: Graph a b -> Int -> Int
The inward-bound degree of the 'Node'.
:: Graph a b -> Int -> Int
The degree of the 'Node'.
:: Int -> Graph a b -> Bool
'True' if the 'Node' is present in the 'Graph'.
:: Graph a b -> Graph a b -> Bool
graph equality
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The 'Node' in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> b
The label in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> (Int,b)
The 'LNode' from a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All 'Node's linked to or from in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All 'Node's linked to in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All 'Node's linked from in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,a)]
All 'Node's linked from in a 'Context', and the label of the links.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,a)]
All 'Node's linked from in a 'Context', and the label of the links.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,Int,a)]
All outward-directed 'LEdge's in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,Int,a)]
All inward-directed 'LEdge's in a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The outward degree of a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The inward degree of a 'Context'.
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The degree of a 'Context'.
:: Graph a b -> [(Int,a)]
A list of all 'LNode's in the 'Graph'.
:: Graph a b -> [(Int,Int,b)]
A list of all 'LEdge's in the 'Graph'.
:: Graph a b -> [Int]
List all 'Node's in the 'Graph'.
:: Graph a b -> [(Int,Int)]
List all 'Edge's in the 'Graph'.
:: Int -> Graph a b -> [Int]
List N available 'Node's, ie 'Node's that are not used in the 'Graph'.
:: (([(a,Int)],Int,b,[(a,Int)]) -> c -> c) -> c -> Graph b a -> c
Fold a function over the graph.
:: (([(a,Int)],Int,b,[(a,Int)]) -> ([(c,Int)],Int,d,[(c,Int)])) -> Graph b a -> Graph d c
Map a function over the graph.
:: (a -> b) -> Graph a c -> Graph b c
Map a function over the 'Node' labels in a graph.
:: (a -> b) -> Graph c a -> Graph c b
Map a function over the 'Edge' labels in a graph.
:: [(a,b)] -> [(a,b,())]
add label () to list of edges (node,node)
:: [a] -> [(a,())]
add label () to list of nodes
:: Graph a b -> String
Represent Graph as String