Détail du package

graphology-generators

graphology25.3kMIT0.11.2

Various graph generators for graphology.

graph, graphology, generators, erdos renyi

readme

Graphology Generators

Various graph generators to be used with graphology.

Installation

npm install graphology-generators

Usage

Classic graphs

Complete

Creates a complete graph.

import Graph, {UndirectedGraph} from 'graphology';
import {complete} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import complete from 'graphology-generators/classic/complete';

// Creating a complete graph
const graph = complete(Graph, 10);

// Using another constuctor to create, say, a complete undirected graph
const graph = complete(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Empty

Creates an empty graph with the desired number of nodes and no edges.

import Graph, {UndirectedGraph} from 'graphology';
import {empty} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import empty from 'graphology-generators/classic/empty';

// Creating an empty graph
const graph = empty(Graph, 10);

// Using another constuctor to create, say, an empty undirected graph
const graph = empty(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Ladder

Creates a ladder graph with the desired length. Note that the generated graph will logically have twice the number of nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {ladder} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import ladder from 'graphology-generators/classic/ladder';

// Creating a ladder graph
const graph = ladder(Graph, 10);

// Using another constuctor to create, say, a undirected ladder graph
const graph = ladder(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • length number: length of the ladder.

Path

Creates a path graph.

import Graph, {UndirectedGraph} from 'graphology';
import {path} from 'graphology-generators/classic';
// Alternatively, if you only want to load relevant code
import path from 'graphology-generators/classic/path';

// Creating a path graph
const graph = path(Graph, 10);

// Using another constuctor to create, say, a path undirected graph
const graph = path(UndirectedGraph, 10);

Arguments

  • constructor Class: a graphology constructor.
  • order number: number of nodes in the generated graph.

Community graphs

Caveman

Creates a Caveman graph containing l components of k nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {caveman} from 'graphology-generators/community';
// Alternatively, if you only want to load relevant code
import caveman from 'graphology-generators/community/caveman';

// Creating a caveman graph
const graph = caveman(Graph, 6, 8);

Arguments

  • constructor Class: a graphology constructor.
  • l number: number of components in the graph.
  • k number: number of nodes of the components.

Connected Caveman

Creates a Connected Caveman graph containing l components of k nodes.

import Graph, {UndirectedGraph} from 'graphology';
import {connectedCaveman} from 'graphology-generators/community';
// Alternatively, if you only want to load relevant code
import connectedCaveman from 'graphology-generators/community/connected-caveman';

// Creating a connected caveman graph
const graph = connectedCaveman(Graph, 6, 8);

Arguments

  • constructor Class: a graphology constructor.
  • l number: number of components in the graph.
  • k number: number of nodes of the components.

Random graphs

Clusters

Creates a graph with the desired number of nodes & edges and having a given number of clusters.

import Graph from 'graphology';
import {clusters} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import clusters from 'graphology-generators/random/clusters';

// Creating a random clustered graph
const graph = clusters(Graph, {
  order: 100,
  size: 1000,
  clusters: 5
});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • order number: number of nodes of the generated graph.
    • size number: number of edges of the generated graph.
    • clusters number: number of clusters of the generated graph.
    • clusterDensity ?number [0.5]: Probability that an edge will link two nodes of the same cluster.
    • rng ?function: custom RNG function.

Erdos-Renyi

Creates an Erdos-Renyi, or binomial graph.

import Graph from 'graphology';
import {erdosRenyi} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import erdosRenyi from 'graphology-generators/random/erdos-renyi';

// Creating a binomial graph
const graph = erdosRenyi(Graph, {order: 10, probability: 0.5});

// If your graph is sparse (low probability), you can use the `sparse` version
// which runs in O(m + n) rather than O(n^2)
const graph = erdosRenyi.sparse(Graph, {order: 1000, probability: 0.1});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • order number: number of nodes of the generated graph.
    • probability number: probability for edge creation. (i.e. density you try to approximate in the generated graph).
    • approximateSize: alternatively, you can pass an approximate number of edges you are trying to get in the generated graph.
    • rng ?function: custom RNG function.

Girvan-Newman

Creates a Girvan-Newman random graph as described in:

Community Structure in social and biological networks. Girvan Newman, 2002. PNAS June, vol 99 n 12

import Graph from 'graphology';
import {girvanNewman} from 'graphology-generators/random';
// Alternatively, if you only want to load relevant code
import girvanNewman from 'graphology-generators/random/girvan-newman';

// Creating a binomial graph
const graph = girvanNewman(Graph, {zOut: 4});

Arguments

  • constructor Class: a graphology constructor.
  • options object: options:
    • zOut number: zout parameter.
    • rng ?function: custom RNG function.

Small graphs

Krackhardt kite

Returns the Krackhardt kite graph.

import Graph from 'graphology';
import {krackhardtKite} from 'graphology-generators/small';
// Alternatively, if you only want to load relevant code
import krackhardtKite from 'graphology-generators/small/krackhardt-kite';

// Creating a random clustered graph
const graph = krackhardtKite(Graph);

Arguments

  • constructor Class: a graphology constructor.

Social graphs

Florentine Families

Returns the Florentine families' graph.

import Graph from 'graphology';
import {florentineFamilies} from 'graphology-generators/florentine-families';
// Alternatively, if you only want to load relevant code
import florentineFamilies from 'graphology-generators/social/florentine-families';

// Generating the graph
const graph = florentineFamilies(Graph);

Arguments

  • constructor Class: a graphology constructor.

Karate Club

Returns Zachary's karate club graph.

import Graph from 'graphology';
import {karateClub} from 'graphology-generators/karate-club';
// Alternatively, if you only want to load relevant code
import karateClub from 'graphology-generators/social/karate-club';

// Generating the graph
const graph = karateClub(Graph);

Arguments

  • constructor Class: a graphology constructor.

changelog

Changelog

0.23.2

  • Fixing a #.mergeUndirectedEdgeWithKey & #.updateUndirectedEdgeWithKey bug when source & target are given in the reverse order.

0.23.1

  • Fixing #.copy not copying the graph's attributes.
  • Improving performance of #.copy.

0.23.0

  • Adding #.updateAttributes.
  • Adding #.updateNodeAttributes.
  • Adding #.updateEdgeAttributes.
  • Adding #.getSourceAttribute, #.getTargetAttribute, #.getOppositeAttribute and friends.
  • Aligning #.updateEachEdgeAttributes callback arguments to #.forEachEdge.
  • Improving #.merge* and #.update* function by returning useful information.
  • Improving #.opposite performance.

Migration guide

This release should only affect you in the following cases:

  1. You were relying on the keys returned by #.mergeEdge, #.updateEdge etc. In which case those methods now return a useful tuple containing said key as its first element as well as additional information about whether target elements already existed in the graph or not.
  2. Some hidden adjacency iteration methods were mangled and are still hidden. This could only affect you if you were using #.forEach, #.find or #.adjacency (not to be confused with their node, edge & neighbor counterparts).

0.22.2

  • Fixing #.mergeEdge & #.updateEdge error messages.
  • Improving performance of #.addEdge etc. (less deopt).
  • Improving #.inspect output wrt undirected multi edges.

0.22.1

  • Fixing prepublishOnly script and shipped package.

0.22.0

  • Rolling back to robust generated ids for edges.
  • Adding #.mapNodes, #.filterNodes, #.reduceNodes, #.findNode #.someNode, #.everyNode.
  • Adding #.mapEdges, #.filterEdges, #.reduceEdges, #.findEdge #.someEdge, #.everyEdge.
  • Adding #.mapNeighbors, #.filterNeighbors, #.reduceNeighbors, #.findNeighbor #.someNeighbor, #.everyNeighbor.
  • Adding #.degreeWithoutSelfLoops.
  • Changing #.forEach*Until methods to #.find* methods.
  • Dropping #.hasGeneratedKey.
  • Dropping the generated last argument to edge & adjacency iterations.
  • Dropping the edgeKeyGenerator instanciation option.
  • Dropping second argument of #.degree.
  • Changing #.neighbors(source, target) to #.areNeighbors.
  • Changing iterator entries to objects rather than arrays.
  • #.exportEdge will now always return a key.
  • Fixing mutability bug with #.copy.
  • Fixing adjacency iterator items missing undirected.
  • Fixing edge iterator items missing undirected.
  • Fixing bug related to instance counters and #.clear, #.clearEdges.
  • Improving #.copy peformance.
  • Improving #.areNeighbors performance.
  • Improving #.forEachNode performance.
  • Upgrading obliterator and improving iterator-based methods.

Migration guide

This release should only affect you in the following use-cases:

  1. You were using #.forEach*Until methods, in which case you should replace them by the relevant #.find* or #.some* method.
  2. You were using the boolean second argument to the #.degree methods. Replace those calls by #.degreeWithoutSelfLoops.
  3. You were using the (well-hidden) two-arguments polymorphism of #.neighbors. Replace those calls by #.areNeighbors.
  4. You were using iterators in which case the yielded entries are now objects rather than arrays and should be easier to destructure to access the parts you need.
  5. You were doing despicable things with automatically generated keys.

0.21.1

  • Fixing #.removeNodeAttribute error message.
  • Upgrading types to 0.20.0.

0.21.0

  • *Until methods now return whether they broke.
  • Fixing a bug with #.forEachNodeUntil.

0.20.0

  • Changing default edge key generator to simple incremental id.

0.19.3

  • Fixing issues related to rollup bundling.

0.19.2

  • Fixing #.dropNode bug.

0.19.1

  • Optimizing #.dropNode.

0.19.0

  • Adding #.forEachUntil.
  • Adding #.forEachNodeUntil.
  • Adding #.forEachEdgeUntil.
  • Adding #.forEachNeighborUntil.
  • Adding #.updateNode.
  • Adding #.updateEdge.
  • Adding attributes to attributesUpdated events.
  • Adding attributes to nodeAttributesUpdated events.
  • Adding attributes to edgeAttributesUpdated events.
  • Adding #.updateEachNodeAttributes.
  • Adding #.updateEachEdgeAttributes.
  • Passing undirected & generatedKey to #.forEachEdge callbacks.
  • Changing #.forEach & #.adjacency semantics to something actually useful.
  • Optimizing *AttributesUpdated events payload.
  • Optimizing #.edges(A, B).
  • Optimizing #.forEachEdge.
  • Optimizing #.mergeEdge.
  • Optimizing #.edges and #.nodes.
  • Optimizing #.import.
  • Fixing #.edges(A, B) with directed self loops.
  • Fixing #.mergeEdgeWithKey edge cases.
  • Fixing #.mergeAttributes event payload.
  • Fixing #.edgeEntries stack overflow with undirected edges.
  • Dropping before and after from replace events metadata.
  • Dropping value from set events metadata.
  • Dropping overkill toString method.
  • Correctly emitting nodeAttributesUpdated event when node is merged.
  • Correctly emitting edgeAttributesUpdated event when edge is merged.
  • graphology-types is now a peer dependency.

0.18.0

  • Adding #.implementation.
  • Adding #.hasExtremity.
  • Adding #.selfLoopCount, #.directedSelfLoopCount & #.undirectedSelfLoopCount.
  • Adding #.hasGeneratedKey.
  • Renaming #.directed & #.undirected to #.isDirected & #.isUndirected.
  • Renanming #.selfLoop to #.isSelfLoop.
  • Serializing options & accepting them with #.from static methods.
  • Improving performance of #.opposite.
  • Improving serialization performance.
  • Updating type declarations & adding generics.
  • Optimizing various degree methods.
  • Optimizing graph attributes methods.
  • Fixing edges & neighbors iteration regarding self loops in the directed case.

0.17.1

  • Optimizing #.forEachEdge methods.

0.17.0

  • Changing packaging system.
  • Fixing browser bundle.

0.16.1

  • Bundle fixes (@zakjan).

0.16.0

  • Proper #.nullCopy & #.emptyCopy methods.

0.15.2

  • More flexible dependency to graphology-types.

0.15.1

  • Adding missing MultiGraph export.
  • Adding missing error typings.

0.15.0

  • TypeScript support.
  • Adding possibility to merge options using #.emptyCopy.

0.14.1

  • Fixing #.mergeEdge for the self loop case.

0.14.0

  • Adding Symbol.iterator to the prototype.
  • Fixing custom inspection for node >= 10.

0.13.1

  • Fixing edge attributes methods with typed graphs.

0.13.0

  • Adding #.nodeEntries.
  • Adding #.edgeEntries.
  • Adding #.neighborEntries.
  • Adding #.forEach.
  • Adding #.adjacency.

0.12.0

  • Adding #.clearEdges.
  • Adding #.forEachEdge & alii.
  • Adding #.forEachNode & alii.
  • Adding #.forEachNeighbor & alii.
  • Adding #.inboundNeighbors & #.outboundNeighbors.
  • Adding #.inboundEdges & #.outboundEdges.
  • Dropping #.addNodesFrom.
  • Dropping #.dropNodes & #.dropEdges.
  • Dropping plural serialization methods.
  • Dropping defaultNodeAttributes & defaultEdgeAttributes.
  • Fixing semantics of #.inEdges & #.outEdges for arity 2.
  • Improving performance of edges-related methods.
  • Improving performance of internal indices.
  • Improving performance of #.mergeNode.
  • Fixing edge-case deopt for #.dropEdges.
  • Fixing bug related to multigraphs' neighbors.
  • Attribute copy is now done on serialization.
  • Completely reworking internal indices.

0.11.4

  • Improving performance of neighbors-related methods.
  • Improving performance of edges-related methods.

0.11.3

  • Fixing issues related to the obliterator dependencies.

0.11.2

  • Fixing an issue with #.mergeNode & string coercion.

0.11.1

  • Fixing the #.edges for undirected graphs.

0.11.0

  • Adding #.directedSize & #.undirectedSize.

0.10.2

  • Performance enhancements.

0.10.1

  • Performance enhancements.
  • Fixing a bug with #.mergeEdge & undirected edges.

0.10.0

  • Adding basic edges iterators.
  • Fixing #.inspect.

0.9.1

  • Fixing a bug concerning #.hasEdge & typed graphs.

0.9.0

  • Major write performance improvements.
  • Shifting the default edge key generation system.
  • Dropping index' laziness.

0.8.0

  • Adding the #.nodesIterator method.
  • Performance improvements.

0.7.1

  • Fixing a bug related to typed graphs' attributes.
  • Fixing a bug with the dropping methods.

0.7.0

  • Adding the #.edge & variants methods.
  • Adding the #.upgradeToMixed method.
  • Adding the #.upgradeToMulti method.
  • Refactoring indices methods.

0.6.0

  • Dropping inbound & outbound iteration methods.
  • Dropping useless counting iteration methods.
  • Dropping bunch consuming polymorphisms from iteration methods.
  • Refactoring internal indices for undirected graphs.
  • Improving performance.

0.5.4

  • Fixing degree methods for typed graphs.

0.5.3

  • Improving performance.

0.5.2

  • Node.js 0.12.x compatibility.
  • Fixing bug related to the graph's string coercion.
  • Improving performance.
  • Better error message when adding a self-loop when it's not authorized.

0.5.1

  • Better unit tests.
  • Internal refactoring.

0.5.0

  • Implementing the static #.from method & switching constructor paradigm.
  • Fixing bug related to the attributesUpdated event.
  • Adding more errors related to attributes' setters.
  • Adding typed edges attributes' getters/setters.
  • Rewrote internal indices.
  • Dropping #.getEdge & friends.
  • Dropping #.selfLoops.

0.4.2

  • Adding missing built files to the npm package.

0.4.1

  • Adding missing attributes in export.

0.4.0

  • Adding #.removeNodeAttribute & #.removeEdgeAttribute that was actually missing from earlier versions.
  • Adding graph attributes.
  • nodeUpdated & edgeUpdated changing to nodeAttributesUpdated & edgeAttributesUpdated respectively.

0.3.0

  • Adding merge flags to import methods.

0.2.0

  • Adding #.hasNodeAttribute & #.hasEdgeAttribute.
  • Adding #.removeNodeAttribute & #.removeEdgeAttribute.
  • Adding #.mergeNode.
  • Adding #.mergeEdge, #.mergeEdgeWithKey and friends.
  • Renaming #.relatedNode to #.opposite.
  • Dropping the onDuplicateNode & onDuplicateEdge options.

0.1.1

  • Fixing the argument passed to the edgeKeyGenerator function.
  • Fixing a bug where source & target of an edge were not internally coerced to strings.

0.1.0

Initial version compliant to the specs.