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: Janaury 2019
(:&)
:: Show a => ([(b,Int)],Int,a,[(b,Int)]) -> Graph a b -> Graph a b
(:&) takes a node-context and a Graph and yields a new graph. |
matchAny
:: 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 .
|
empty
:: Graph a b
An empty Graph .
|
mkGraph
:: Show a => [(Int,a)] -> [(Int,Int,b)] -> Graph a b
Create a Graph from the list of LNode s and LEdge s.
|
buildGr
:: Show a => [([(b,Int)],Int,a,[(b,Int)])] -> Graph a b
Build a Graph from a list of Context s.
|
mkUGraph
:: [Int] -> [(Int,Int)] -> Graph () ()
Build a quasi-unlabeled Graph from the list of Node s and Edge s.
|
insNode
:: Show a => (Int,a) -> Graph a b -> Graph a b
Insert a LNode into the Graph .
|
insEdge
:: Show a => (Int,Int,b) -> Graph a b -> Graph a b
Insert a LEdge into the Graph .
|
delNode
:: Int -> Graph a b -> Graph a b
Remove a Node from the Graph .
|
delEdge
:: Show a => (Int,Int) -> Graph a b -> Graph a b
Remove an Edge from the Graph .
|
insNodes
:: Show a => [(Int,a)] -> Graph a b -> Graph a b
Insert multiple LNode s into the Graph .
|
insEdges
:: Show a => [(Int,Int,b)] -> Graph a b -> Graph a b
Insert multiple LEdge s into the Graph .
|
delNodes
:: [Int] -> Graph a b -> Graph a b
Remove multiple Node s from the Graph .
|
delEdges
:: Show a => [(Int,Int)] -> Graph a b -> Graph a b
Remove multiple Edge s from the Graph .
|
isEmpty
:: Graph a b -> Bool
test if the given Graph is empty.
|
match
:: 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 .
|
noNodes
:: Graph a b -> Int
The number of Node s in a Graph .
|
nodeRange
:: Graph a b -> (Int,Int)
The minimum and maximum Node in a Graph .
|
context
:: Graph a b -> Int -> ([(b,Int)],Int,a,[(b,Int)])
Find the context for the given Node .
|
lab
:: Graph a b -> Int -> Maybe a
Find the label for a Node .
|
neighbors
:: Graph a b -> Int -> [Int]
Find the neighbors for a Node .
|
suc
:: Graph a b -> Int -> [Int]
Find all Node s that have a link from the given Node .
|
pre
:: Graph a b -> Int -> [Int]
Find all Node s that link to to the given Node .
|
lsuc
:: Graph a b -> Int -> [(Int,b)]
Find all Nodes and their labels, which are linked from the given Node .
|
lpre
:: Graph a b -> Int -> [(Int,b)]
Find all Node s that link to the given Node and the label of each link.
|
out
:: Graph a b -> Int -> [(Int,Int,b)]
Find all outward-bound LEdge s for the given Node .
|
inn
:: Graph a b -> Int -> [(Int,Int,b)]
Find all inward-bound LEdge s for the given Node .
|
outdeg
:: Graph a b -> Int -> Int
The outward-bound degree of the Node .
|
indeg
:: Graph a b -> Int -> Int
The inward-bound degree of the Node .
|
deg
:: Graph a b -> Int -> Int
The degree of the Node .
|
gelem
:: Int -> Graph a b -> Bool
True if the Node is present in the Graph .
|
equal
:: (Eq a, Eq b) => Graph a b -> Graph a b -> Bool
graph equality |
node'
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The Node in a Context .
|
lab'
:: ([(a,Int)],Int,b,[(a,Int)]) -> b
The label in a Context .
|
labNode'
:: ([(a,Int)],Int,b,[(a,Int)]) -> (Int,b)
The LNode from a Context .
|
neighbors'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All Node s linked to or from in a Context .
|
suc'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All Node s linked to in a Context .
|
pre'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [Int]
All Node s linked from in a Context .
|
lpre'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,a)]
All Node s linked from in a Context , and the label of the links.
|
lsuc'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,a)]
All Node s linked from in a Context , and the label of the links.
|
out'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,Int,a)]
All outward-directed LEdge s in a Context .
|
inn'
:: ([(a,Int)],Int,b,[(a,Int)]) -> [(Int,Int,a)]
All inward-directed LEdge s in a Context .
|
outdeg'
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The outward degree of a Context .
|
indeg'
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The inward degree of a Context .
|
deg'
:: ([(a,Int)],Int,b,[(a,Int)]) -> Int
The degree of a Context .
|
labNodes
:: Graph a b -> [(Int,a)]
A list of all LNode s in the Graph .
|
labEdges
:: Graph a b -> [(Int,Int,b)]
A list of all LEdge s in the Graph .
|
nodes
:: Graph a b -> [Int]
List all Node s in the Graph .
|
edges
:: Graph a b -> [(Int,Int)]
List all Edge s in the Graph .
|
newNodes
:: Int -> Graph a b -> [Int]
List N available Node s, ie Node s that are not used in the Graph .
|
ufold
:: (([(a,Int)],Int,b,[(a,Int)]) -> c -> c) -> c -> Graph b a -> c
Fold a function over the graph. |
gmap
:: Show a => (([(b,Int)],Int,c,[(b,Int)]) -> ([(d,Int)],Int,a,[(d,Int)])) -> Graph c b -> Graph a d
Map a function over the graph. |
nmap
:: Show a => (b -> a) -> Graph b c -> Graph a c
Map a function over the Node labels in a graph.
|
emap
:: Show a => (b -> c) -> Graph a b -> Graph a c
Map a function over the Edge labels in a graph.
|
labUEdges
:: [(a,b)] -> [(a,b,())]
add label () to list of edges (node,node) |
labUNodes
:: [a] -> [(a,())]
add label () to list of nodes |
showGraph
:: (Show a, Show b) => Graph a b -> String
Represent Graph as String |
The type variables of Graph are nodeLabel and edgeLabel. The internal representation of Graph is hidden.
Constructors:
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 = (Node,a)
Quasi-unlabeled node
Type synonym: UNode = LNode ()
Unlabeled edge
Type synonym: Edge = (Node,Node)
Labeled edge
Type synonym: LEdge a = (Node,Node,a)
Quasi-unlabeled edge
Type synonym: UEdge = LEdge ()
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 = (Adj b,Node,a,Adj b)
maybe context
Type synonym: MContext a b = Maybe (Context a b)
context with edges and node label only, without the node identifier itself
Type synonym: Context' a b = (Adj b,a,Adj b)
Unlabeled context.
Type synonym: UContext = ([Node],Node,[Node])
A graph decompostion is a context for a node n and the remaining graph without that node.
Type synonym: GDecomp a b = (Context a b,Graph a b)
a decomposition with a maybe context
Type synonym: Decomp a b = (MContext a b,Graph a b)
Unlabeled decomposition.
Type synonym: UDecomp a = (Maybe UContext,a)
Unlabeled path
Type synonym: Path = [Node]
Labeled path
Type synonym: LPath a = [LNode a]
Quasi-unlabeled path
Type synonym: UPath = [UNode]
a graph without any labels
Type synonym: UGr = Graph () ()
(:&) 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.
|
decompose a graph into the 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.
|
Build a quasi-unlabeled |
match is the complement side of (:&), decomposing a |
The number of
|
Find the context for the given |
Find all Nodes and their labels, which are linked from the given |
Find all |
|
The label in a
|
|
|
All |
All |
List N available |
Fold a function over the graph. |
Map a function over the graph. |
Map a function over the |
Map a function over the |
add label () to list of edges (node,node) |
add label () to list of nodes |