Skip to main content

Python module for finding transitive edges in a directed acyclic graph

Project description



This is tiny yet fast module to get set of explicitly defined transitive edges from a directed acyclic graph. Given a DAG with edges child<--parent represented as dictionary (keys are children, values are iterables with parents), or as iterable of iterables representing edges ((child, parent)), or as file object pointing to tab-delimited file with 2 columns (child, parent), it returns set of transitive edges found there. Original intent of this package was to use it for removing redundant edges from tree structures.


import tredge

g = {
    'b': set(['a']),
    'c': set(['a']),
    'd': set(['b', 'c', 'a']),
    'e': set(['d', 'a'])
result = tredge.transitive_edges(g)

# {('d', 'a'), ('e', 'a')}


import tredge

g = [
    ('b', 'a'),
    ('c', 'a'),
    ('d', 'b'),
    ('d', 'c'),
    ('e', 'd'),
    ('e', 'a'),
    ('d', 'a')
result = tredge.transitive_edges(g)

# {('d', 'a'), ('e', 'a')}


b	a
c	a
d	b
d	c
e	d
e	a
d	a

import tredge

with open('', mode='r', encoding='utf8') as g:
    result = tredge.transitive_edges(g)

# {('d', 'a'), ('e', 'a')}

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tredge-0.0.2.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

tredge-0.0.2-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page