Various graph generators for graphology.
npm install graphology-generatorsVarious graph generators to be used with graphology.
```
npm install graphology-generators
- Classic graphs
- Complete
- Empty
- Ladder
- Path
- Community graphs
- Caveman
- Connected Caveman
- Random graphs
- Clusters
- Erdos-Renyi
- Girvan-Newman
- Small graphs
- Krackhardt Kite
- Social graphs
- Florentine Families
- Karate Club
#### Complete
Creates a complete graph.
`js
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.
`js
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.
`js
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.
`js
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.
#### Caveman
Creates a Caveman graph containing l components of k nodes.
`js
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.
`js
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.
#### Clusters
Creates a graph with the desired number of nodes & edges and having a given number of clusters.
`js
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.0.5
- 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_ []: 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.
`js
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
`js
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.
#### Krackhardt kite
Returns the Krackhardt kite graph.
`js
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.
#### Florentine Families
Returns the Florentine families' graph.
`js
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.
`js
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.