Name | base-dag JSON |
Version |
0.1.9
JSON |
| download |
home_page | None |
Summary | A simple base implementation of a Directed Acyclic Graph, intended to be subclassed for more specific functionality. |
upload_time | 2024-11-03 03:19:17 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | None |
keywords |
dag
data structures
directed acyclic graph
graph
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# base-dag
A simple base implementation of a DAG. Users should feel free to subclass this DAG class to provide their desired functionality. The API is intended to be similar to the NetworkX API, though not an exact replica. Note that multiple edges between the same two nodes are not supported by this package.
## Creating a DAG.
```python
from base_dag import DAG
# Initialize the DAG
dag = DAG()
# Add nodes and edges
dag.add_nodes_from([1, 2])
dag.add_node(3)
dag.add_edge((1, 2))
dag.add_edge((2, 3))
# Remove nodes and edges
dag.remove_edge((2, 3))
dag.remove_node(3)
```
## Subgraph
```python
# Re-add a third node.
dag.add_node(3)
# Extract the subgraph of nodes 1 and 2.
sub_dag = dag.subgraph([1, 2])
```
## Other Operations
### All nodes & edges
```python
all_nodes = dag.nodes() # (1, 2, 3)
all_edges = dag.edges() # ( (1, 2), (2, 3) )
```
### Successors and Predecessors
```python
successors = dag.successors(1) # [2]
predecessors = dag.predecessors(2) # [1]
```
### Descendants and Ancestors
```python
descendants = dag.descendants(1) # [2, 3]
ancestors = dag.ancestors(2) # [1]
```
### Indegree and Outdegree
```python
in_degree = dag.indegree(2) # 1
out_degree = dag.outdegree(1) # 1
```
### Reverse
```python
# Reverse the direction of the edges in the graph in place, without affecting the nodes at all.
dag.reverse()
```
### Topological sort
```python
sorted_nodes = dag.topological_sort()
```
### Topological generations
```python
generations = dag.topological_generations()
```
### Sorted topological generations
```python
sorted_generations = dag.sorted_topological_generations()
```
### has_path
```python
has_path = dag.has_path(1, 3) # True
```
### is_acyclic
```python
is_acyclic = dag.is_acyclic() # True
```
Raw data
{
"_id": null,
"home_page": null,
"name": "base-dag",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "DAG, data structures, directed acyclic graph, graph",
"author": null,
"author_email": "Mitchell Tillman <mtillman14@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/5f/52/ce4f931e3d2a8b2eefb22834dc92dd5a672e0614f9de72abf2a890ebad47/base_dag-0.1.9.tar.gz",
"platform": null,
"description": "# base-dag\nA simple base implementation of a DAG. Users should feel free to subclass this DAG class to provide their desired functionality. The API is intended to be similar to the NetworkX API, though not an exact replica. Note that multiple edges between the same two nodes are not supported by this package.\n\n## Creating a DAG.\n ```python\nfrom base_dag import DAG\n\n# Initialize the DAG\ndag = DAG()\n\n# Add nodes and edges\ndag.add_nodes_from([1, 2])\ndag.add_node(3)\ndag.add_edge((1, 2))\ndag.add_edge((2, 3))\n\n# Remove nodes and edges\ndag.remove_edge((2, 3))\ndag.remove_node(3)\n```\n\n## Subgraph\n```python\n# Re-add a third node.\ndag.add_node(3)\n# Extract the subgraph of nodes 1 and 2.\nsub_dag = dag.subgraph([1, 2])\n```\n\n## Other Operations\n### All nodes & edges\n```python\nall_nodes = dag.nodes() # (1, 2, 3)\nall_edges = dag.edges() # ( (1, 2), (2, 3) )\n```\n\n### Successors and Predecessors\n```python\nsuccessors = dag.successors(1) # [2]\npredecessors = dag.predecessors(2) # [1]\n```\n\n### Descendants and Ancestors\n```python\ndescendants = dag.descendants(1) # [2, 3]\nancestors = dag.ancestors(2) # [1]\n```\n\n### Indegree and Outdegree\n```python\nin_degree = dag.indegree(2) # 1\nout_degree = dag.outdegree(1) # 1\n```\n\n### Reverse\n```python\n# Reverse the direction of the edges in the graph in place, without affecting the nodes at all.\ndag.reverse()\n```\n\n### Topological sort\n```python\nsorted_nodes = dag.topological_sort()\n```\n\n### Topological generations\n```python\ngenerations = dag.topological_generations()\n```\n\n### Sorted topological generations\n```python\nsorted_generations = dag.sorted_topological_generations()\n```\n\n### has_path\n```python\nhas_path = dag.has_path(1, 3) # True\n```\n\n### is_acyclic\n```python\nis_acyclic = dag.is_acyclic() # True\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple base implementation of a Directed Acyclic Graph, intended to be subclassed for more specific functionality.",
"version": "0.1.9",
"project_urls": {
"documentation": "https://github.com/ResearchOS/base-dag",
"homepage": "https://github.com/ResearchOS/base-dag",
"repository": "https://github.com/ResearchOS/base-dag"
},
"split_keywords": [
"dag",
" data structures",
" directed acyclic graph",
" graph"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "79d5eab53d9bd83e93946ec273886bc7da24e771c4dc17088333c63d124913c5",
"md5": "27dd251b5e3418b0969334df37c4ee7d",
"sha256": "1e28004c553c1b1adf97148ab68075c605222b20c6b00c3812b56354cab1996d"
},
"downloads": -1,
"filename": "base_dag-0.1.9-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "27dd251b5e3418b0969334df37c4ee7d",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 5337,
"upload_time": "2024-11-03T03:19:13",
"upload_time_iso_8601": "2024-11-03T03:19:13.936301Z",
"url": "https://files.pythonhosted.org/packages/79/d5/eab53d9bd83e93946ec273886bc7da24e771c4dc17088333c63d124913c5/base_dag-0.1.9-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5f52ce4f931e3d2a8b2eefb22834dc92dd5a672e0614f9de72abf2a890ebad47",
"md5": "c523e2d1863300b1b8c66c551a3caaa4",
"sha256": "9cabba5fb89f77a4478dd48f346a82b2b05d1410eea678587e3531c0b2b3f19d"
},
"downloads": -1,
"filename": "base_dag-0.1.9.tar.gz",
"has_sig": false,
"md5_digest": "c523e2d1863300b1b8c66c551a3caaa4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5792,
"upload_time": "2024-11-03T03:19:17",
"upload_time_iso_8601": "2024-11-03T03:19:17.428672Z",
"url": "https://files.pythonhosted.org/packages/5f/52/ce4f931e3d2a8b2eefb22834dc92dd5a672e0614f9de72abf2a890ebad47/base_dag-0.1.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-03 03:19:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ResearchOS",
"github_project": "base-dag",
"github_not_found": true,
"lcname": "base-dag"
}