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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file networkx_reverse_topological_sort-0.1.0a0.tar.gz.
File metadata
- Download URL: networkx_reverse_topological_sort-0.1.0a0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84f0c942e1770fbebae5ec95875e98a4ead985c068b5d628b46f09b8ea468c5c
|
|
| MD5 |
023d490f75fa4af5e9a614a80ef80297
|
|
| BLAKE2b-256 |
bafa90ca14a7701542d40456f6983e77d09d2c819fd9230c97201b0c8c7cce29
|
File details
Details for the file networkx_reverse_topological_sort-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: networkx_reverse_topological_sort-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e51b626b29465c2dcf63976cd1fa3df6ba078991fb412b515591ac8b2301b35
|
|
| MD5 |
b93266e6b81da7d3be9023551acd05f2
|
|
| BLAKE2b-256 |
0edb0e751020d32b0af11e9f5606136cb8374938a2322dc978e22c77a0ae4591
|