graphite-0.7.0.0: Graphs and networks library

Data.Graph.Types

Synopsis

# Documentation

class Graph g where Source #

Minimal complete definition

Methods

empty :: Hashable v => g v e Source #

The Empty (order-zero) graph with no vertices and no edges

order :: g v e -> Int Source #

Retrieve the order of a graph | The order of a graph is its number of vertices

size :: (Hashable v, Eq v) => g v e -> Int Source #

Retrieve the size of a graph | The size of a graph is its number of edges

vertices :: g v e -> [v] Source #

Retrieve the vertices of a graph

edgeTriples :: (Hashable v, Eq v) => g v e -> [(v, v, e)] Source #

Retrieve the edges of a graph

edgePairs :: (Hashable v, Eq v) => g v e -> [(v, v)] Source #

Retrieve the edges of a graph, ignoring its attributes

containsVertex :: (Hashable v, Eq v) => g v e -> v -> Bool Source #

Tell if a vertex exists in the graph

areAdjacent :: (Hashable v, Eq v) => g v e -> v -> v -> Bool Source #

Tell if two vertices are adjacent

adjacentVertices :: (Hashable v, Eq v) => g v e -> v -> [v] Source #

Retrieve the adjacent vertices of a vertex

adjacentVertices' :: (Hashable v, Eq v) => g v e -> v -> [(v, e)] Source #

Same as adjacentVertices but pairs the vertex with the connecting | edge's attribute

reachableAdjacentVertices :: (Hashable v, Eq v) => g v e -> v -> [v] Source #

Same as adjacentVertices but gives back only those vertices for which | the connecting edge allows the vertex to be reached. | | For an undirected graph this is equivalent to adjacentVertices, but | for the case of a directed graph, the directed arcs will constrain the | reachability of the adjacent vertices.

reachableAdjacentVertices' :: (Hashable v, Eq v) => g v e -> v -> [(v, e)] Source #

Same as reachableAdjacentVertices but pairs the vertex with the | connecting edge's attribute

vertexDegree :: (Hashable v, Eq v) => g v e -> v -> Int Source #

Total number of incident edges of a vertex

degrees :: (Hashable v, Eq v) => g v e -> [Int] Source #

Degrees of a all the vertices in a graph

maxDegree :: (Hashable v, Eq v) => g v e -> Int Source #

Maximum degree of a graph

minDegree :: (Hashable v, Eq v) => g v e -> Int Source #

Minimum degree of a graph

avgDegree :: (Hashable v, Eq v) => g v e -> Double Source #

Average degree of a graph

density :: (Hashable v, Eq v) => g v e -> Double Source #

Density of a graph | The ratio of the number of existing edges in the graph to the number of | posible edges

insertVertex :: (Hashable v, Eq v) => v -> g v e -> g v e Source #

Insert a vertex into a graph | If the graph already contains the vertex leave the graph untouched

insertVertices :: (Hashable v, Eq v) => [v] -> g v e -> g v e Source #

Insert a many vertices into a graph | New vertices are inserted and already contained vertices are left | untouched

containsEdgePair :: (Hashable v, Eq v) => g v e -> (v, v) -> Bool Source #

Tell if an edge exists in the graph

incidentEdgeTriples :: (Hashable v, Eq v) => g v e -> v -> [(v, v, e)] Source #

Retrieve the incident edges of a vertex

incidentEdgePairs :: (Hashable v, Eq v) => g v e -> v -> [(v, v)] Source #

Retrieve the incident edges of a vertex, ignoring its attributes

insertEdgeTriple :: (Hashable v, Eq v) => (v, v, e) -> g v e -> g v e Source #

Insert an edge into a graph | The involved vertices are inserted if don't exist. If the graph already | contains the edge, its attribute is updated

insertEdgeTriples :: (Hashable v, Eq v) => [(v, v, e)] -> g v e -> g v e Source #

Same as insertEdgeTriple but for multiple edges

insertEdgePair :: (Hashable v, Eq v) => (v, v) -> g v () -> g v () Source #

Same as insertEdgeTriple but insert edge pairs in graphs with | attributeless edges

insertEdgePairs :: (Hashable v, Eq v) => [(v, v)] -> g v () -> g v () Source #

Same as insertEdgePair for multiple edges

removeVertex :: (Hashable v, Eq v) => v -> g v e -> g v e Source #

Remove a vertex from a graph if present | Every edge incident to this vertex is also removed

removeVertices :: (Hashable v, Eq v) => [v] -> g v e -> g v e Source #

Same as removeVertex but for multiple vertices

removeEdgePair :: (Hashable v, Eq v) => (v, v) -> g v e -> g v e Source #

Remove an edge from a graph if present | The involved vertices are left untouched

removeEdgePairs :: (Hashable v, Eq v) => [(v, v)] -> g v e -> g v e Source #

Same as removeEdgePair but for multple edges

removeEdgePairAndVertices :: (Hashable v, Eq v) => (v, v) -> g v e -> g v e Source #

Remove the edge from a graph if present | The involved vertices are also removed

isSimple :: (Hashable v, Eq v) => g v e -> Bool Source #

Tell if a graph is simple | A graph is simple if it has no loops

fromAdjacencyMatrix :: [[Int]] -> Maybe (g Int ()) Source #

Generate a graph of Int vertices from an adjacency | square matrix

toAdjacencyMatrix :: g v e -> [[Int]] Source #

Get the adjacency matrix representation of a grah

Instances

data Edge v e Source #

Undirected Edge with attribute of type e between to Vertices of type v

Constructors

 Edge v v e

Instances

 Source # MethodstoPair :: Edge v a -> (v, v) Source #toTriple :: Edge v a -> (v, v, a) Source #isLoop :: Eq v => Edge v a -> Bool Source # (Eq v, Eq a) => Eq (Edge v a) Source # To Edges are equal if they point to the same vertices, regardless of the | direction Methods(==) :: Edge v a -> Edge v a -> Bool #(/=) :: Edge v a -> Edge v a -> Bool # (Ord e, Ord v) => Ord (Edge v e) Source # Methodscompare :: Edge v e -> Edge v e -> Ordering #(<) :: Edge v e -> Edge v e -> Bool #(<=) :: Edge v e -> Edge v e -> Bool #(>) :: Edge v e -> Edge v e -> Bool #(>=) :: Edge v e -> Edge v e -> Bool #max :: Edge v e -> Edge v e -> Edge v e #min :: Edge v e -> Edge v e -> Edge v e # (Read e, Read v) => Read (Edge v e) Source # MethodsreadsPrec :: Int -> ReadS (Edge v e) #readList :: ReadS [Edge v e] #readPrec :: ReadPrec (Edge v e) #readListPrec :: ReadPrec [Edge v e] # (Show e, Show v) => Show (Edge v e) Source # MethodsshowsPrec :: Int -> Edge v e -> ShowS #show :: Edge v e -> String #showList :: [Edge v e] -> ShowS # Generic (Edge v e) Source # Associated Typestype Rep (Edge v e) :: * -> * # Methodsfrom :: Edge v e -> Rep (Edge v e) x #to :: Rep (Edge v e) x -> Edge v e # (Arbitrary v, Arbitrary e, Num v, Ord v) => Arbitrary (Edge v e) Source # Methodsarbitrary :: Gen (Edge v e) #shrink :: Edge v e -> [Edge v e] # (NFData v, NFData e) => NFData (Edge v e) Source # Methodsrnf :: Edge v e -> () # type Rep (Edge v e) Source # type Rep (Edge v e) = D1 (MetaData "Edge" "Data.Graph.Types" "graphite-0.7.0.0-8WWdAG6H6TkGNMaQTFz76U" False) (C1 (MetaCons "Edge" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 v)) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 v)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 e)))))

data Arc v e Source #

Directed Arc with attribute of type e between to Vertices of type v

Constructors

 Arc v v e

Instances

 Source # MethodstoPair :: Arc v a -> (v, v) Source #toTriple :: Arc v a -> (v, v, a) Source #isLoop :: Eq v => Arc v a -> Bool Source # (Eq v, Eq a) => Eq (Arc v a) Source # To Arcs are equal if they point to the same vertices, and the directions | is the same Methods(==) :: Arc v a -> Arc v a -> Bool #(/=) :: Arc v a -> Arc v a -> Bool # (Ord e, Ord v) => Ord (Arc v e) Source # Methodscompare :: Arc v e -> Arc v e -> Ordering #(<) :: Arc v e -> Arc v e -> Bool #(<=) :: Arc v e -> Arc v e -> Bool #(>) :: Arc v e -> Arc v e -> Bool #(>=) :: Arc v e -> Arc v e -> Bool #max :: Arc v e -> Arc v e -> Arc v e #min :: Arc v e -> Arc v e -> Arc v e # (Read e, Read v) => Read (Arc v e) Source # MethodsreadsPrec :: Int -> ReadS (Arc v e) #readList :: ReadS [Arc v e] #readPrec :: ReadPrec (Arc v e) #readListPrec :: ReadPrec [Arc v e] # (Show e, Show v) => Show (Arc v e) Source # MethodsshowsPrec :: Int -> Arc v e -> ShowS #show :: Arc v e -> String #showList :: [Arc v e] -> ShowS # Generic (Arc v e) Source # Associated Typestype Rep (Arc v e) :: * -> * # Methodsfrom :: Arc v e -> Rep (Arc v e) x #to :: Rep (Arc v e) x -> Arc v e # (Arbitrary v, Arbitrary e, Num v, Ord v) => Arbitrary (Arc v e) Source # Methodsarbitrary :: Gen (Arc v e) #shrink :: Arc v e -> [Arc v e] # (NFData v, NFData e) => NFData (Arc v e) Source # Methodsrnf :: Arc v e -> () # type Rep (Arc v e) Source # type Rep (Arc v e) = D1 (MetaData "Arc" "Data.Graph.Types" "graphite-0.7.0.0-8WWdAG6H6TkGNMaQTFz76U" False) (C1 (MetaCons "Arc" PrefixI False) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 v)) ((:*:) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 v)) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 e)))))

(<->) :: Hashable v => v -> v -> Edge v () Source #

Construct an undirected Edge between two vertices

(-->) :: Hashable v => v -> v -> Arc v () Source #

Construct a directed Arc between two vertices

class IsEdge e where Source #

Minimal complete definition

Methods

toPair :: e v a -> (v, v) Source #

Convert an edge to a pair discargind its attribute

toTriple :: e v a -> (v, v, a) Source #

Convert an edge to a triple, where the 3rd element it's the edge | attribute

isLoop :: Eq v => e v a -> Bool Source #

Tell if an edge is a loop | An edge forms a loop if both of its ends point to the same vertex

Instances

 Source # MethodstoPair :: Arc v a -> (v, v) Source #toTriple :: Arc v a -> (v, v, a) Source #isLoop :: Eq v => Arc v a -> Bool Source # Source # MethodstoPair :: Edge v a -> (v, v) Source #toTriple :: Edge v a -> (v, v, a) Source #isLoop :: Eq v => Edge v a -> Bool Source #

class Weighted a where Source #

Weighted Edge attributes | Useful for computing some algorithms on graphs

Minimal complete definition

weight

Methods

weight :: a -> Double Source #

Instances

 Source # Methods Source # Methods Source # Methods Source # Methodsweight :: (Double, String) -> Double Source #

class Labeled a where Source #

Labeled Edge attributes | Useful for graph plotting

Minimal complete definition

label

Methods

label :: a -> String Source #

Instances

 Source # Methods Source # Methodslabel :: (Double, String) -> String Source #

tripleToPair :: (a, b, c) -> (a, b) Source #

Convert a triple to a pair by ignoring the third element

arbitraryEdge :: (Arbitrary v, Arbitrary e, Ord v, Num v) => (v -> v -> e -> edge) -> Gen edge Source #

Edges generator

type Links v e = HashMap v e Source #

Each vertex maps to a Links value so it can poit to other vertices

insertLink :: (Hashable v, Eq v) => v -> a -> Links v a -> Links v a Source #

Insert a link directed to *v* with attribute *a* | If the connnection already exists, the attribute is replaced

getLinks :: (Hashable v, Eq v) => v -> HashMap v (Links v e) -> Links v e Source #

Get the links for a given vertex

linksToArcs :: [(v, Links v a)] -> [Arc v a] Source #

Get Arcs from an association list of vertices and their links

linksToEdges :: [(v, Links v a)] -> [Edge v a] Source #

Get Edges from an association list of vertices and their links

hashMapInsert :: (Eq k, Hashable k) => k -> v -> HashMap k v -> HashMap k v Source #

O(log n) Associate the specified value with the specified key in this map. | If this map previously contained a mapping for the key, leave the map | intact.