cifl-math-library-1.1.1.0: Math libraries
Safe HaskellSafe
LanguageHaskell2010

Math.Graph.Reversible

Description

Graph representation as a set with action of a monoid. See Lawvere,Rosebrugh: Sets for Mathematics for details.

This module implements graphs using a representation as a set with an action of a monoid.

For directed graph, the monoid Three is used, which represents operations of id,source and target

For undirected graph, the monoid Four is used, which represents operations of id,source, target and inverse.

See Math.Graph.InGraphMonad for how to read graphs in monadic context

See Math.Graph.InGraphA for how to read graphs in arrow context

Synopsis

Documentation

data Graph m a Source #

Graph representation containing a set of elements. an element of a graph is either an edge or a vertex.

the action_endomorphism allows obtaining source vertex, target vertex and inverse edge of an element See GraphMonoid for details.

Note that the monoid data structure contains only names of the monoid elements - the action_endomorphism is then used to convert it to actual operation.

Constructors

Graph 

Fields

Instances

Instances details
(Ord a, Show a, Show (m Bool Bool)) => Monoid (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Methods

mempty :: Graph m a #

mappend :: Graph m a -> Graph m a -> Graph m a #

mconcat :: [Graph m a] -> Graph m a #

(Ord a, Show a, Show (m Bool Bool)) => Semigroup (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Methods

(<>) :: Graph m a -> Graph m a -> Graph m a #

sconcat :: NonEmpty (Graph m a) -> Graph m a #

stimes :: Integral b => b -> Graph m a -> Graph m a #

Generic (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Associated Types

type Rep (Graph m a) :: Type -> Type #

Methods

from :: Graph m a -> Rep (Graph m a) x #

to :: Rep (Graph m a) x -> Graph m a #

(Ord a, PpShow a) => Show (Graph (Four :: Type -> Type -> Type) a) Source # 
Instance details

Defined in Math.Graph.Show

Methods

showsPrec :: Int -> Graph Four a -> ShowS #

show :: Graph Four a -> String #

showList :: [Graph Four a] -> ShowS #

(Ord a, PpShow a) => Show (Graph (Three :: Type -> Type -> Type) a) Source # 
Instance details

Defined in Math.Graph.Show

Methods

showsPrec :: Int -> Graph Three a -> ShowS #

show :: Graph Three a -> String #

showList :: [Graph Three a] -> ShowS #

(Binary a, Ord a) => Binary (Graph (Three :: Type -> Type -> Type) a) Source # 
Instance details

Defined in Math.Graph.Show

Methods

put :: Graph Three a -> Put #

get :: Get (Graph Three a) #

putList :: [Graph Three a] -> Put #

(Ord a, Show a, Show (m Bool Bool), ReversibleGraphMonoid m Bool) => SetLike (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Methods

sintersection :: Graph m a -> Graph m a -> Graph m a Source #

sunion :: Graph m a -> Graph m a -> Graph m a Source #

scomplement :: Graph m a -> Graph m a Source #

(Ord a, PpShow a) => PpShow (Graph (Four :: Type -> Type -> Type) a) Source # 
Instance details

Defined in Math.Graph.Show

Methods

pp :: Graph Four a -> Doc Source #

(Ord a, PpShow a) => PpShow (Graph (Three :: Type -> Type -> Type) a) Source # 
Instance details

Defined in Math.Graph.Show

Methods

pp :: Graph Three a -> Doc Source #

(Ord a, GraphMonoid m Bool) => Visitor (Graph m a) Source # 
Instance details

Defined in Math.Graph.InGraphMonad

Associated Types

data Fold (Graph m a) :: Type -> Type Source #

Methods

visit :: Fold (Graph m a) a0 -> Graph m a -> a0 Source #

(Eq a, Universe (m Bool Bool)) => Eq (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Methods

(==) :: Graph m a -> Graph m a -> Bool #

(/=) :: Graph m a -> Graph m a -> Bool #

(Ord a, Universe (m Bool Bool)) => Ord (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

Methods

compare :: Graph m a -> Graph m a -> Ordering #

(<) :: Graph m a -> Graph m a -> Bool #

(<=) :: Graph m a -> Graph m a -> Bool #

(>) :: Graph m a -> Graph m a -> Bool #

(>=) :: Graph m a -> Graph m a -> Bool #

max :: Graph m a -> Graph m a -> Graph m a #

min :: Graph m a -> Graph m a -> Graph m a #

(Monad m, Ord e, GraphMonoid mon Bool) => GraphMonad (ReaderT (Graph mon e) m) e Source # 
Instance details

Defined in Math.Graph.InGraphMonad

Methods

gisVertex :: e -> ReaderT (Graph mon e) m Bool Source #

gsource :: e -> ReaderT (Graph mon e) m e Source #

gtarget :: e -> ReaderT (Graph mon e) m e Source #

gelements :: ReaderT (Graph mon e) m (Set e) Source #

gvertices :: ReaderT (Graph mon e) m (Set e) Source #

gedges :: ReaderT (Graph mon e) m (Set e) Source #

gedgesStartingFrom :: e -> ReaderT (Graph mon e) m (Set e) Source #

gedgesEndingTo :: e -> ReaderT (Graph mon e) m (Set e) Source #

glinks :: ReaderT (Graph mon e) m (Set (e, e, e)) Source #

gloops :: ReaderT (Graph mon e) m (Set e) Source #

gisLoop :: e -> ReaderT (Graph mon e) m Bool Source #

gisEdgeBetween :: e -> e -> e -> ReaderT (Graph mon e) m Bool Source #

(Monad m, Ord e, ReversibleGraphMonoid mon Bool) => ReversibleGraphMonad (ReaderT (Graph mon e) m) e Source # 
Instance details

Defined in Math.Graph.InGraphMonad

Methods

ginverse :: e -> ReaderT (Graph mon e) m e Source #

greversibleLinks :: ReaderT (Graph mon e) m (Set ((e, e), (e, e))) Source #

goneLaneLoops :: ReaderT (Graph mon e) m (Set e) Source #

gisOneLaneLoop :: e -> ReaderT (Graph mon e) m Bool Source #

(Ord v, Ord e) => DigraphFactory (Graph (Three :: Type -> Type -> Type) (GraphElem v e)) v e Source # 
Instance details

Defined in Math.Graph.Digraph

Methods

vertexGraph :: v -> Graph Three (GraphElem v e) Source #

edgeGraph :: e -> v -> v -> Graph Three (GraphElem v e) Source #

verticesFromSetGraph :: Set v -> Graph Three (GraphElem v e) Source #

verticesGraph :: [v] -> Graph Three (GraphElem v e) Source #

completeGraph :: [v] -> (v -> v -> e) -> Graph Three (GraphElem v e) Source #

edgeGraphFromMap :: Map e (v, v) -> Graph Three (GraphElem v e) Source #

edgesGraph :: [(e, (v, v))] -> Graph Three (GraphElem v e) Source #

loopGraph :: [(v, e)] -> Graph Three (GraphElem v e) Source #

(Ord v, Ord e) => ReversibleGraphFactory (Graph (Four :: Type -> Type -> Type) (GraphElem v e)) v e Source # 
Instance details

Defined in Math.Graph.Digraph

ArrowReader (Graph m a) (InGraphA m a) 
Instance details

Defined in Math.Graph.InGraphA

Methods

readState :: InGraphA m a b (Graph m a)

newReader :: InGraphA m a e b -> InGraphA m a (e, Graph m a) b

Monad m => MonadReader (Graph mon e) (InGraphM mon e m) Source # 
Instance details

Defined in Math.Graph.InGraphMonad

Methods

ask :: InGraphM mon e m (Graph mon e) #

local :: (Graph mon e -> Graph mon e) -> InGraphM mon e m a -> InGraphM mon e m a #

reader :: (Graph mon e -> a) -> InGraphM mon e m a #

type Rep (Graph m a) Source # 
Instance details

Defined in Math.Graph.Reversible

type Rep (Graph m a) = D1 ('MetaData "Graph" "Math.Graph.Reversible" "cifl-math-library-1.1.1.0-JEQP78tsA0rJRaFkv5LJVZ" 'False) (C1 ('MetaCons "Graph" 'PrefixI 'True) (S1 ('MetaSel ('Just "vertices") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Set a)) :*: (S1 ('MetaSel ('Just "edges") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Set a)) :*: S1 ('MetaSel ('Just "action_endomorphism") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m Bool Bool -> Endo a)))))
data Fold (Graph m a) b Source # 
Instance details

Defined in Math.Graph.InGraphMonad

data Fold (Graph m a) b = GraphFold {}

elements :: Ord a => Graph m a -> Set a Source #

action :: Graph m a -> a -> m Bool Bool -> a Source #

setAction :: Ord a => Graph m a -> Set a -> m Bool Bool -> Set a Source #

listAction :: Ord a => Graph m a -> [a] -> m Bool Bool -> [a] Source #

inverseImageG :: (m Bool Bool -> n Bool Bool) -> Graph n a -> Graph m a Source #

vertexG :: a -> Graph m a Source #

verticesG :: Ord a => [a] -> Graph m a Source #

edgeG :: Ord a => a -> a -> a -> Graph Three a Source #

binopG :: Set b -> Set b -> (arr Bool Bool -> b -> b) -> Graph arr b Source #

data EitherMonoid m a b where Source #

Constructors

EitherMonoid :: m Bool Bool -> m Bool Bool -> EitherMonoid m a a 

discriminatedUnionG :: (Ord a, Ord b) => Graph m a -> Graph m b -> Graph (EitherMonoid m) (Either a b) Source #

intersectionG :: Ord a => Graph m a -> Graph m a -> Graph m a Source #

productG :: (Ord a, Ord b) => Graph m a -> Graph m b -> Graph m (a, b) Source #

unionG :: (Ord a, Show a, Show (m Bool Bool)) => Graph m a -> Graph m a -> Graph m a Source #

union of two graphs. Notice: calls error if two edges with same name point to different vertices. Notice: calls error if action is called with input that is not in vertices or edges.

completeG :: Ord a => [a] -> (a -> a -> a) -> Graph Three a Source #

In a complete graph, every pair of vertices (x,y) has a single link.

completeG \["1","2","3"\] \(++\) == [1, 2, 3] ; [11 = 1 -> 1, 12 = 1 -> 2, 13 = 1 -> 3, 21 = 2 -> 1,
                                             22 = 2 -> 2, 23 = 2 -> 3, 31 = 3 -> 1, 32 = 3 -> 2, 33 = 3 -> 3]

Note though that edge names produced from pair of vertices by the function given must be unique, no overlaps are allowed, so it is required that for call 'completeG vertices edge'

forall v,w : vertices . (v != v' || w != w') => edge v w != edge v' w'

edgesFromMapG :: Ord a => Map a (a, a) -> Graph Three a Source #

edgesG :: Ord a => [(a, (a, a))] -> Graph Three a Source #

loopG :: Ord a => [(a, a)] -> Graph Three a Source #

given a list of (v,e), the loopG contains looped edges of the form e : v -> v.

reversibleToDirectedG :: Graph Four a -> Graph Three a Source #

converts from undirected graph to directed graph

inverseGraphG :: Group (m Bool Bool) => Graph m a -> Graph m a Source #

inverts all edges

mapG :: (Ord a, Ord b) => (a :==: b) -> Graph m a :==: Graph m b Source #

mapG uses an isomorphism of graph elements to permute a graph.

reversibleEdgeG :: Ord a => a -> a -> a -> a -> Graph Four a Source #

reversibleCompleteG :: Ord a => [a] -> (a -> a -> (a, a)) -> Graph Four a Source #

edges argument has inputs from and to and should return names of forward and backward edges.

reversibleEdgesG :: Ord a => [((a, a), (a, a))] -> Graph Four a Source #

The input data contains ((edge,reverse-edge),(startNode,endNode))