https://github.com/fibo/iper
Hypergraphs for breakfast
https://github.com/fibo/iper
graph-theory hypergraph
Last synced: 8 months ago
JSON representation
Hypergraphs for breakfast
- Host: GitHub
- URL: https://github.com/fibo/iper
- Owner: fibo
- License: mit
- Created: 2013-07-25T09:56:44.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-01-24T01:12:47.000Z (about 6 years ago)
- Last Synced: 2025-03-28T17:11:11.742Z (12 months ago)
- Topics: graph-theory, hypergraph
- Language: JavaScript
- Homepage: http://g14n.info/iper/
- Size: 525 KB
- Stars: 6
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# iper
> Hypergraphs for breakfast!
[Installation](#installation) |
[API](#api) |
[Examples](#examples) |
[License](#license)
[](https://nodejs.org/en/) [](http://badge.fury.io/js/iper) [](https://travis-ci.org/fibo/iper?branch=master) [](https://gemnasium.com/fibo/iper) [](https://coveralls.io/r/fibo/iper?branch=master) [](http://g14n.info/iper/test)
[](https://github.com/feross/standard)
[](https://nodei.co/npm-dl/iper/)
## Installation
With [npm](https://npmjs.org/) do
```bash
npm install iper
```
## API
### `new Graph([graph])`
> Hypergraph constructor.
```javascript
const Graph = require('iper').Graph
const graph = new Graph()
```
* **@param** `{Object}` [graph]
* **@param** `{Object}` [graph.edges]
* **@param** `{Object}` [graph.nodes]
* **@param** `{Boolean}` [graph.multigraph] can contain duplicated edges
* **@param** `{Boolean}` [graph.pseudograph] is a multigraph with loops allowed
* **@param** `{Number}` [graph.uniform] all edges have the same cardinality (i.e. number of nodes)
### `graph.addEdge(nodeIds)`
> Add an hyperedge that connects given nodeIds.
* **@param** `{Array}` nodeIds
* **@returns** `{String}` id
### `graph.addNode(data)`
> Add a node, containing given data.
```javascript
var nodeId = graph.addNode({ label: 'foo' })
```
* **@param** `{*}` [data]
* **@returns** `{String}` id of the node created
### `graph.degreeOf(nodeId)`
> Returns the degree of a node, that is the number of incident edges with loops counted twice.
* **@param** `{String}` id
* **@returns** `{void}`
### `graph.delEdge(edgeId)`
> Delete edge by given id.
The node id will be removed from every edge connected.
If some edge after this operation will result having only one or zero
vertices left, it will be removed too.
* **@param** `{String}` edgeId
* **@returns** `{void}`
### `graph.delNode(nodeId)`
> Delete node by given id.
* **@param** `{String}` nodeId
* **@returns** `{void}`
### `graph.generateId()`
> Returns a random string to be used as id.
* **@returns** `{String}`
Override this method if you want to customize how ids are generated, for example
```javascript
const uniqueid = require('lodash.uniqueid')
const Graph = require('iper').Graph
class MyGraph extends Graph {
generateId () {
return uniqueid()
}
}
module.exports = MyGraph
```
### `graph.getRank()`
> Returns the max cardinality of any of the edges in the hypergraph.
* **@returns** `{Number}`
## Examples
### Classic graph
```javascript
const Graph = require('iper').Graph
const classicGraph = new Graph({ uniform: 2 })
```
## License
[MIT](http://www.g14n.info/mit-license)