Hets - the Heterogeneous Tool Set

Copyright(c) Uni Bremen 2003-2005
LicenseGPLv2 or higher, see LICENSE.txt
MaintainerChristian.Maeder@dfki.de
Stabilityprovisional
Portabilityportable
Safe HaskellSafe

Common.Lib.Rel

Description

supply a simple data type for (precedence or subsort) relations. A relation is conceptually a set of (ordered) pairs, but the hidden implementation is based on a map of sets. An alternative view is that of a directed Graph possibly with isolated nodes.

Rel is a directed graph with elements (Ord a) as (uniquely labelled) nodes and (unlabelled) edges (with a multiplicity of at most one).

Usage: start with an empty relation, insert edges, and test for an edge member (before or after calling transClosure).

It is possible to insert self edges or bigger cycles. But rather than inserting self edges and element can be mapped to the empty set.

Checking for a path corresponds to checking for a member in the transitive (possibly non-reflexive) closure. A further insert, however, may destroy the closedness property of a relation.

Synopsis

Documentation

data Rel a Source #

no invariant is ensured for relations!

Instances

Eq a => Eq (Rel a) Source # 

Methods

(==) :: Rel a -> Rel a -> Bool

(/=) :: Rel a -> Rel a -> Bool

(Ord a, Data a) => Data (Rel a) Source # 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Rel a -> c (Rel a)

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Rel a)

toConstr :: Rel a -> Constr

dataTypeOf :: Rel a -> DataType

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Rel a))

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Rel a))

gmapT :: (forall b. Data b => b -> b) -> Rel a -> Rel a

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Rel a -> r

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Rel a -> r

gmapQ :: (forall d. Data d => d -> u) -> Rel a -> [u]

gmapQi :: Int -> (forall d. Data d => d -> u) -> Rel a -> u

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Rel a -> m (Rel a)

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Rel a -> m (Rel a)

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Rel a -> m (Rel a)

Ord a => Ord (Rel a) Source # 

Methods

compare :: Rel a -> Rel a -> Ordering

(<) :: Rel a -> Rel a -> Bool

(<=) :: Rel a -> Rel a -> Bool

(>) :: Rel a -> Rel a -> Bool

(>=) :: Rel a -> Rel a -> Bool

max :: Rel a -> Rel a -> Rel a

min :: Rel a -> Rel a -> Rel a

(Ord a, Read a) => Read (Rel a) Source # 

Methods

readsPrec :: Int -> ReadS (Rel a)

readList :: ReadS [Rel a]

readPrec :: ReadPrec (Rel a)

readListPrec :: ReadPrec [Rel a]

Show a => Show (Rel a) Source # 

Methods

showsPrec :: Int -> Rel a -> ShowS

show :: Rel a -> String

showList :: [Rel a] -> ShowS

(Ord a, HasSorts a) => HasSorts (Rel a) Source # 

empty :: Rel a Source #

the empty relation

nullKeys :: Rel a -> Bool Source #

test for empty

rmNullSets :: Ord a => Rel a -> Rel a Source #

insertPair :: Ord a => a -> a -> Rel a -> Rel a Source #

insert an ordered pair

insertDiffPair :: Ord a => a -> a -> Rel a -> Rel a Source #

insert a pair only if both sides are different

insertKeyOrPair :: Ord a => a -> a -> Rel a -> Rel a Source #

insert a pair only if both sides are different

member :: Ord a => a -> a -> Rel a -> Bool Source #

test for an (previously inserted) ordered pair

toMap :: Rel a -> Map a (Set a) Source #

map :: (Ord a, Ord b) => (a -> b) -> Rel a -> Rel b Source #

map the values of a relation

noPairs :: Ord a => Rel a -> Bool Source #

test for empty

insertKey :: Ord a => a -> Rel a -> Rel a Source #

insert an unrelated node

deleteKey :: Ord a => a -> Rel a -> Rel a Source #

delete a node and all its relations

memberKey :: Ord a => a -> Rel a -> Bool Source #

keysSet :: Rel a -> Set a Source #

keys of the relation

fromKeysSet :: Ord a => Set a -> Rel a Source #

convert a plain node set to a relation

reflexive :: Ord a => Rel a -> Rel a Source #

add all keys as reflexive elements

getCycles :: Ord a => Rel a -> Rel a Source #

get entries that contain the key as element

union :: Ord a => Rel a -> Rel a -> Rel a Source #

union of two relations

intersection :: Ord a => Rel a -> Rel a -> Rel a Source #

intersection of two relations

isSubrelOf :: Ord a => Rel a -> Rel a -> Bool Source #

is the first relation a sub-relation of the second

difference :: Ord a => Rel a -> Rel a -> Rel a Source #

difference of two relations

path :: Ord a => a -> a -> Rel a -> Bool Source #

test for member or transitive membership (non-empty path)

delete :: Ord a => a -> a -> Rel a -> Rel a Source #

delete an ordered pair

succs :: Ord a => Rel a -> a -> Set a Source #

get direct successors

predecessors :: Ord a => Rel a -> a -> Set a Source #

get direct predecessors

irreflex :: Ord a => Rel a -> Rel a Source #

make relation irreflexive

sccOfClosure :: Ord a => Rel a -> [Set a] Source #

compute strongly connected components for a transitively closed relation

transClosure :: Ord a => Rel a -> Rel a Source #

compute transitive closure (make all transitive members direct members)

fromList :: Ord a => [(a, a)] -> Rel a Source #

convert a list of ordered pairs to a relation

toList :: Rel a -> [(a, a)] Source #

convert a relation to a list of ordered pairs (this loses isolated keys!)

toPrecMap :: Ord a => Rel a -> (Map a Int, Int) Source #

Construct a precedence map from a closed relation. Indices range between 1 and the second value that is output.

intransKernel :: Ord a => Rel a -> Rel a Source #

intransitive kernel of a reflexive and transitive closure

  • precondition: (transClosure r == r)
  • cycles are uniquely represented (according to Ord)

mostRight :: Ord a => Rel a -> Set a Source #

find s such that x in s => forall y . yRx or not yRx and not xRy

  • precondition: (transClosure r == r)
  • strongly connected components (cycles) are treated as a compound node

restrict :: Ord a => Rel a -> Set a -> Rel a Source #

Restriction of a relation under a set

delSet :: Ord a => Set a -> Rel a -> Rel a Source #

restrict to elements not in the input set

toSet :: Ord a => Rel a -> Set (a, a) Source #

convert a relation to a set of ordered pairs

fromSet :: Ord a => Set (a, a) -> Rel a Source #

convert a set of ordered pairs to a relation

topSort :: Ord a => Rel a -> [Set a] Source #

topologically sort a closed relation (ignore isolated cycles)

depSort :: Ord a => Rel a -> [Set a] Source #

nodes :: Ord a => Rel a -> Set a Source #

all nodes of the edges

collaps :: Ord a => [Set a] -> Rel a -> Rel a Source #

restrict strongly connected components to its minimal representative (input sets must be non-null). Direct cycles may remain.

transpose :: Ord a => Rel a -> Rel a Source #

get transposed relation (losing unrelated keys)

transReduce :: Ord a => Rel a -> Rel a Source #

transitive reduction (minimal relation with the same transitive closure) of a transitively closed DAG (i.e. without cycles)!

fromMap :: Map a (Set a) -> Rel a Source #

locallyFiltered :: Ord a => Rel a -> Bool Source #

checks if a given relation is locally filtered

  • precondition: the relation must already be closed by transitive closure

flatSet :: Ord a => [Set a] -> Set a Source #

flattens a list of non-empty sets and uses the minimal element of each set to represent the set

partSet :: Ord a => (a -> a -> Bool) -> Set a -> [Set a] Source #

partitions a set into a list of disjoint non-empty subsets determined by the given function as equivalence classes

partList :: (a -> a -> Bool) -> [a] -> [[a]] Source #

partitions a list into a list of disjoint non-empty lists determined by the given function as equivalence classes

leqClasses :: Ord a => (a -> a -> Bool) -> Set a -> [[a]] Source #

Divide a Set (List) into equivalence classes w.r.t. eq