dhgraph


Namedhgraph JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/toda-lab/dhgraph
SummaryPython Module for Directed Hypergraphs
upload_time2024-03-24 07:51:45
maintainerNone
docs_urlNone
authorTakahisa Toda
requires_python<4.0,>=3.8
licenseMIT
keywords mathematics hypergraph directed hypergraph
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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
============

.. code:: shell-session

    $ pip install dhgraph

Usage
=====

Let us import ``dhgraph`` module, create an empty directed hypergraph object, 
and add hyperarcs as follows.

.. code:: python

    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.

.. code:: python

    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.

.. code:: python

    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.

.. code:: python

    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.

.. code:: python

    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
<https://graphviz.readthedocs.io/en/stable/manual.html>`__ .

Bugs/Requests/Discussions
=========================

Please report bugs and requests from `GitHub Issues
<https://github.com/toda-lab/dhgraph/issues>`__ , and 
ask questions from `GitHub Discussions <https://github.com/toda-lab/dhgraph/discussions>`__ .

License
=======

Please see `LICENSE <https://github.com/toda-lab/dhgraph/blob/main/LICENSE>`__ .


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/toda-lab/dhgraph",
    "name": "dhgraph",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "mathematics, hypergraph, directed hypergraph",
    "author": "Takahisa Toda",
    "author_email": "toda@disc.lab.uec.ac.jp",
    "download_url": "https://files.pythonhosted.org/packages/ad/d3/7a85fcee37d7f10a4bec6d233d985430c079ae06a30d30c49553c489e297/dhgraph-1.0.0.tar.gz",
    "platform": null,
    "description": "dhgraph: Python Modlue for Directed Hypergraphs\n===============================================\n\nIntroduction\n============\nA *directed hypergraph* is a generalization of digraph.\nIt consists of a set of *vertices* ``V`` and a set of *hyperarcs* ``H``.\nA hyperarc is a pair of a nonempty subset of ``V`` (called *head*) and a vertex\nof ``V`` (called *tail*).\n\nInstallation\n============\n\n.. code:: shell-session\n\n    $ pip install dhgraph\n\nUsage\n=====\n\nLet us import ``dhgraph`` module, create an empty directed hypergraph object, \nand add hyperarcs as follows.\n\n.. code:: python\n\n    from dhgraph import DirectedHypergraph\n\n    g = DirectedHypergraph()\n\n    #   1 ---> 2\n    #   |      |\n    #   v      v\n    #   4----> 3\n\n    h1 = g.add_hyperarc((1,),  2)\n    h2 = g.add_hyperarc((1,),  4)\n    h3 = g.add_hyperarc((4, 2), 3)\n    H = {h1, h2, h3} # Set of hyperarc identifiers, used later.\n\n    # NOTE: The order of vertices in head is not important.\n    assert h3 == g.add_hyperarc((2, 4), 3) \n\n    # NOTE: The output of get_head() is sorted.\n    assert g.get_head(h3) == (2,4)\n    assert g.get_tail(h3) == 3\n\nAs above, ``add_hyperarc()`` has a tuple of vertex identifiers, head, as its 1st\nargument and a vertex identifier, tail, as its 2nd argument, \nand returns the identifier of a hyperarc having the head and the tail.\n\nThe vertices and the hyperarcs added so far can be obtained \nby ``get_vertices()`` and ``get_hyperarcs()``, which respecitvely return \na tuple of vertex identifiers and a tuple of hyperarc identifiers, as follows.\n\n.. code:: python\n\n    assert set(g.get_vertices())  == {1, 2, 3, 4}\n    assert set(g.get_hyperarcs()) == H\n\nHyperarcs that are incident to a vertex can be obtained by\n``get_hyperarcs_from()`` and ``get_hyperarcs_to()``, which respectively return\na tuple of hyperarcs emanating from a vertex and a tuple of hyperarcs pointing\nto a vertex, as follows.\n\n.. code:: python\n\n    assert set(g.get_hyperarcs_from(1)) == {h1, h2}\n    assert set(g.get_hyperarcs_to(3))   == {h3}\n    # exceptinal cases\n    assert set(g.get_hyperarcs_from(3)) == set()\n    assert set(g.get_hyperarcs_to(1))   == set()\n\nVertices and hyperarcs can be assigned labels, if necessary, when they are added.\n\n.. code:: python\n\n    gg = DirectedHypergraph()\n\n    gg.add_vertex(1, label=\"A\")\n    gg.add_vertex(2, label=\"B\")\n    gg.add_vertex(3, label=\"C\")\n    gg.add_vertex(4, label=\"D\")\n    h1 = gg.add_hyperarc((1,),   2, label=\"A->B\")\n    h2 = gg.add_hyperarc((1,),   4, label=\"A->D\")\n    h3 = gg.add_hyperarc((4, 2), 3, label=\"B,D->C\")\n    \n    assert gg.get_vertex_label(4)    == \"D\"\n    assert gg.get_hyperarc_label(h3) == \"B,D->C\"\n\nIf you prefer to use vertex labels, call ``add_vertex()`` \nfor all vertices to which labels are to be assigned and then call ``add_hyperarc()``.\nOtherwise, ``add_hyperarc()`` will add vertices appearing in head or tail \nso that they have vertex identifiers as their labels.\n\nA directed hypergraph can be rendered as follows.\n\n.. code:: python\n\n    gg.render(filename=\"sample\", format=\"png\")\n\nAs a result, ``sample.png`` will be generated.\nThe arugments of ``render()`` are the same as those of ``render()`` of\nGraphviz.\nSee `User Guide of Graphviz\n<https://graphviz.readthedocs.io/en/stable/manual.html>`__ .\n\nBugs/Requests/Discussions\n=========================\n\nPlease report bugs and requests from `GitHub Issues\n<https://github.com/toda-lab/dhgraph/issues>`__ , and \nask questions from `GitHub Discussions <https://github.com/toda-lab/dhgraph/discussions>`__ .\n\nLicense\n=======\n\nPlease see `LICENSE <https://github.com/toda-lab/dhgraph/blob/main/LICENSE>`__ .\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python Module for Directed Hypergraphs",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://dhgraph.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/toda-lab/dhgraph",
        "Repository": "https://github.com/toda-lab/dhgraph"
    },
    "split_keywords": [
        "mathematics",
        " hypergraph",
        " directed hypergraph"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3aa602bc30698da268f96ab6a46138caec7553014f8397a1730f4d9b520b9875",
                "md5": "e6ab51221ade726a6d47f15f957b83e6",
                "sha256": "b1bc8cf74745a48702841b86beb9e6715ced74d5e1715c91ffad2e5cff4564c9"
            },
            "downloads": -1,
            "filename": "dhgraph-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e6ab51221ade726a6d47f15f957b83e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 5715,
            "upload_time": "2024-03-24T07:51:42",
            "upload_time_iso_8601": "2024-03-24T07:51:42.830657Z",
            "url": "https://files.pythonhosted.org/packages/3a/a6/02bc30698da268f96ab6a46138caec7553014f8397a1730f4d9b520b9875/dhgraph-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "add37a85fcee37d7f10a4bec6d233d985430c079ae06a30d30c49553c489e297",
                "md5": "6abd91f87e7f3ec74026cfdda7c02454",
                "sha256": "0f8f74ec92b0526f98cba720a5a50cd2cb146cd6376e6858925d5806c26a577a"
            },
            "downloads": -1,
            "filename": "dhgraph-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6abd91f87e7f3ec74026cfdda7c02454",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 5067,
            "upload_time": "2024-03-24T07:51:45",
            "upload_time_iso_8601": "2024-03-24T07:51:45.106839Z",
            "url": "https://files.pythonhosted.org/packages/ad/d3/7a85fcee37d7f10a4bec6d233d985430c079ae06a30d30c49553c489e297/dhgraph-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-24 07:51:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "toda-lab",
    "github_project": "dhgraph",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "dhgraph"
}
        
Elapsed time: 0.23762s