dhgraph: Python Modlue for Directed Hypergraphs
Introduction
A directed hypergraph is a generalization of digraph. It consists of a set of vertices V and a set of hyperarcs H. A hyperarc is a pair of a nonempty subset of V (called head) and a vertex of V (called tail).
Installation
$ pip install dhgraph
Usage
Let us import dhgraph module, create an empty directed hypergraph object, and add hyperarcs as follows.
from dhgraph import DirectedHypergraph
g = DirectedHypergraph()
# 1 ---> 2
# | |
# v v
# 4----> 3
h1 = g.add_hyperarc((1,), 2)
h2 = g.add_hyperarc((1,), 4)
h3 = g.add_hyperarc((4, 2), 3)
H = {h1, h2, h3} # Set of hyperarc identifiers, used later.
# NOTE: The order of vertices in head is not important.
assert h3 == g.add_hyperarc((2, 4), 3)
# NOTE: The output of get_head() is sorted.
assert g.get_head(h3) == (2,4)
assert g.get_tail(h3) == 3
As above, add_hyperarc() has a tuple of vertex identifiers, head, as its 1st argument and a vertex identifier, tail, as its 2nd argument, and returns the identifier of a hyperarc having the head and the tail.
The vertices and the hyperarcs added so far can be obtained by get_vertices() and get_hyperarcs(), which respecitvely return a tuple of vertex identifiers and a tuple of hyperarc identifiers, as follows.
assert set(g.get_vertices()) == {1, 2, 3, 4}
assert set(g.get_hyperarcs()) == H
Hyperarcs that are incident to a vertex can be obtained by get_hyperarcs_from() and get_hyperarcs_to(), which respectively return a tuple of hyperarcs emanating from a vertex and a tuple of hyperarcs pointing to a vertex, as follows.
assert set(g.get_hyperarcs_from(1)) == {h1, h2}
assert set(g.get_hyperarcs_to(3)) == {h3}
# exceptinal cases
assert set(g.get_hyperarcs_from(3)) == set()
assert set(g.get_hyperarcs_to(1)) == set()
Vertices and hyperarcs can be assigned labels, if necessary, when they are added.
gg = DirectedHypergraph()
gg.add_vertex(1, label="A")
gg.add_vertex(2, label="B")
gg.add_vertex(3, label="C")
gg.add_vertex(4, label="D")
h1 = gg.add_hyperarc((1,), 2, label="A->B")
h2 = gg.add_hyperarc((1,), 4, label="A->D")
h3 = gg.add_hyperarc((4, 2), 3, label="B,D->C")
assert gg.get_vertex_label(4) == "D"
assert gg.get_hyperarc_label(h3) == "B,D->C"
If you prefer to use vertex labels, call add_vertex() for all vertices to which labels are to be assigned and then call add_hyperarc(). Otherwise, add_hyperarc() will add vertices appearing in head or tail so that they have vertex identifiers as their labels.
A directed hypergraph can be rendered as follows.
gg.render(filename="sample", format="png")
As a result, sample.png will be generated. The arugments of render() are the same as those of render() of Graphviz. See User Guide of Graphviz .
Bugs/Requests/Discussions
Please report bugs and requests from GitHub Issues , and ask questions from GitHub Discussions .
License
Please see LICENSE .
Metadata
Release files for dhgraph 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dhgraph-1.0.0.tar.gz | 5.1 kB | Without provenance | Details for dhgraph-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dhgraph-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dhgraph-1.0.0-py3-none-any.whl |
Total release size: 10.8 kB
Release files / dhgraph-1.0.0.tar.gz
| Download URL | dhgraph-1.0.0.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f8f74ec92b0526f98cba720a5a50cd2cb146cd6376e6858925d5806c26a577a
|
|
BLAKE2b-256 checksum How to use checksums |
add37a85fcee37d7f10a4bec6d233d985430c079ae06a30d30c49553c489e297
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Release files / dhgraph-1.0.0-py3-none-any.whl
| Download URL | dhgraph-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b1bc8cf74745a48702841b86beb9e6715ced74d5e1715c91ffad2e5cff4564c9
|
|
BLAKE2b-256 checksum How to use checksums |
3aa602bc30698da268f96ab6a46138caec7553014f8397a1730f4d9b520b9875
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
|
Security for dhgraph 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.