-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Martin Erwig's Functional Graph Library -- @package fgl @version 5.5.2.0 -- | Threading Combinators. module Data.Graph.Inductive.Internal.Thread type Split t i r = i -> t -> (r, t) type SplitM t i r = Split t i (Maybe r) type Thread t i r = (t, Split t i r) type Collect r c = (r -> c -> c, c) threadList' :: Collect r c -> Split t i r -> [i] -> t -> (c, t) threadList :: Collect r c -> Split t i r -> [i] -> t -> (c, t) threadMaybe' :: (r -> a) -> Split t i r -> Split t j (Maybe i) -> Split t j (Maybe a) threadMaybe :: (i -> r -> a) -> Split t i r -> SplitM t j i -> SplitM t j a splitPar :: Split t i r -> Split u j s -> Split (t, u) (i, j) (r, s) splitParM :: SplitM t i r -> Split u j s -> SplitM (t, u) (i, j) (r, s) -- | Static and Dynamic Inductive Graphs module Data.Graph.Inductive.Graph -- | Unlabeled node type Node = Int -- | Labeled node type LNode a = (Node, a) -- | Quasi-unlabeled node type UNode = LNode () -- | Unlabeled edge type Edge = (Node, Node) -- | Labeled edge type LEdge b = (Node, Node, b) -- | Quasi-unlabeled edge type UEdge = LEdge () -- | Labeled links to or from a Node. type Adj b = [(b, Node)] -- | Links to the Node, the Node itself, a label, links from -- the Node. type Context a b = (Adj b, Node, a, Adj b) type MContext a b = Maybe (Context a b) -- | Graph decomposition - the context removed from a Graph, -- and the rest of the Graph. type Decomp g a b = (MContext a b, g a b) -- | The same as Decomp, only more sure of itself. type GDecomp g a b = (Context a b, g a b) -- | Unlabeled context. type UContext = ([Node], Node, [Node]) -- | Unlabeled decomposition. type UDecomp g = (Maybe UContext, g) -- | Unlabeled path type Path = [Node] -- | Labeled path newtype LPath a LP :: [LNode a] -> LPath a unLPath :: LPath a -> [LNode a] -- | Quasi-unlabeled path type UPath = [UNode] -- | Minimum implementation: empty, isEmpty, match, -- mkGraph, labNodes class Graph gr where matchAny g = case labNodes g of { [] -> error "Match Exception, Empty Graph" (v, _) : _ -> (c, g') where (Just c, g') = match v g } noNodes = length . labNodes nodeRange g | isEmpty g = error "nodeRange of empty graph" | otherwise = (minimum vs, maximum vs) where vs = nodes g labEdges = ufold (\ (_, v, _, s) -> (map (\ (l, w) -> (v, w, l)) s ++)) [] empty :: Graph gr => gr a b isEmpty :: Graph gr => gr a b -> Bool match :: Graph gr => Node -> gr a b -> Decomp gr a b mkGraph :: Graph gr => [LNode a] -> [LEdge b] -> gr a b labNodes :: Graph gr => gr a b -> [LNode a] matchAny :: Graph gr => gr a b -> GDecomp gr a b noNodes :: Graph gr => gr a b -> Int nodeRange :: Graph gr => gr a b -> (Node, Node) labEdges :: Graph gr => gr a b -> [LEdge b] class Graph gr => DynGraph gr (&) :: DynGraph gr => Context a b -> gr a b -> gr a b -- | Fold a function over the graph. ufold :: Graph gr => (Context a b -> c -> c) -> c -> gr a b -> c -- | Map a function over the graph. gmap :: DynGraph gr => (Context a b -> Context c d) -> gr a b -> gr c d -- | Map a function over the Node labels in a graph. nmap :: DynGraph gr => (a -> c) -> gr a b -> gr c b -- | Map a function over the Edge labels in a graph. emap :: DynGraph gr => (b -> c) -> gr a b -> gr a c -- | Map functions over both the Node and Edge labels in a -- graph. nemap :: DynGraph gr => (a -> c) -> (b -> d) -> gr a b -> gr c d -- | List all Nodes in the Graph. nodes :: Graph gr => gr a b -> [Node] -- | List all Edges in the Graph. edges :: Graph gr => gr a b -> [Edge] -- | Drop the label component of an edge. toEdge :: LEdge b -> Edge -- | The label in an edge. edgeLabel :: LEdge b -> b -- | Add a label to an edge. toLEdge :: Edge -> b -> LEdge b -- | List N available Nodes, i.e. Nodes that are not used in -- the Graph. newNodes :: Graph gr => Int -> gr a b -> [Node] -- | True if the Node is present in the Graph. gelem :: Graph gr => Node -> gr a b -> Bool -- | Insert a LNode into the Graph. insNode :: DynGraph gr => LNode a -> gr a b -> gr a b -- | Insert a LEdge into the Graph. insEdge :: DynGraph gr => LEdge b -> gr a b -> gr a b -- | Remove a Node from the Graph. delNode :: Graph gr => Node -> gr a b -> gr a b -- | Remove an Edge from the Graph. -- -- NOTE: in the case of multiple edges, this will delete all such -- edges from the graph as there is no way to distinguish between them. -- If you need to delete only a single such edge, please use -- delLEdge. delEdge :: DynGraph gr => Edge -> gr a b -> gr a b -- | Remove an LEdge from the Graph. -- -- NOTE: in the case of multiple edges with the same label, this will -- only delete the first such edge. To delete all such edges, -- please use delAllLedges. delLEdge :: (DynGraph gr, Eq b) => LEdge b -> gr a b -> gr a b -- | Remove all edges equal to the one specified. delAllLEdge :: (DynGraph gr, Eq b) => LEdge b -> gr a b -> gr a b -- | Insert multiple LNodes into the Graph. insNodes :: DynGraph gr => [LNode a] -> gr a b -> gr a b -- | Insert multiple LEdges into the Graph. insEdges :: DynGraph gr => [LEdge b] -> gr a b -> gr a b -- | Remove multiple Nodes from the Graph. delNodes :: Graph gr => [Node] -> gr a b -> gr a b -- | Remove multiple Edges from the Graph. delEdges :: DynGraph gr => [Edge] -> gr a b -> gr a b -- | Build a Graph from a list of Contexts. -- -- The list should be in the order such that earlier Contexts -- depend upon later ones (i.e. as produced by ufold (:) -- []). buildGr :: DynGraph gr => [Context a b] -> gr a b -- | Build a quasi-unlabeled Graph. mkUGraph :: Graph gr => [Node] -> [Edge] -> gr () () -- | Build a graph out of the contexts for which the predicate is true. gfiltermap :: DynGraph gr => (Context a b -> MContext c d) -> gr a b -> gr c d -- | Returns the subgraph only containing the nodes which satisfy the given -- predicate. nfilter :: DynGraph gr => (Node -> Bool) -> gr a b -> gr a b -- | Returns the subgraph only containing the labelled nodes which satisfy -- the given predicate. labnfilter :: Graph gr => (LNode a -> Bool) -> gr a b -> gr a b -- | Returns the subgraph only containing the nodes whose labels satisfy -- the given predicate. labfilter :: DynGraph gr => (a -> Bool) -> gr a b -> gr a b -- | Returns the subgraph induced by the supplied nodes. subgraph :: DynGraph gr => [Node] -> gr a b -> gr a b -- | Find the context for the given Node. Causes an error if the -- Node is not present in the Graph. context :: Graph gr => gr a b -> Node -> Context a b -- | Find the label for a Node. lab :: Graph gr => gr a b -> Node -> Maybe a -- | Find the neighbors for a Node. neighbors :: Graph gr => gr a b -> Node -> [Node] -- | Find the labelled links coming into or going from a Context. lneighbors :: Graph gr => gr a b -> Node -> Adj b -- | Find all Nodes that have a link from the given Node. suc :: Graph gr => gr a b -> Node -> [Node] -- | Find all Nodes that link to to the given Node. pre :: Graph gr => gr a b -> Node -> [Node] -- | Find all Nodes that are linked from the given Node and -- the label of each link. lsuc :: Graph gr => gr a b -> Node -> [(Node, b)] -- | Find all Nodes that link to the given Node and the label -- of each link. lpre :: Graph gr => gr a b -> Node -> [(Node, b)] -- | Find all outward-bound LEdges for the given Node. out :: Graph gr => gr a b -> Node -> [LEdge b] -- | Find all inward-bound LEdges for the given Node. inn :: Graph gr => gr a b -> Node -> [LEdge b] -- | The outward-bound degree of the Node. outdeg :: Graph gr => gr a b -> Node -> Int -- | The inward-bound degree of the Node. indeg :: Graph gr => gr a b -> Node -> Int -- | The degree of the Node. deg :: Graph gr => gr a b -> Node -> Int -- | Checks if there is a directed edge between two nodes. hasEdge :: Graph gr => gr a b -> Edge -> Bool -- | Checks if there is an undirected edge between two nodes. hasNeighbor :: Graph gr => gr a b -> Node -> Node -> Bool -- | Checks if there is a labelled edge between two nodes. hasLEdge :: (Graph gr, Eq b) => gr a b -> LEdge b -> Bool -- | Checks if there is an undirected labelled edge between two nodes. hasNeighborAdj :: (Graph gr, Eq b) => gr a b -> Node -> (b, Node) -> Bool equal :: (Eq a, Eq b, Graph gr) => gr a b -> gr a b -> Bool -- | The Node in a Context. node' :: Context a b -> Node -- | The label in a Context. lab' :: Context a b -> a -- | The LNode from a Context. labNode' :: Context a b -> LNode a -- | All Nodes linked to or from in a Context. neighbors' :: Context a b -> [Node] -- | All labelled links coming into or going from a Context. lneighbors' :: Context a b -> Adj b -- | All Nodes linked to in a Context. suc' :: Context a b -> [Node] -- | All Nodes linked from in a Context. pre' :: Context a b -> [Node] -- | All Nodes linked from in a Context, and the label of the -- links. lpre' :: Context a b -> [(Node, b)] -- | All Nodes linked from in a Context, and the label of the -- links. lsuc' :: Context a b -> [(Node, b)] -- | All outward-directed LEdges in a Context. out' :: Context a b -> [LEdge b] -- | All inward-directed LEdges in a Context. inn' :: Context a b -> [LEdge b] -- | The outward degree of a Context. outdeg' :: Context a b -> Int -- | The inward degree of a Context. indeg' :: Context a b -> Int -- | The degree of a Context. deg' :: Context a b -> Int -- | Pretty-print the graph. Note that this loses a lot of information, -- such as edge inverses, etc. prettify :: (DynGraph gr, Show a, Show b) => gr a b -> String -- | Pretty-print the graph to stdout. prettyPrint :: (DynGraph gr, Show a, Show b) => gr a b -> IO () -- | OrdGr comes equipped with an Ord instance, so that graphs can be used -- as e.g. Map keys. newtype OrdGr gr a b OrdGr :: gr a b -> OrdGr gr a b unOrdGr :: OrdGr gr a b -> gr a b instance Show b => Show (GroupEdges b) instance Read b => Read (GroupEdges b) instance Read (gr a b) => Read (OrdGr gr a b) instance Show (gr a b) => Show (OrdGr gr a b) instance (Graph gr, Ord a, Ord b) => Ord (OrdGr gr a b) instance (Graph gr, Ord a, Ord b) => Eq (OrdGr gr a b) instance Eq b => Eq (GroupEdges b) instance Ord a => Ord (LPath a) instance Eq a => Eq (LPath a) instance Show a => Show (LPath a) -- | Basic Graph Algorithms module Data.Graph.Inductive.Basic -- | Reverse the direction of all edges. grev :: DynGraph gr => gr a b -> gr a b -- | Make the graph undirected, i.e. for every edge from A to B, there -- exists an edge from B to A. undir :: (Eq b, DynGraph gr) => gr a b -> gr a b -- | Remove all labels. unlab :: DynGraph gr => gr a b -> gr () () -- | Return all Contexts for which the given function returns -- True. gsel :: Graph gr => (Context a b -> Bool) -> gr a b -> [Context a b] -- | Directed graph fold. gfold :: Graph gr => (Context a b -> [Node]) -> (Context a b -> c -> d) -> (Maybe d -> c -> c, c) -> [Node] -> gr a b -> c -- | Filter based on edge property. efilter :: DynGraph gr => (LEdge b -> Bool) -> gr a b -> gr a b -- | Filter based on edge label property. elfilter :: DynGraph gr => (b -> Bool) -> gr a b -> gr a b -- | True if the graph has any edges of the form (A, A). hasLoop :: Graph gr => gr a b -> Bool -- | The inverse of hasLoop. isSimple :: Graph gr => gr a b -> Bool -- | Flatten a Tree, returning the elements in post-order. postorder :: Tree a -> [a] -- | Flatten multiple Trees in post-order. postorderF :: [Tree a] -> [a] -- | Flatten a Tree, returning the elements in pre-order. Equivalent -- to flatten in Tree. preorder :: Tree a -> [a] -- | Flatten multiple Trees in pre-order. preorderF :: [Tree a] -> [a] -- | An efficient implementation of Graph using big-endian patricia -- tree (i.e. Data.IntMap). -- -- This module provides the following specialised functions to gain more -- performance, using GHC's RULES pragma: -- --
module Data.Graph.Inductive.PatriciaTree data Gr a b type UGr = Gr () () instance Generic (Gr a b) instance Datatype D1Gr instance Constructor C1_0Gr instance (NFData a, NFData b) => NFData (Gr a b) instance DynGraph Gr instance Graph Gr instance (Read a, Read b) => Read (Gr a b) instance (Show a, Show b) => Show (Gr a b) instance (Eq a, Ord b) => Eq (Gr a b) -- | Monadic Graphs module Data.Graph.Inductive.Monad class Monad m => GraphM m gr where matchAnyM g = do { vs <- labNodesM g; case vs of { [] -> fail "Match Exception, Empty Graph" (v, _) : _ -> do { (Just c, g') <- matchM v g; return (c, g') } } } noNodesM = labNodesM >>. length nodeRangeM g = do { isE <- isEmptyM g; if isE then fail "nodeRangeM of empty graph" else do { vs <- nodesM g; return (minimum vs, maximum vs) } } labEdgesM = ufoldM (\ (p, v, _, s) -> ((map (i v) p ++ map (o v) s) ++)) [] where o v = \ (l, w) -> (v, w, l) i v = \ (l, w) -> (w, v, l) emptyM :: GraphM m gr => m (gr a b) isEmptyM :: GraphM m gr => m (gr a b) -> m Bool matchM :: GraphM m gr => Node -> m (gr a b) -> m (Decomp gr a b) mkGraphM :: GraphM m gr => [LNode a] -> [LEdge b] -> m (gr a b) labNodesM :: GraphM m gr => m (gr a b) -> m [LNode a] matchAnyM :: GraphM m gr => m (gr a b) -> m (GDecomp gr a b) noNodesM :: GraphM m gr => m (gr a b) -> m Int nodeRangeM :: GraphM m gr => m (gr a b) -> m (Node, Node) labEdgesM :: GraphM m gr => m (gr a b) -> m [LEdge b] -- | graph fold ufoldM :: GraphM m gr => (Context a b -> c -> c) -> c -> m (gr a b) -> m c nodesM :: GraphM m gr => m (gr a b) -> m [Node] edgesM :: GraphM m gr => m (gr a b) -> m [Edge] newNodesM :: GraphM m gr => Int -> m (gr a b) -> m [Node] delNodeM :: GraphM m gr => Node -> m (gr a b) -> m (gr a b) delNodesM :: GraphM m gr => [Node] -> m (gr a b) -> m (gr a b) mkUGraphM :: GraphM m gr => [Node] -> [Edge] -> m (gr () ()) contextM :: GraphM m gr => m (gr a b) -> Node -> m (Context a b) labM :: GraphM m gr => m (gr a b) -> Node -> m (Maybe a) -- | Static IOArray-based Graphs module Data.Graph.Inductive.Monad.IOArray newtype SGr a b SGr :: (GraphRep a b) -> SGr a b type GraphRep a b = (Int, Array Node (Context' a b), IOArray Node Bool) type Context' a b = Maybe (Adj b, a, Adj b) type USGr = SGr () () defaultGraphSize :: Int emptyN :: Int -> IO (SGr a b) -- | filter list (of successors/predecessors) through a boolean ST array -- representing deleted marks removeDel :: IOArray Node Bool -> Adj b -> IO (Adj b) instance GraphM IO SGr instance (Show a, Show b) => Show (IO (SGr a b)) instance (Show a, Show b) => Show (SGr a b) -- | Example Graphs module Data.Graph.Inductive.Example -- | generate list of unlabeled nodes genUNodes :: Int -> [UNode] -- | generate list of labeled nodes genLNodes :: Enum a => a -> Int -> [LNode a] -- | denote unlabeled edges labUEdges :: [Edge] -> [UEdge] -- | empty (unlabeled) edge list noEdges :: [UEdge] a :: Gr Char () b :: Gr Char () c :: Gr Char () e :: Gr Char () loop :: Gr Char () ab :: Gr Char () abb :: Gr Char () dag3 :: Gr Char () e3 :: Gr () String cyc3 :: Gr Char String g3 :: Gr Char String g3b :: Gr Char String dag4 :: Gr Int () d1 :: Gr Int Int d3 :: Gr Int Int a' :: IO (SGr Char ()) b' :: IO (SGr Char ()) c' :: IO (SGr Char ()) e' :: IO (SGr Char ()) loop' :: IO (SGr Char ()) ab' :: IO (SGr Char ()) abb' :: IO (SGr Char ()) dag3' :: IO (SGr Char ()) e3' :: IO (SGr () String) dag4' :: IO (SGr Int ()) d1' :: IO (SGr Int Int) d3' :: IO (SGr Int Int) ucycle :: Graph gr => Int -> gr () () star :: Graph gr => Int -> gr () () ucycleM :: GraphM m gr => Int -> m (gr () ()) starM :: GraphM m gr => Int -> m (gr () ()) clr479 :: Gr Char () clr489 :: Gr Char () clr486 :: Gr String () clr508 :: Gr Char Int clr528 :: Gr Char Int clr595 :: Gr Int Int gr1 :: Gr Int Int kin248 :: Gr Int () vor :: Gr String Int clr479' :: IO (SGr Char ()) clr489' :: IO (SGr Char ()) clr486' :: IO (SGr String ()) clr508' :: IO (SGr Char Int) clr528' :: IO (SGr Char Int) kin248' :: IO (SGr Int ()) vor' :: IO (SGr String Int) -- | Utility methods to automatically generate and keep track of a mapping -- between node labels and Nodes. module Data.Graph.Inductive.NodeMap data NodeMap a -- | Create a new, empty mapping. new :: NodeMap a -- | Generate a mapping containing the nodes in the given graph. fromGraph :: (Ord a, Graph g) => g a b -> NodeMap a -- | Generate a labelled node from the given label. Will return the same -- node for the same label. mkNode :: Ord a => NodeMap a -> a -> (LNode a, NodeMap a) -- | Generate a labelled node and throw away the modified NodeMap. mkNode_ :: Ord a => NodeMap a -> a -> LNode a -- | Construct a list of nodes. mkNodes :: Ord a => NodeMap a -> [a] -> ([LNode a], NodeMap a) -- | Construct a list of nodes and throw away the modified NodeMap. mkNodes_ :: Ord a => NodeMap a -> [a] -> [LNode a] -- | Generate a LEdge from the node labels. mkEdge :: Ord a => NodeMap a -> (a, a, b) -> Maybe (LEdge b) -- | Generates a list of LEdges. mkEdges :: Ord a => NodeMap a -> [(a, a, b)] -> Maybe [LEdge b] insMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> (g a b, NodeMap a, LNode a) insMapNode_ :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b insMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a, b) -> g a b -> g a b delMapNode :: (Ord a, DynGraph g) => NodeMap a -> a -> g a b -> g a b delMapEdge :: (Ord a, DynGraph g) => NodeMap a -> (a, a) -> g a b -> g a b insMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> (g a b, NodeMap a, [LNode a]) insMapNodes_ :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b insMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a, b)] -> g a b -> g a b delMapNodes :: (Ord a, DynGraph g) => NodeMap a -> [a] -> g a b -> g a b delMapEdges :: (Ord a, DynGraph g) => NodeMap a -> [(a, a)] -> g a b -> g a b mkMapGraph :: (Ord a, DynGraph g) => [a] -> [(a, a, b)] -> (g a b, NodeMap a) -- | Graph construction monad; handles passing both the NodeMap and -- the Graph. type NodeMapM a b g r = State (NodeMap a, g a b) r -- | Run a construction; return the value of the computation, the modified -- NodeMap, and the modified Graph. run :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> (r, (NodeMap a, g a b)) -- | Run a construction and only return the Graph. run_ :: (DynGraph g, Ord a) => g a b -> NodeMapM a b g r -> g a b -- | Monadic node construction. mkNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g (LNode a) mkNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g [LNode a] mkEdgeM :: (Ord a, DynGraph g) => (a, a, b) -> NodeMapM a b g (Maybe (LEdge b)) mkEdgesM :: (Ord a, DynGraph g) => [(a, a, b)] -> NodeMapM a b g (Maybe [LEdge b]) insMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g (LNode a) insMapEdgeM :: (Ord a, DynGraph g) => (a, a, b) -> NodeMapM a b g () delMapNodeM :: (Ord a, DynGraph g) => a -> NodeMapM a b g () delMapEdgeM :: (Ord a, DynGraph g) => (a, a) -> NodeMapM a b g () insMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g [LNode a] insMapEdgesM :: (Ord a, DynGraph g) => [(a, a, b)] -> NodeMapM a b g () delMapNodesM :: (Ord a, DynGraph g) => [a] -> NodeMapM a b g () delMapEdgesM :: (Ord a, DynGraph g) => [(a, a)] -> NodeMapM a b g () instance Eq a => Eq (NodeMap a) instance Show a => Show (NodeMap a) instance (Ord a, Read a) => Read (NodeMap a) instance NFData a => NFData (NodeMap a) module Data.Graph.Inductive.Query.ArtPoint -- | Finds the articulation points for a connected undirected graph, by -- using the low numbers criteria: -- -- a) The root node is an articulation point iff it has two or more -- children. -- -- b) An non-root node v is an articulation point iff there exists at -- least one child w of v such that lowNumber(w) >= dfsNumber(v). ap :: Graph gr => gr a b -> [Node] instance Eq a => Eq (DFSTree a) instance Show a => Show (DFSTree a) instance Read a => Read (DFSTree a) instance Eq a => Eq (LOWTree a) instance Show a => Show (LOWTree a) instance Read a => Read (LOWTree a) -- | Depth-first search algorithms. -- -- Names consist of: -- ---- xdfsWith d f vs = preorderF . xdffWith d f vs --xdfsWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> [c] -- | 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. xdfWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> ([Tree c], gr a b) -- | Discard the graph part of the result of xdfWith. -- --
-- xdffWith d f vs g = fst (xdfWith d f vs g) --xdffWith :: Graph gr => CFun a b [Node] -> CFun a b c -> [Node] -> gr a b -> [Tree c] -- | Undirected depth-first search, obtained by following edges regardless -- of their direction. udfs :: Graph gr => [Node] -> gr a b -> [Node] udfs' :: Graph gr => gr a b -> [Node] -- | Undirected depth-first forest, obtained by following edges regardless -- of their direction. 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] -- | Reverse depth-first forest, obtained by following predecessors. rdff :: Graph gr => [Node] -> gr a b -> [Tree Node] rdff' :: Graph gr => gr a b -> [Tree Node] -- | Reverse depth-first search, obtained by following predecessors. 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] -- | Topological sorting, i.e. a list of Nodes 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 -> [Node] -- | topsort, returning only the labels of the nodes. topsort' :: Graph gr => gr a b -> [a] -- | Collection of strongly connected components scc :: Graph gr => gr a b -> [[Node]] -- | Collection of nodes reachable from a starting point. reachable :: Graph gr => Node -> gr a b -> [Node] -- | Collection of connected components components :: Graph gr => gr a b -> [[Node]] -- | Number of connected components noComponents :: Graph gr => gr a b -> Int -- | Is the graph connected? isConnected :: Graph gr => gr a b -> Bool -- | The condensation of the given graph, i.e., the graph of its strongly -- connected components. condensation :: Graph gr => gr a b -> gr [Node] () module Data.Graph.Inductive.Query.BCC -- | Finds the bi-connected components of an undirected connected graph. It -- first finds the articulation points of the graph. Then it disconnects -- the graph on each articulation point and computes the connected -- components. bcc :: DynGraph gr => gr a b -> [gr a b] module Data.Graph.Inductive.Query.Dominators -- | return the set of dominators of the nodes of a graph, given a root dom :: Graph gr => gr a b -> Node -> [(Node, [Node])] -- | return immediate dominators for each node of a graph, given a root iDom :: Graph gr => gr a b -> Node -> [(Node, Node)] -- | Maximum Independent Node Sets module Data.Graph.Inductive.Query.Indep -- | Calculate the maximum independent node set of the specified graph. indep :: DynGraph gr => gr a b -> [Node] -- | The maximum independent node set along with its size. indepSize :: DynGraph gr => gr a b -> ([Node], Int) -- | Monadic Graph Algorithms module Data.Graph.Inductive.Query.Monad mapFst :: (a -> b) -> (a, c) -> (b, c) mapSnd :: (a -> b) -> (c, a) -> (c, b) (><) :: (a -> b) -> (c -> d) -> (a, c) -> (b, d) orP :: (a -> Bool) -> (b -> Bool) -> (a, b) -> Bool newtype GT m g a MGT :: (m g -> m (a, g)) -> GT m g a apply :: GT m g a -> m g -> m (a, g) apply' :: Monad m => GT m g a -> g -> m (a, g) applyWith :: Monad m => (a -> b) -> GT m g a -> m g -> m (b, g) applyWith' :: Monad m => (a -> b) -> GT m g a -> g -> m (b, g) runGT :: Monad m => GT m g a -> m g -> m a condMGT' :: Monad m => (s -> Bool) -> GT m s a -> GT m s a -> GT m s a recMGT' :: Monad m => (s -> Bool) -> GT m s a -> (a -> b -> b) -> b -> GT m s b condMGT :: Monad m => (m s -> m Bool) -> GT m s a -> GT m s a -> GT m s a recMGT :: Monad m => (m s -> m Bool) -> GT m s a -> (a -> b -> b) -> b -> GT m s b getNode :: GraphM m gr => GT m (gr a b) Node getContext :: GraphM m gr => GT m (gr a b) (Context a b) getNodes' :: (Graph gr, GraphM m gr) => GT m (gr a b) [Node] getNodes :: GraphM m gr => GT m (gr a b) [Node] sucGT :: GraphM m gr => Node -> GT m (gr a b) (Maybe [Node]) sucM :: GraphM m gr => Node -> m (gr a b) -> m (Maybe [Node]) -- | encapsulates a simple recursion schema on graphs graphRec :: GraphM m gr => GT m (gr a b) c -> (c -> d -> d) -> d -> GT m (gr a b) d graphRec' :: (Graph gr, GraphM m gr) => GT m (gr a b) c -> (c -> d -> d) -> d -> GT m (gr a b) d graphUFold :: GraphM m gr => (Context a b -> c -> c) -> c -> GT m (gr a b) c graphNodesM0 :: GraphM m gr => GT m (gr a b) [Node] graphNodesM :: GraphM m gr => GT m (gr a b) [Node] graphNodes :: GraphM m gr => m (gr a b) -> m [Node] graphFilterM :: GraphM m gr => (Context a b -> Bool) -> GT m (gr a b) [Context a b] graphFilter :: GraphM m gr => (Context a b -> Bool) -> m (gr a b) -> m [Context a b] -- | Monadic graph algorithms are defined in two steps: -- --
-- For all u,v in V, f(u,v)<=c(u,v)
-- For all u,v in V, f(u,v)=-f(v,u)
-- For all u in V-{s,t}, Sum{f(u,v):v in V } = 0
--
--
-- The value of a flow f is defined as |f|=Sum {f(s,v)|v in V},
-- i.e., the total net flow out of the source.
--
-- In this module we implement the Edmonds-Karp algorithm, which is the
-- Ford-Fulkerson method but using the shortest path from s to
-- t as the augmenting path along which the flow is incremented.
module Data.Graph.Inductive.Query.MaxFlow
-- | -- i 0 -- For each edge a--->b this function returns edge b--->a . -- i -- Edges a<--->b are ignored -- j --getRevEdges :: Num b => [Edge] -> [LEdge b] -- |
-- i 0 -- For each edge a--->b insert into graph the edge a<---b . Then change the -- i (i,0,i) -- label of every edge from a---->b to a------->b ---- -- where label (x,y,z)=(Max Capacity, Current flow, Residual capacity) augmentGraph :: (DynGraph gr, Num b) => gr a b -> gr a (b, b, b) -- | Given a successor or predecessor list for node u and given -- node v, find the label corresponding to edge (u,v) -- and update the flow and residual capacity of that edge's label. Then -- return the updated list. updAdjList :: Num b => Adj (b, b, b) -> Node -> b -> Bool -> Adj (b, b, b) -- | Update flow and residual capacity along augmenting path from -- s to t in graph @G. For a path -- [u,v,w,...] find the node u in G and its -- successor and predecessor list, then update the corresponding edges -- (u,v) and (v,u)@ on those lists by using the minimum -- residual capacity of the path. updateFlow :: (DynGraph gr, Num b) => Path -> b -> gr a (b, b, b) -> gr a (b, b, b) -- | Compute the flow from s to t on a graph whose edges -- are labeled with (x,y,z)=(max capacity,current flow,residual -- capacity) and all edges are of the form a<---->b. -- First compute the residual graph, that is, delete those edges whose -- residual capacity is zero. Then compute the shortest augmenting path -- from s to t, and finally update the flow and -- residual capacity along that path by using the minimum capacity of -- that path. Repeat this process until no shortest path from s -- to t exist. mfmg :: (DynGraph gr, Num b, Ord b) => gr a (b, b, b) -> Node -> Node -> gr a (b, b, b) -- | Compute the flow from s to t on a graph whose edges are labeled with -- x, which is the max capacity and where not all edges need to -- be of the form a<---->b. Return the flow as a grap whose edges -- are labeled with (x,y,z)=(max capacity,current flow,residual capacity) -- and all edges are of the form a<---->b mf :: (DynGraph gr, Num b, Ord b) => gr a b -> Node -> Node -> gr a (b, b, b) -- | Compute the maximum flow from s to t on a graph whose edges are -- labeled with x, which is the max capacity and where not all edges need -- to be of the form a<---->b. Return the flow as a graph whose -- edges are labeled with (y,x) = (current flow, max capacity). maxFlowgraph :: (DynGraph gr, Num b, Ord b) => gr a b -> Node -> Node -> gr a (b, b) -- | Compute the value of a maximumflow maxFlow :: (DynGraph gr, Num b, Ord b) => gr a b -> Node -> Node -> b -- | Alternative Maximum Flow module Data.Graph.Inductive.Query.MaxFlow2 type Network = Gr () (Double, Double) ekSimple :: Network -> Node -> Node -> (Network, Double) ekFused :: Network -> Node -> Node -> (Network, Double) ekList :: Network -> Node -> Node -> (Network, Double) instance Eq Direction instance Ord Direction instance Show Direction instance Read Direction -- | Pairing heap implementation of dictionary module Data.Graph.Inductive.Internal.Heap data Heap a b Empty :: Heap a b Node :: a -> b -> [Heap a b] -> Heap a b prettyHeap :: (Show a, Show b) => Heap a b -> String printPrettyHeap :: (Show a, Show b) => Heap a b -> IO () empty :: Heap a b unit :: a -> b -> Heap a b insert :: Ord a => (a, b) -> Heap a b -> Heap a b merge :: Ord a => Heap a b -> Heap a b -> Heap a b mergeAll :: Ord a => [Heap a b] -> Heap a b isEmpty :: Heap a b -> Bool findMin :: Heap a b -> (a, b) deleteMin :: Ord a => Heap a b -> Heap a b splitMin :: Ord a => Heap a b -> (a, b, Heap a b) build :: Ord a => [(a, b)] -> Heap a b toList :: Ord a => Heap a b -> [(a, b)] heapsort :: Ord a => [a] -> [a] instance (Eq a, Eq b) => Eq (Heap a b) instance (Show a, Show b) => Show (Heap a b) instance (Read a, Read b) => Read (Heap a b) instance (NFData a, NFData b) => NFData (Heap a b) -- | Minimum-Spanning-Tree Algorithms module Data.Graph.Inductive.Query.MST msTreeAt :: (Graph gr, Real b) => Node -> gr a b -> LRTree b msTree :: (Graph gr, Real b) => gr a b -> LRTree b msPath :: LRTree b -> Node -> Node -> Path type LRTree a = [LPath a] -- | Shortest path algorithms module Data.Graph.Inductive.Query.SP -- | Tree of shortest paths from a certain node to the rest of the -- (reachable) nodes. -- -- Corresponds to dijkstra applied to a heap in which the only -- known node is the starting node, with a path of length 0 leading to -- it. spTree :: (Graph gr, Real b) => Node -> gr a b -> LRTree b -- | Shortest path between two nodes. sp :: (Graph gr, Real b) => Node -> Node -> gr a b -> Path -- | Length of the shortest path between two nodes. spLength :: (Graph gr, Real b) => Node -> Node -> gr a b -> b -- | Dijkstra's shortest path algorithm. dijkstra :: (Graph gr, Real b) => Heap b (LPath b) -> gr a b -> LRTree b type LRTree a = [LPath a] data Heap a b -- | Graph Voronoi Diagram -- -- These functions can be used to create a shortest path forest -- where the roots are specified. module Data.Graph.Inductive.Query.GVD -- | Representation of a shortest path forest. type Voronoi a = LRTree a type LRTree a = [LPath a] -- | Produce a shortest path forest (the roots of which are those nodes -- specified) from nodes in the graph to one of the root nodes (if -- possible). gvdIn :: (DynGraph gr, Real b) => [Node] -> gr a b -> Voronoi b -- | Produce a shortest path forest (the roots of which are those nodes -- specified) from nodes in the graph from one of the root nodes -- (if possible). gvdOut :: (Graph gr, Real b) => [Node] -> gr a b -> Voronoi b -- | Return the nodes reachable to/from (depending on how the -- Voronoi was constructed) from the specified root node (if the -- specified node is not one of the root nodes of the shortest path -- forest, an empty list will be returned). voronoiSet :: Node -> Voronoi b -> [Node] -- | Try to determine the nearest root node to the one specified in the -- shortest path forest. nearestNode :: Real b => Node -> Voronoi b -> Maybe Node -- | The distance to the nearestNode (if there is one) in the -- shortest path forest. nearestDist :: Node -> Voronoi b -> Maybe b -- | Try to construct a path to/from a specified node to one of the root -- nodes of the shortest path forest. nearestPath :: Node -> Voronoi b -> Maybe Path module Data.Graph.Inductive.Query module Data.Graph.Inductive -- | Version info version :: IO ()