Skip to main content

Reverse topological sort utilities for NetworkX: easily stratify or sort nodes in a DAG from leaves to root.

Project description

networkx-reverse-topological-sort

Reverse topological sort utilities for NetworkX: easily stratify or sort nodes in a DAG from leaves to root.

Features

  • Reverse Topological Sort: Get a valid reverse of NetworkX's topological_sort, yielding from "leaf" nodes up to roots.
  • Reverse Topological Generations: Partition your DAG into generations in reverse order (each generation, all children are in earlier generations).

Motivation

NetworkX includes tools for forward (root-to-leaf) topological traversals, but some applications (e.g., evaluating dependencies after their dependents, post-order processing, certain scheduling schemes) need the reverse order: leaves to root.

This tiny package offers that for networkx.

Installation

pip install networkx-reverse-topological-sort

Usage

import networkx as nx
from networkx_reverse_topological_sort import (
    reverse_topological_generations,
    reverse_topological_sort,
)

DG = nx.DiGraph([(2, 1), (3, 1)])
print([sorted(generation) for generation in reverse_topological_generations(DG)])
# Output: [[1], [2, 3]]

print(list(reverse_topological_sort(DG)))
# Output: [1, 2, 3]  (or [1, 3, 2]: nodes before their parents)

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

networkx_reverse_topological_sort-0.1.0a0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

networkx_reverse_topological_sort-0.1.0a0-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file networkx_reverse_topological_sort-0.1.0a0.tar.gz.

File metadata

File hashes

Hashes for networkx_reverse_topological_sort-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 84f0c942e1770fbebae5ec95875e98a4ead985c068b5d628b46f09b8ea468c5c
MD5 023d490f75fa4af5e9a614a80ef80297
BLAKE2b-256 bafa90ca14a7701542d40456f6983e77d09d2c819fd9230c97201b0c8c7cce29

See more details on using hashes here.

File details

Details for the file networkx_reverse_topological_sort-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for networkx_reverse_topological_sort-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4e51b626b29465c2dcf63976cd1fa3df6ba078991fb412b515591ac8b2301b35
MD5 b93266e6b81da7d3be9023551acd05f2
BLAKE2b-256 0edb0e751020d32b0af11e9f5606136cb8374938a2322dc978e22c77a0ae4591

See more details on using hashes here.

Supported by

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