Skip to main content

tredge

pypi

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.

If a given graph is cyclic, transitive_edges function will not return edges that include vertices participating in loops. To find such vertices beforehand or make sure there are none, there is a function cycles(g).

Usage:

import tredge

g = {
    'b': {'a'},
    'c': {'a'},
    'd': {'b', 'c', 'a'},
    'e': {'d', 'a'}
}
result = tredge.transitive_edges(g)
print(result)

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

or

import tredge

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

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

or

"""input_file.tab:
b	a
c	a
d	b
d	c
e	d
e	a
d	a
"""

import tredge

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

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

To check if a graph has cycles:

import tredge

g = {
    'b': {'a'},
    'c': {'a'},
    'd': {'b', 'c', 'a'},
    'e': {'d', 'a'}
}
result = tredge.cycles(g)
print(result)

# {'e', 'c', 'd'}

Metadata

Release files for tredge 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tredge 0.0.3
File Size Uploaded
tredge-0.0.3.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tredge 0.0.3
File Interpreter ABI Platform
tredge-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / tredge-0.0.3.tar.gz

Download URL tredge-0.0.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9b6c47321e194274f6cb69c6f5ae6fe3889b6b025cb6f823524b3e505940a8f2
BLAKE2b-256 checksum
How to use checksums
7af1f26401faae3130232afae16640c361a3acca4010bcd6802bc8e9225343da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6

Release files / tredge-0.0.3-py3-none-any.whl

Download URL tredge-0.0.3-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8638e20fd181d7b60efe130155050a9dc40ed5c1135fdcfd646cb1c93c821cb
BLAKE2b-256 checksum
How to use checksums
a5f97439095c81d3837be8361ce76281bb2aed6801c8d7e76b1b0e225fad21df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page