iper

Hypergraphs for breakfast!

Installation | API | Examples | License

Node engine NPM version Build Status Dependency Status Coverage Status Test page

js-standard-style

NPM

Installation

With npm do

npm install iper

API

new Graph([graph])

Hypergraph constructor.

const Graph = require('iper').Graph

const graph = new Graph()

graph.addEdge(nodeIds)

Add an hyperedge that connects given nodeIds.

graph.addNode(data)

Add a node, containing given data.

var nodeId = graph.addNode({ label: 'foo' })

graph.degreeOf(nodeId)

Returns the degree of a node, that is the number of incident edges with loops counted twice.

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.

graph.delNode(nodeId)

Delete node by given id.

graph.generateId()

Returns a random string to be used as id.

Override this method if you want to customize how ids are generated, for example

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.

Examples

Classic graph

const Graph = require('iper').Graph

const classicGraph = new Graph({ uniform: 2 })

License

MIT