A module defining a polymorphic data type for (simple, undirected) graphs, together with constructions of some common families of graphs, new from old constructions, and calculation of simple properties of graphs.
- combinationsOf :: Integral t => t -> [a] -> [[a]]
- data Graph a = G [a] [[a]]
- nf :: Ord a => Graph a -> Graph a
- graph :: Ord t => ([t], [[t]]) -> Graph t
- nullGraph :: Integral t => t -> Graph t
- nullGraph' :: Graph Int
- c :: Integral t => t -> Graph t
- k :: Integral t => t -> Graph t
- fromDigits :: Integral a => Graph [a] -> Graph a
- fromBinary :: Integral a => Graph [a] -> Graph a
- diameter :: Ord t => Graph t -> Int
- girth :: Eq t => Graph t -> Int
- kneser :: Integral t => t -> t -> Graph [t]
Documentation
combinationsOf :: Integral t => t -> [a] -> [[a]]Source
combinationsOf k xs returns the subsets of xs of size k. If xs is in ascending order, then the returned list is in ascending order
Datatype for graphs, represented as a list of vertices and a list of edges. For most purposes, graphs are required to be in normal form. A graph G vs es is in normal form if (i) vs is in ascending order without duplicates, (ii) es is in ascending order without duplicates, (iii) each e in es is a 2-element list [x,y], x<y
G [a] [[a]] |
nf :: Ord a => Graph a -> Graph aSource
Convert a graph to normal form. The input is assumed to be a valid graph apart from order
graph :: Ord t => ([t], [[t]]) -> Graph tSource
Safe constructor for graph from lists of vertices and edges. graph (vs,es) checks that vs and es are valid before returning the graph.
nullGraph :: Integral t => t -> Graph tSource
The null graph on n vertices is the graph with no edges
The null graph, with no vertices or edges
fromDigits :: Integral a => Graph [a] -> Graph aSource
Given a graph with vertices which are lists of small integers, eg [1,2,3], return a graph with vertices which are the numbers obtained by interpreting these as digits, eg 123. The caller is responsible for ensuring that this makes sense (eg that the small integers are all < 10)
fromBinary :: Integral a => Graph [a] -> Graph aSource
Given a graph with vertices which are lists of 0s and 1s, return a graph with vertices which are the numbers obtained by interpreting these as binary digits. For example, [1,1,0] -> 6.
diameter :: Ord t => Graph t -> IntSource
The diameter of a graph is maximum distance between two distinct vertices