-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: tests | ||
on: [push] | ||
jobs: | ||
run: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
python-version: ["3.9", "3.10", "3.11"] | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@master | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install tox tox-gh-actions poetry | ||
- name: Poetry Install Dependencies | ||
run: | | ||
poetry install --no-interaction | ||
- name: Test with tox | ||
run: poetry run tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
simpgraph: Minimal Python Module for Unordered Graphs | ||
================================================================ | ||
|
||
Introduction | ||
============ | ||
``simpgraph`` is a simple and minimal implementation of the class | ||
of unordered graphs. | ||
|
||
Installation | ||
============ | ||
|
||
.. code:: shell-session | ||
$ pip install simpgraph | ||
Usage | ||
===== | ||
|
||
Let us import ``simpgraph`` module, create an empty graph, | ||
and add edges. | ||
|
||
.. code:: python | ||
from simpgraph import SimpGraph | ||
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. | ||
|
||
.. 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. | ||
|
||
.. code:: python | ||
assert set(g.get_hyperarcs_from(1)) == {h1, h2} | ||
assert set(g.get_hyperarcs_to(3)) == {h3} | ||
# exceptional 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 graph can be rendered as follows. | ||
|
||
.. code:: python | ||
gg.render(filename="sample", format="png") | ||
As a result, ``sample.png`` will be generated. | ||
The arguments 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/simpgraph/issues>`__ , and | ||
ask questions from `GitHub Discussions <https://github.com/toda-lab/simpgraph/discussions>`__ . | ||
|
||
License | ||
======= | ||
|
||
Please see `LICENSE <https://github.com/toda-lab/simpgraph/blob/main/LICENSE>`__ . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[tool.poetry] | ||
name = "simpgraph" | ||
version = "1.0.0" | ||
description = "Simple and minimal Python module for unordered graphs" | ||
authors = ["Takahisa Toda <toda@disc.lab.uec.ac.jp>"] | ||
license = "MIT" | ||
readme = "README.rst" | ||
repository = "https://github.com/toda-lab/simpgraph" | ||
keywords = [ | ||
"mathematics", | ||
"graph", | ||
] | ||
classifiers = [ | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Topic :: Scientific/Engineering :: Mathematics", | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.8" | ||
graphviz = "^0.20.3" | ||
|
||
pytest = { version ="^8.1.1", optional = true } | ||
Sphinx = { version = "^7.1.2", optional = true } | ||
sphinx-removed-in = { version = "^0.2.1", optional = true } | ||
sphinxcontrib-trio = { version = "^1.1.2", optional = true } | ||
pallets-sphinx-themes = { version = "^2.1.1", optional= true } | ||
|
||
|
||
[tool.poetry.extras] | ||
test = ["pytest"] | ||
docs = ["Sphinx", "sphinx-removed-in", "sphinxcontrib-trio", "pallets-sphinx-themes"] | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# simpgraph: Simple Python module for unordered graphs | ||
|
||
import importlib.metadata | ||
|
||
__version__ = importlib.metadata.version(__package__) | ||
|
||
from .simpgraph import SimpGraph | ||
|
||
__all__ = [ | ||
"SimpGraph", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[tox] | ||
skip_missing_interpreters=true | ||
envlist = | ||
build | ||
build_docs | ||
py{39,310,311} | ||
isolated_build = True | ||
|
||
[testenv:build] | ||
allowlist_externals = poetry | ||
skip_install = true | ||
commands = | ||
poetry build | ||
|
||
[testenv:build_docs] | ||
allowlist_externals = poetry | ||
skip_install = true | ||
commands = | ||
poetry install --extras "docs" | ||
poetry run sphinx-build -n -T -b html -d {envtmpdir}/doctrees docs docs/_build/html | ||
|
||
[testenv] | ||
allowlist_externals = poetry | ||
skip_install = true | ||
commands= | ||
poetry install --extras "test" | ||
poetry run pytest |