![Static Badge](https://img.shields.io/badge/homepage-blue?link=https%3A%2F%2Fgithub.com%2Fjmorris335%2FConstraintHg%2Fwiki)
![Read the Docs](https://img.shields.io/readthedocs/constrainthg?link=https%3A%2F%2Fconstrainthg.readthedocs.io%2Fen%2Flatest%2Findex.html) ![Static Badge](https://img.shields.io/badge/tests-passing-brightgreen) ![GitHub Release](https://img.shields.io/github/v/release/jmorris335/ConstraintHg?include_prereleases&display_name=tag) ![GitHub last commit](https://img.shields.io/github/last-commit/jmorris335/ConstraintHg)
# ConstraintHg
This repository enables usage of hypergraphs to define and execute system models. **It is not a rigorous data storage solution. Do not use this as a database.** Note that this repo is under active development (no official release yet), therefore changes may occur rapidly. Fork the repository before using it.
## Install
ConstraintHg is listed on the Python Package Index. Just use `pip install constrainthg` to get started.
# Introduction
Hypergraphs are normal graphs but without the constraint that edges must only link between two nodes. Because of this expanded generality, hypergraphs can be used to model more complex relationships. For instance, the relationship `A + B = C` is a multinodal relationship between three nodes, A, B, and C. You can think of all three nodes being linked by a 2D hyperedge, so that to move along that hyperedge you need at least two of three nodes.
An constraint hypergraph is a hypergraph where the relationships are constraints that can be solved for by some execution engine, generally via API calls. These constraints reveal the behavior of the system. The goal is for the hypergraph to be platform agnostic, while API calls allow for edges to be processed on any available software.
Processing a series of nodes and edges (a "route") is what constitutes a simulation, so one of the uses of an constraint hypergraph is enabling high-level simulation ability from any possible entry point in a system model.
## Getting started
*Note that this demo is found in [`demos/demo_basic.py`](https://github.com/jmorris335/ConstraintHg/blob/main/demos/demo_basic.py)*
Let's build a basic constraint hypergraph of the following equations:
- $A + B = C$
- $A = -D$
- $B = -E$
- $D + E = F$
- $F = -C$
First, import the classes.
```[python]
from constrainthg.hypergraph import Hypergraph
import constrainthg.relations as R
```
A hypergraph consists of edges that map between a set of nodes to a single node. We provide the mapping by defining a constraint function (many of which are already defined in the `relationships` module). The two relationships defined in the governing equations are addition and negation. Using the typical syntax, we refer to the functions defined in `relationships` with `R.<name>`, in this case `R.Rsum` and `R.Rnegate`. To make the hypergraph we'll need to compose the 5 edges (equations) given above.
```[python]
hg = Hypergraph()
hg.add_edge(['A', 'B'], 'C', R.Rsum)
hg.add_edge('A', 'D', R.Rnegate)
hg.add_edge('B', 'E', R.Rnegate)
hg.add_edge(['D', 'E'], 'F', R.Rsum)
hg.add_edge('F', 'C', R.Rnegate)
```
We can verify that the hypergraph was made correctly by tracing all possible paths for generating C using the `printPaths` function.
```[python]
print(hg.print_paths('C'))
```
This should give us the following output. Hyperedges are indicated with a `◯`, with the last source separated from other edges with a `●`.
```
└──C, cost=1
├◯─A, cost=0
├●─B, cost=0
└──F, cost=3
├◯─D, cost=1
│ └──A, cost=0
└●─E, cost=1
└──B, cost=0
```
Compute the value of $C$ by picking a set of source nodes (inputs), such as $A$ and $B$ or $A$ and $E$. Set values for the inputs and the solver will automatically calulate an optimized route to simulate $C$.
```[python]
print("**Inputs A and E**")
hg.solve('C', {'A':3, 'E':-7}, to_print=True)
print("**Inputs A and B**")
hg.solve('C', {'A':3, 'B':7}, to_print=True)
```
The output of the above should be:
```
**Inputs A and E**
└──C= 10, cost=3
└──F= -10, cost=2
├──D= -3, cost=1
│ └──A= 3, cost=0
└──E= -7, cost=0
**Inputs A and B**
└──C= 10, cost=1
├──A= 3, cost=0
└──B= 7, cost=0
```
Check out the [demos](https://github.com/jmorris335/ConstraintHg/tree/main/demos) directory for more examples.
## Licensing and Usage
Author: [John Morris](https://www.people.clemson.edu/jhmrrs/)
Organization: [PLM Center](https://github.com/Clemson-PLMC) at Clemson University
Contact: Reach out to my GitHub profile ([jmorris335](https://github.com/jmorris335))
Usage: An official release will *likely* be provided under the CC BY-NC-SA 4.0 license, but for now **all rights are reserved**. For usage, please reach out to the author directly.
Raw data
{
"_id": null,
"home_page": null,
"name": "constrainthg",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.1",
"maintainer_email": null,
"keywords": "hypergraphs, systems engineering",
"author": null,
"author_email": "John Morris <jhmrrs@clemson.edu>",
"download_url": "https://files.pythonhosted.org/packages/d9/78/ae7a540b4c8dcf1188935c68268b786062dc5f9a8d16f68ce3771dab4fb4/constrainthg-0.1.1.tar.gz",
"platform": null,
"description": "![Static Badge](https://img.shields.io/badge/homepage-blue?link=https%3A%2F%2Fgithub.com%2Fjmorris335%2FConstraintHg%2Fwiki)\n ![Read the Docs](https://img.shields.io/readthedocs/constrainthg?link=https%3A%2F%2Fconstrainthg.readthedocs.io%2Fen%2Flatest%2Findex.html) ![Static Badge](https://img.shields.io/badge/tests-passing-brightgreen) ![GitHub Release](https://img.shields.io/github/v/release/jmorris335/ConstraintHg?include_prereleases&display_name=tag) ![GitHub last commit](https://img.shields.io/github/last-commit/jmorris335/ConstraintHg)\n\n\n\n# ConstraintHg\nThis repository enables usage of hypergraphs to define and execute system models. **It is not a rigorous data storage solution. Do not use this as a database.** Note that this repo is under active development (no official release yet), therefore changes may occur rapidly. Fork the repository before using it.\n\n## Install\nConstraintHg is listed on the Python Package Index. Just use `pip install constrainthg` to get started.\n\n# Introduction\nHypergraphs are normal graphs but without the constraint that edges must only link between two nodes. Because of this expanded generality, hypergraphs can be used to model more complex relationships. For instance, the relationship `A + B = C` is a multinodal relationship between three nodes, A, B, and C. You can think of all three nodes being linked by a 2D hyperedge, so that to move along that hyperedge you need at least two of three nodes. \n\nAn constraint hypergraph is a hypergraph where the relationships are constraints that can be solved for by some execution engine, generally via API calls. These constraints reveal the behavior of the system. The goal is for the hypergraph to be platform agnostic, while API calls allow for edges to be processed on any available software.\n\nProcessing a series of nodes and edges (a \"route\") is what constitutes a simulation, so one of the uses of an constraint hypergraph is enabling high-level simulation ability from any possible entry point in a system model.\n\n## Getting started\n*Note that this demo is found in [`demos/demo_basic.py`](https://github.com/jmorris335/ConstraintHg/blob/main/demos/demo_basic.py)*\nLet's build a basic constraint hypergraph of the following equations:\n- $A + B = C$\n- $A = -D$\n- $B = -E$\n- $D + E = F$ \n- $F = -C$\n\nFirst, import the classes. \n```[python]\nfrom constrainthg.hypergraph import Hypergraph\nimport constrainthg.relations as R\n```\n\nA hypergraph consists of edges that map between a set of nodes to a single node. We provide the mapping by defining a constraint function (many of which are already defined in the `relationships` module). The two relationships defined in the governing equations are addition and negation. Using the typical syntax, we refer to the functions defined in `relationships` with `R.<name>`, in this case `R.Rsum` and `R.Rnegate`. To make the hypergraph we'll need to compose the 5 edges (equations) given above. \n```[python]\nhg = Hypergraph()\nhg.add_edge(['A', 'B'], 'C', R.Rsum)\nhg.add_edge('A', 'D', R.Rnegate)\nhg.add_edge('B', 'E', R.Rnegate)\nhg.add_edge(['D', 'E'], 'F', R.Rsum)\nhg.add_edge('F', 'C', R.Rnegate)\n```\n\nWe can verify that the hypergraph was made correctly by tracing all possible paths for generating C using the `printPaths` function.\n```[python]\nprint(hg.print_paths('C'))\n```\n\nThis should give us the following output. Hyperedges are indicated with a `\u25ef`, with the last source separated from other edges with a `\u25cf`.\n```\n\u2514\u2500\u2500C, cost=1\n \u251c\u25ef\u2500A, cost=0\n \u251c\u25cf\u2500B, cost=0\n \u2514\u2500\u2500F, cost=3\n \u251c\u25ef\u2500D, cost=1\n \u2502 \u2514\u2500\u2500A, cost=0\n \u2514\u25cf\u2500E, cost=1\n \u2514\u2500\u2500B, cost=0\n```\n\nCompute the value of $C$ by picking a set of source nodes (inputs), such as $A$ and $B$ or $A$ and $E$. Set values for the inputs and the solver will automatically calulate an optimized route to simulate $C$. \n```[python]\nprint(\"**Inputs A and E**\")\nhg.solve('C', {'A':3, 'E':-7}, to_print=True)\nprint(\"**Inputs A and B**\")\nhg.solve('C', {'A':3, 'B':7}, to_print=True)\n```\n\nThe output of the above should be:\n```\n**Inputs A and E**\n\u2514\u2500\u2500C= 10, cost=3\n \u2514\u2500\u2500F= -10, cost=2\n \u251c\u2500\u2500D= -3, cost=1\n \u2502 \u2514\u2500\u2500A= 3, cost=0\n \u2514\u2500\u2500E= -7, cost=0\n\n**Inputs A and B**\n\u2514\u2500\u2500C= 10, cost=1\n \u251c\u2500\u2500A= 3, cost=0\n \u2514\u2500\u2500B= 7, cost=0\n```\n\nCheck out the [demos](https://github.com/jmorris335/ConstraintHg/tree/main/demos) directory for more examples.\n\n## Licensing and Usage\nAuthor: [John Morris](https://www.people.clemson.edu/jhmrrs/) \nOrganization: [PLM Center](https://github.com/Clemson-PLMC) at Clemson University \nContact: Reach out to my GitHub profile ([jmorris335](https://github.com/jmorris335)) \nUsage: An official release will *likely* be provided under the CC BY-NC-SA 4.0 license, but for now **all rights are reserved**. For usage, please reach out to the author directly.\n",
"bugtrack_url": null,
"license": "All rights reserved",
"summary": "Methods for building and simulating constraint hypergraphs.",
"version": "0.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/jmorris335/ConstraintHg/issues",
"Documentation": "https://constrainthg.readthedocs.io/en/latest/",
"Homepage": "https://github.com/jmorris335/ConstraintHg/wiki",
"Repository": "https://github.com/jmorris335/ConstraintHg"
},
"split_keywords": [
"hypergraphs",
" systems engineering"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "192a900168fc0fb02d118179c131c16a70f64992e3427dcdc6f6a20dfccc5c4a",
"md5": "700ce0d9b6f3535bf276520bd88c830c",
"sha256": "9a275b8a143bbbe8dd8311df5c9c866ccfecd2273703dda318204bd8680f2314"
},
"downloads": -1,
"filename": "constrainthg-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "700ce0d9b6f3535bf276520bd88c830c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.1",
"size": 16654,
"upload_time": "2024-11-08T21:26:24",
"upload_time_iso_8601": "2024-11-08T21:26:24.117185Z",
"url": "https://files.pythonhosted.org/packages/19/2a/900168fc0fb02d118179c131c16a70f64992e3427dcdc6f6a20dfccc5c4a/constrainthg-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d978ae7a540b4c8dcf1188935c68268b786062dc5f9a8d16f68ce3771dab4fb4",
"md5": "3f0a60e3e6882126adebf1359d0206af",
"sha256": "d1c9458cd0e80eb57b39d0b0cfd40c292581a328bb37f154269d0e4d76464198"
},
"downloads": -1,
"filename": "constrainthg-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "3f0a60e3e6882126adebf1359d0206af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.1",
"size": 18769,
"upload_time": "2024-11-08T21:26:25",
"upload_time_iso_8601": "2024-11-08T21:26:25.183231Z",
"url": "https://files.pythonhosted.org/packages/d9/78/ae7a540b4c8dcf1188935c68268b786062dc5f9a8d16f68ce3771dab4fb4/constrainthg-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-08 21:26:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jmorris335",
"github_project": "ConstraintHg",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "constrainthg"
}