-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Graph-Theoretic Analysis library. -- -- A library to use graph theory to analyse the relationships inherent in -- discrete data. @package Graphalyze @version 0.11.0.0 -- | This module defines the report framework used. module Data.Graph.Analysis.Reporting -- | Representation of a document. The document is to be stored in the -- directory rootDirectory, and the main file is to have a -- filename of fileFront <.> -- (docExtension dg), where dg is an instance of -- DocumentGenerator. data Document Doc :: FilePath -> String -> FilePath -> DocInline -> String -> String -> [(Either DocGraph DocInline, DocInline)] -> [DocElement] -> Document -- | Document location rootDirectory :: Document -> FilePath fileFront :: Document -> String -- | The sub-directory of rootDirectory, where graphs are to be -- created. graphDirectory :: Document -> FilePath -- | Pre-matter title :: Document -> DocInline author :: Document -> String date :: Document -> String -- | Main-matter legend :: Document -> [(Either DocGraph DocInline, DocInline)] content :: Document -> [DocElement] -- | Represents the class of document generators. class DocumentGenerator dg createDocument :: DocumentGenerator dg => dg -> Document -> IO (Maybe FilePath) docExtension :: DocumentGenerator dg => dg -> String -- | Representation of a location, either on the internet or locally. data Location Web :: String -> Location File :: FilePath -> Location -- | Elements of a document. data DocElement Section :: DocInline -> [DocElement] -> DocElement Paragraph :: [DocInline] -> DocElement Enumeration :: [DocElement] -> DocElement Itemized :: [DocElement] -> DocElement Definitions :: [(DocInline, DocInline)] -> DocElement GraphImage :: DocGraph -> DocElement -- | Inline elements of a document. data DocInline Text :: String -> DocInline BlankSpace :: DocInline Grouping :: [DocInline] -> DocInline Bold :: DocInline -> DocInline Emphasis :: DocInline -> DocInline DocLink :: DocInline -> Location -> DocInline DocImage :: DocInline -> Location -> DocInline -- | Specify the size the DotGraph should be at. data GraphSize -- | Specify the size to use. GivenSize :: Point -> GraphSize -- | Let GraphViz choose an appropriate size. DefaultSize :: GraphSize -- | Specify the DotGraph to turn into an image, its filename (sans -- extension) and its caption. The DotGraph should not have a -- Size set. data DocGraph DG :: FilePath -> DocInline -> DotGraph Node -> DocGraph -- | What name to provide the image file (without an extension). imageFile :: DocGraph -> FilePath description :: DocGraph -> DocInline dotGraph :: DocGraph -> DotGraph Node -- | Defines the parameters used for creating visualisations of graphs. data VisParams VParams :: FilePath -> FilePath -> VisProperties -> Maybe VisProperties -> Bool -> VisParams -- | Root directory of the document. rootDir :: VisParams -> FilePath -- | Image sub-directory. graphDir :: VisParams -> FilePath -- | The default visualisation. defaultImage :: VisParams -> VisProperties -- | If Just vp', then a larger visualisation is linked to -- from the default one. largeImage :: VisParams -> Maybe VisProperties -- | Should the Dot source code be saved as well? saveDot :: VisParams -> Bool -- | A specification on how to visualise a DocGraph. data VisProperties VProps :: GraphSize -> GraphvizOutput -> VisProperties size :: VisProperties -> GraphSize format :: VisProperties -> GraphvizOutput -- | Create the legend section and add it to the document proper. addLegend :: FilePath -> FilePath -> VisProperties -> Document -> IO Document -- | Return today's date as a string, e.g. "Monday 1 January, 2000". This -- arbitrary format is chosen as there doesn't seem to be a way of -- determining the correct format as per the user's locale settings. today :: IO String -- | Attempts to create the specified directly, returning True if -- successful (or if the directory already exists), False if an -- error occurred. tryCreateDirectory :: FilePath -> IO Bool -- | Attempts to create image files (with the given filename in the given -- directory) from the graph. If the second VisProperties not -- Nothing, then the first image links to the second. The whole -- result is wrapped in a Paragraph. unDotPath is applied -- to the filename in the DocGraph. createGraph :: VisParams -> DocGraph -> IO DocElement -- | Using a 6:4 ratio, create the given Point representing -- width,height from the width. createSize :: Double -> GraphSize -- | Replace all . with - in the given FilePath, -- since some output formats (e.g. LaTeX) don't like extraneous -- .'s in the filename. unDotPath :: FilePath -> FilePath instance Eq GraphSize instance Ord GraphSize instance Show GraphSize instance Read GraphSize instance Eq VisProperties instance Ord VisProperties instance Show VisProperties instance Read VisProperties instance Eq VisParams instance Ord VisParams instance Show VisParams instance Read VisParams instance Eq DocGraph instance Ord DocGraph instance Show DocGraph instance Read DocGraph instance Eq DocInline instance Ord DocInline instance Show DocInline instance Read DocInline instance Eq DocElement instance Ord DocElement instance Show DocElement instance Read DocElement instance Eq Location instance Ord Location instance Show Location instance Read Location instance Eq Document instance Ord Document instance Show Document instance Read Document -- | This module uses Pandoc to generate documents: -- http://johnmacfarlane.net/pandoc/ -- -- Note that Pandoc is released under GPL-2 or later, however according -- to the Free Software Foundation, I am indeed allowed to use it: -- http://www.fsf.org/licensing/licenses/gpl-faq.html#IfLibraryIsGPL -- since the 2-Clause BSD license that I'm using is GPL-compatible: -- http://www.fsf.org/licensing/licenses/index_html#GPLCompatibleLicenses -- (search for FreeBSD License, which is another name for it). module Data.Graph.Analysis.Reporting.Pandoc -- | Definition of a Pandoc Document. Size measurements are in inches, and -- a 6:4 ratio is used for width:length. data PandocDocument pandocHtml :: PandocDocument pandocLaTeX :: PandocDocument pandocRtf :: PandocDocument pandocMarkdown :: PandocDocument -- | Also save the generated Dot code to file when creating visualisations. alsoSaveDot :: PandocDocument -> PandocDocument instance Eq PandocProcess instance Ord PandocProcess instance Show PandocProcess instance Read PandocProcess instance DocumentGenerator PandocDocument -- | This module defines the various types and classes utilised by the -- Graphalyze library. module Data.Graph.Analysis.Types -- | Represents information about the graph being analysed. data GraphData n e GraphData :: AGr n e -> NGroup -> Bool -> [Rel n e] -> GraphData n e -- | We use a graph type with no edge labels. graph :: GraphData n e -> AGr n e -- | The expected root nodes in the graph. wantedRootNodes :: GraphData n e -> NGroup -- | Is the data this graph represents directed in nature? directedData :: GraphData n e -> Bool -- | Unused relationships (i.e. not in the actual graph). These are the -- edges containing nodes not in the graph. unusedRelationships :: GraphData n e -> [Rel n e] -- | An alias for the type of graph being used by default. type AGr n e = Gr n e -- | A relationship between two nodes with a label. type Rel n e = (n, n, e) -- | A grouping of Nodes. type NGroup = [Node] -- | A grouping of LNodes. type LNGroup a = [LNode a] -- | The expected roots in the data to be analysed. wantedRoots :: GraphData n e -> LNGroup n -- | Add extra expected root nodes. No checks are made that these are valid -- Node values. addRoots :: GraphData n e -> NGroup -> GraphData n e -- | Use a filtering function to find extra root nodes to add. addRootsBy :: (LNode n -> Bool) -> GraphData n e -> GraphData n e -- | Apply an algorithm to the data to be analysed. applyAlg :: (AGr n e -> a) -> GraphData n e -> a -- | Apply an algorithm that requires knowledge about whether the graph is -- directed (True) or undirected (False) to the data to be -- analysed. applyDirAlg :: (Bool -> AGr n e -> a) -> GraphData n e -> a -- | Merge the unusedRelationships into the graph by adding the -- appropriate nodes. mergeUnused :: (Ord n, Ord e) => GraphData n e -> GraphData n e -- | Used to set unusedRelationships = []. This is of use -- when they are unneeded or because there is no sensible mapping -- function to use when applying a mapping function to the nodes in the -- graph. removeUnused :: GraphData n e -> GraphData n e -- | Replace the current graph by applying a function to it. To ensure type -- safety, removeUnused is applied. updateGraph :: (AGr a b -> AGr c d) -> GraphData a b -> GraphData c d -- | Replace the current graph by applying a function to it, where the -- function depends on whether the graph is directed (True) or -- undirected (False). To ensure type safety, removeUnused -- is applied. updateGraph' :: (Bool -> AGr a b -> AGr c d) -> GraphData a b -> GraphData c d -- | Apply a function to all the data points. This might be useful in -- circumstances where you want to reduce the data type used to a simpler -- one, etc. The function is also applied to the datums in -- unusedRelationships. mapAllNodes :: (Ord a, Ord e, Ord b) => (a -> b) -> GraphData a e -> GraphData b e -- | Apply the first function to nodes in the graph, and the second -- function to those unknown datums in unusedRelationships. As a -- sample reason for this function, it can be used to apply a two-part -- constructor (e.g. Left and Right from Either) to -- the nodes such that the wanted and unwanted datums can be -- differentiated before calling mergeUnused. mapNodeType :: (Ord a, Ord b, Ord e) => (a -> b) -> (a -> b) -> GraphData a e -> GraphData b e -- | These types and classes represent useful label types. -- -- The class of outputs of a clustering algorithm. This class is mainly -- used for visualization purposes, with the Ord instance required -- for grouping. Instances of this class are intended for use as the -- label type of graphs. class ClusterType (Cluster cl) => ClusterLabel cl where { type family Cluster cl; type family NodeLabel cl; } cluster :: ClusterLabel cl => cl -> Cluster cl nodeLabel :: ClusterLabel cl => cl -> NodeLabel cl -- | A class used to define which types are valid for clusters. class Ord c => ClusterType c clustID :: ClusterType c => c -> Maybe GraphID -- | A polymorphic type that covers all possible ID values allowed by Dot -- syntax. Note that whilst the ParseDot and PrintDot -- instances for String will properly take care of the special -- cases for numbers, they are treated differently here. data GraphID :: * Str :: String -> GraphID Int :: Int -> GraphID Dbl :: Double -> GraphID -- | A generic cluster-label type. data GenCluster a GC :: Int -> a -> GenCluster a clust :: GenCluster a -> Int nLbl :: GenCluster a -> a -- | Label type for storing node positions. Note that this isn't an -- instance of ClusterLabel since there's no clear indication on -- which cluster a node belongs to at this stage. data PosLabel a PLabel :: Int -> Int -> Node -> a -> PosLabel a xPos :: PosLabel a -> Int yPos :: PosLabel a -> Int pnode :: PosLabel a -> Node plabel :: PosLabel a -> a instance Eq a => Eq (PosLabel a) instance Show a => Show (PosLabel a) instance Eq a => Eq (GenCluster a) instance Show a => Show (GenCluster a) instance ClusterLabel (GenCluster a) instance ClusterType String instance ClusterType Int -- | This module defines various utility functions used throughout. module Data.Graph.Analysis.Utils -- | The node number of an LNode. node :: LNode a -> Node -- | The label of an LNode. label :: LNode a -> a -- | The labels of all nodes in a tree. labels :: Graph g => g a b -> [a] -- | Extract the Edge from the LEdge. edge :: LEdge b -> Edge -- | The label of an LEdge. eLabel :: LEdge b -> b -- | Obtain the labels for a list of Nodes. It is assumed that each -- Node is indeed present in the given graph. addLabels :: Graph g => g a b -> [Node] -> [LNode a] -- | Obtain the labels for a Set of Nodes. It is assumed that -- each Node is indeed present in the given graph. addLabels' :: (Ord a, Graph g) => g a b -> Set Node -> Set (LNode a) -- | Obtain the labels for a list of Nodes. It is assumed that each -- Node is indeed present in the given graph. getLabels :: Graph g => g a b -> [Node] -> [a] -- | Obtain the labels for a list of Nodes. It is assumed that each -- Node is indeed present in the given graph. getLabels' :: (Ord a, Graph g) => g a b -> Set Node -> Set a -- | Find all the labelled nodes in the graph that match the given -- predicate. filterNodes :: Graph g => (g a b -> LNode a -> Bool) -> g a b -> [LNode a] -- | Find all the nodes in the graph that match the given predicate. filterNodes' :: Graph g => (g a b -> Node -> Bool) -> g a b -> [Node] -- | Extract the actual LNodes from an LPath. pathValues :: LPath a -> [LNode a] -- | Make the graph undirected, i.e. for every edge from A to B, there -- exists an edge from B to A. The provided function -- Data.Graph.Inductive.Basic.undir duplicates loops as well, -- which isn't wanted. It is assumed that no edges are already duplicates -- [i.e. if there exists an edge (n1,n2), then there doesn't exist -- (n2,n1)]. This function also preserves edge labels: if two edges exist -- between two nodes with different edge labels, then both edges will be -- duplicated. undir :: (Eq b, DynGraph gr) => gr a b -> gr a b -- | This is a pseudo-inverse of undir: any edges that are both -- successor and predecessor become successor edges only. oneWay :: (DynGraph g, Eq b) => g a b -> g a b -- | Makes the graph a simple one, by removing all duplicate edges and -- loops. The edges removed if duplicates exist are arbitrary. mkSimple :: DynGraph gr => gr a b -> gr a b -- | Adjoin duplicate edges by grouping the labels together. compact :: DynGraph gr => gr a b -> gr a [b] -- | Compact the graph by counting how many multiple edges there are -- (considering only the two nodes and not the labels). compact' :: DynGraph gr => gr a b -> gr a Int -- | Compact the graph by adjoining identical duplicate edges. compactSame :: (Ord b, DynGraph gr) => gr a b -> gr a (Int, b) -- | Map over the labels on the nodes, using the node values as well. nlmap :: DynGraph gr => (LNode a -> c) -> gr a b -> gr c b -- | Delete these labelled nodes from the graph. delLNodes :: DynGraph gr => LNGroup a -> gr a b -> gr a b -- | Convert the graph into one with positions stored in the node labels. -- The Bool parameter denotes if the graph is directed or not. toPosGraph :: (DynGraph gr, Ord b) => Bool -> gr a b -> gr (PosLabel a) b -- | Returns the positions of the nodes in the graph, as found using -- Graphviz. The Bool parameter denotes if the graph is directed -- or not. getPositions :: (DynGraph gr, Ord b) => Bool -> gr a b -> [PosLabel a] -- | Create a cluster-lookup IntMap. createLookup :: [[Node]] -> IntMap Int -- | Used when the clusters are assigned in a lookup IntMap -- instance. setCluster :: DynGraph gr => IntMap Int -> gr a b -> gr (GenCluster a) b -- | Change the cluster values in the graph by having the largest cluster -- have the smallest cluster label. reCluster :: DynGraph g => g (GenCluster a) b -> g (GenCluster a) b -- | Change the cluster values using the given lookup IntMap. reClusterBy :: DynGraph g => IntMap Int -> g (GenCluster a) b -> g (GenCluster a) b -- | Create an IntMap of the size of each cluster. clusterCount :: Graph g => g (GenCluster a) b -> IntMap Int -- | Return true if and only if the list contains a single element. single :: [a] -> Bool -- | If we need to only tell if the list contains more than n -- elements, there's no need to find its length. longerThan :: Int -> [a] -> Bool -- | Add the length of each sublist. addLengths :: [[a]] -> [(Int, [a])] -- | Returns the longest list in a list of lists. longest :: [[a]] -> [a] lengthSort :: [[a]] -> [[a]] -- | Group elements by the given grouping function. groupElems :: Ord b => (a -> b) -> [a] -> [(b, [a])] -- | Returns the unique elements of the list in ascending order, as well as -- the minimum and maximum elements. sortMinMax :: Ord a => [a] -> ([a], a, a) -- | Shuffle a list of elements. This isn't the most efficient version, but -- should serve for small lists. Adapted from: -- http://www.cse.unsw.edu.au/~tsewell/shuffle.html The adaptation -- mainly involved altering the code so that the new random seed is also -- returned. shuffle :: RandomGen g => g -> [a] -> ([a], g) -- | An efficient mean function by Don Stewart, available from: -- http://cgi.cse.unsw.edu.au/~dons/blog/2008/05/16#fast mean :: [Double] -> Double -- | Calculate the mean and standard deviation of a list of elements. statistics :: [Double] -> (Double, Double) -- | Calculate the mean and standard deviation of a list of Int -- values. statistics' :: [Int] -> (Int, Int) -- | Find the fixed point of a function with the given initial value. fixPoint :: Eq a => (a -> a) -> a -> a -- | Find the fixed point of a graph transformation function. fixPointGraphs :: (Eq a, Eq b, Graph g) => (g a b -> g a b) -> g a b -> g a b -- | Find the fixed point of a function with the given initial value, using -- the given equality function. fixPointBy :: (a -> a -> Bool) -> (a -> a) -> a -> a -- | Functions to assist in visualising graphs and components of graphs. module Data.Graph.Analysis.Visualisation -- | Convert the GraphData into DotGraph format. graphviz :: Ord cl => GraphvizParams nl el cl l -> GraphData nl el -> DotGraph Node -- | Convert the clustered GraphData into DotGraph format. -- Cluster the nodes based upon their ClusterLabel clusters. graphvizClusters :: ClusterLabel nl => GraphvizParams nl el (Cluster nl) (NodeLabel nl) -> GraphData nl el -> DotGraph Node -- | A function to convert an LNode to the required -- LNodeCluster for use with the GraphViz library. assignCluster :: ClusterLabel cl => LNode cl -> LNodeCluster (Cluster cl) (NodeLabel cl) -- | A cross between applyDirAlg and setDirectedness. setDir :: (GraphvizParams nl el cl l -> AGr nl el -> a) -> GraphvizParams nl el cl l -> GraphData nl el -> a -- | Print a path, with "->" between each element. showPath :: Show a => [a] -> String -- | Print a path, with "->" between each element. showPath' :: (a -> String) -> [a] -> String -- | Print a cycle: copies the first node to the end of the list, and then -- calls showPath. showCycle :: Show a => [a] -> String -- | Print a cycle: copies the first node to the end of the list, and then -- calls showPath'. showCycle' :: (a -> String) -> [a] -> String -- | Show a group of nodes, with no implicit ordering. showNodes :: Show a => [a] -> String -- | Show a group of nodes, with no implicit ordering. showNodes' :: (a -> String) -> [a] -> String -- | Attempt to convert the String form of a list into as much of -- a square shape as possible, using a single space as a separation -- string. blockPrint :: Show a => [a] -> String -- | Attempt to convert a list of Strings into a single -- String that is roughly a square shape, with a single space as -- a row separator. blockPrint' :: [String] -> String -- | Attempt to convert the String form of a list into as much of -- a square shape as possible, separating values with commas. blockPrintList :: Show a => [a] -> String -- | Attempt to combine a list of Strings into as much of a square -- shape as possible, separating values with commas. blockPrintList' :: [String] -> String -- | Attempt to convert the String form of a list into as much of -- a square shape as possible, using the given separation string between -- elements in the same row. blockPrintWith :: Show a => String -> [a] -> String -- | Attempt to convert the combined form of a list of Strings -- into as much of a square shape as possible, using the given separation -- string between elements in the same row. blockPrintWith' :: String -> [String] -> String -- | Defines algorithms that work on both undirected and directed graphs. module Data.Graph.Analysis.Algorithms.Common -- | Find all connected components of a graph. componentsOf :: DynGraph g => g a b -> [g a b] -- | Find all possible paths from this given node, avoiding loops, cycles, -- etc. pathTree :: DynGraph g => Decomp g a b -> [NGroup] -- | Finds all cliques (i.e. maximal complete subgraphs) in the given -- graph. cliquesIn :: DynGraph g => g a b -> [[LNode a]] -- | Finds all cliques in the graph, without including labels. cliquesIn' :: DynGraph g => g a b -> [NGroup] -- | Find all regular subgraphs of the given graph. findRegular :: Graph g => g a b -> [[Node]] -- | Determines if the list of nodes represents a regular subgraph. isRegular :: Graph g => g a b -> NGroup -> Bool -- | Find all cycles in the given graph. cyclesIn :: DynGraph g => g a b -> [LNGroup a] -- | Find all cycles in the given graph, returning just the nodes. cyclesIn' :: DynGraph g => g a b -> [NGroup] -- | Find all cycles in the given graph, excluding those that are also -- cliques. uniqueCycles :: DynGraph g => g a b -> [LNGroup a] -- | Find all cycles in the given graph, excluding those that are also -- cliques. uniqueCycles' :: DynGraph g => g a b -> [NGroup] -- | Find all chains in the given graph. chainsIn :: (DynGraph g, Eq b) => g a b -> [LNGroup a] -- | Find all chains in the given graph. chainsIn' :: (DynGraph g, Eq b) => g a b -> [NGroup] -- | Defines algorithms that work on directed graphs. module Data.Graph.Analysis.Algorithms.Directed -- | Determine if this LNode is an ending node. endNode :: Graph g => (g a b -> Node -> NGroup) -> g a b -> LNode a -> Bool -- | Determine if this Node is an ending node. endNode' :: Graph g => (g a b -> Node -> NGroup) -> g a b -> Node -> Bool -- | Find all LNodes that meet the ending criteria. endBy :: Graph g => (g a b -> Node -> NGroup) -> g a b -> LNGroup a -- | Find all Nodes that match the ending criteria. endBy' :: Graph g => (g a b -> Node -> NGroup) -> g a b -> NGroup -- | Find all roots of the graph. rootsOf :: Graph g => g a b -> LNGroup a -- | Find all roots of the graph. rootsOf' :: Graph g => g a b -> NGroup -- | Returns True if this LNode is a root. isRoot :: Graph g => g a b -> LNode a -> Bool -- | Returns True if this Node is a root. isRoot' :: Graph g => g a b -> Node -> Bool -- | Find all leaves of the graph. leavesOf :: Graph g => g a b -> LNGroup a -- | Find all leaves of the graph. leavesOf' :: Graph g => g a b -> NGroup -- | Returns True if this LNode is a leaf. isLeaf :: Graph g => g a b -> LNode a -> Bool -- | Returns True if this Node is a leaf. isLeaf' :: Graph g => g a b -> Node -> Bool -- | Find all singletons of the graph. singletonsOf :: Graph g => g a b -> LNGroup a -- | Find all singletons of the graph. singletonsOf' :: Graph g => g a b -> NGroup -- | Returns True if this LNode is a singleton. isSingleton :: Graph g => g a b -> LNode a -> Bool -- | Returns True if this Node is a singleton. isSingleton' :: Graph g => g a b -> Node -> Bool -- | The core of the graph is the part of the graph containing all -- the cycles, etc. Depending on the context, it could be interpreted as -- the part of the graph where all the work is done. coreOf :: (DynGraph g, Eq a, Eq b) => g a b -> g a b -- | Cluster the nodes in the graph based upon how far away they are from a -- root node. Root nodes are in the cluster labelled minLevel, -- nodes in level "n" (with n > minLevel) are at least -- n edges away from a root node. levelGraph :: (Ord a, DynGraph g) => g a b -> g (GenCluster a) b -- | As with levelGraph but provide a custom grouping of -- Nodes to consider as the "roots". levelGraphFrom :: (Ord a, DynGraph g) => NGroup -> g a b -> g (GenCluster a) b -- | The level of the nodes in the NGroup provided to -- levelGraphFrom (or the root nodes for levelGraph). A -- level less than this indicates that the node is not accessible. minLevel :: Int -- | Find all Nodes that can be reached from the provided -- Nodes. accessibleFrom :: Graph g => g a b -> [Node] -> [Node] -- | Find all Nodes that can be reached from the provided nodes -- using Sets rather than lists. accessibleFrom' :: Graph g => g a b -> Set Node -> Set Node -- | Find those Nodes that are reachable only from the provided -- Nodes. accessibleOnlyFrom :: Graph g => g a b -> [Node] -> [Node] -- | Find those Nodes that are reachable only from the provided -- Nodes, using Sets rather than lists. accessibleOnlyFrom' :: Graph g => g a b -> Set Node -> Set Node -- | The shortest paths to each of the leaves in the graph (excluding -- singletons). This can be used to obtain an indication of the overall -- height/depth of the graph. leafMinPaths :: Graph g => g a b -> [LNGroup a] -- | The shortest paths to each of the leaves in the graph (excluding -- singletons). This can be used to obtain an indication of the overall -- height/depth of the graph. leafMinPaths' :: Graph g => g a b -> [NGroup] -- | Clustering and grouping algorithms that are graph-invariant and -- require no user intervention. -- -- For a clustering algorithm that works only on directed graphs, see -- levelGraph in Data.Graph.Analysis.Algorithms.Directed. module Data.Graph.Analysis.Algorithms.Clustering -- | The actual Chinese Whispers algorithm. chineseWhispers :: (RandomGen g, Eq a, Eq b, DynGraph gr) => g -> gr a b -> gr (GenCluster a) b -- | The renamed CLUSTER algorithm. Attempts to cluster a graph by using -- the spatial locations used by Graphviz. relativeNeighbourhood :: (DynGraph gr, Eq a, Ord b) => Bool -> gr a b -> gr (GenCluster a) b -- | A collapsed node contains a list of nodes that it represents. type CNodes a = [a] -- | Collapse the cliques, cycles and chains in the graph down. Note that -- this doesn't work too well on undirected graphs, since every pair of -- nodes forms a K_2 subgraph. collapseGraph :: (DynGraph gr, Eq b) => gr a b -> gr (CNodes a) b -- | Use the given functions to determine which nodes to collapse. collapseGraphBy :: DynGraph gr => [gr (CNodes a) b -> [NGroup]] -> gr a b -> gr (CNodes a) b -- | Use the given functions to determine which nodes to collapse, with a -- new label to represent the collapsed nodes. collapseAndReplace :: DynGraph gr => [gr a b -> [(NGroup, a)]] -> gr a b -> gr a b -- | As with collapseAndReplace, but also return the -- (NGroup, a)'s calculated with the functions provided. collapseAndReplace' :: DynGraph gr => [gr a b -> [(NGroup, a)]] -> gr a b -> (gr a b, [(NGroup, a)]) -- | Return True if the collapsed graph is either a -- singleton node or else isomorphic to the original graph (i.e. not -- collapsed at all). trivialCollapse :: Graph gr => gr (CNodes a) b -> Bool instance Eq a => Metric (PosLabel a) -- | This module exports all the algorithms found in the -- Data.Graph.Analysis.Algorithms.* modules. module Data.Graph.Analysis.Algorithms -- | This is the root module of the Graphalyze library, which aims -- to provide a way of analysing the relationships inherent in discrete -- data as a graph. -- -- The original version of this library was written as part of my -- mathematics honours thesis, Graph-Theoretic Analysis of the -- Relationships in Discrete Data. module Data.Graph.Analysis -- | The library version. version :: String -- | This represents the information that's being passed in that we want to -- analyse. If the graph is undirected, it is better to list each edge -- once rather than both directions. data ImportParams n e ImpParams :: [n] -> [Rel n e] -> [n] -> Bool -> ImportParams n e -- | The discrete points. dataPoints :: ImportParams n e -> [n] -- | The relationships between the points. relationships :: ImportParams n e -> [Rel n e] -- | The expected roots of the graph. If directed = -- False, then this is ignored. roots :: ImportParams n e -> [n] -- | False if relationships are symmetric (i.e. an undirected -- graph). directed :: ImportParams n e -> Bool -- | Import data into a format suitable for analysis. This function is -- edge-safe: if any datums are listed in the edges of -- ImportParams that aren't listed in the data points, then those -- edges are ignored. Thus, no sanitation of the relationships in -- ImportParams is necessary. The unused relations are stored in -- unusedRelationships. Note that it is assumed that all datums in -- roots are also contained within dataPoints. importData :: (Ord n, Ord e) => ImportParams n e -> GraphData n e -- | Returns the mean and standard deviations of the lengths of the -- sublists, as well all those lists more than one standard deviation -- longer than the mean. lengthAnalysis :: [[a]] -> (Int, Int, [(Int, [a])]) -- | Compare the actual roots in the graph with those that are expected -- (i.e. those in wantedRootNodes). Returns (in order): -- -- classifyRoots :: GraphData n e -> (Set Node, Set Node, Set Node) -- | Find the nodes that are not reachable from the expected roots (i.e. -- those in wantedRootNodes). inaccessibleNodes :: GraphData n e -> Set Node -- | Only return those chains (see chainsIn) where the non-initial -- nodes are not expected roots. interiorChains :: (Eq n, Eq e) => GraphData n e -> [LNGroup n] -- | As with collapseAndReplace, but also update the -- wantedRootNodes to contain the possibly compressed nodes. Since -- the datums they refer to may no longer exist (as they are compressed), -- unusedRelationships is set to []. collapseAndUpdate :: Ord n => [AGr n e -> [(NGroup, n)]] -> GraphData n e -> GraphData n e -- | As with collapseAndUpdate, but also includes a lookup -- Map from the old label to the new. collapseAndUpdate' :: Ord n => [AGr n e -> [(NGroup, n)]] -> GraphData n e -> (GraphData n e, Map n n) -- | As with levelGraph, but use the expected roots rather than the -- actual roots. levelGraphFromRoot :: Ord n => GraphData n e -> GraphData (GenCluster n) e