9.8. Graph Generation

This section describes the graph generation algorithms in the Neo4j Graph Algorithms library.

In certain use cases it is useful to generate random graphs, for example, for testing or benchmarking purposes. For that reason the Neo4j Graph Algorithm library comes with a set of built-in graph generators. The generator produces named graphs, that can be used as input for all algorithms in the library.

It is currently not possible to persist these graphs in Neo4j. Running an algorithm in write mode on a generated graph will lead to unexpected results.

The graph generation is parameterized by three dimensions:

9.8.1. Syntax

The following describes the API for running the algorithm. 

CALL algo.beta.graph.generate(name: String, nodeCount: Integer, averageDegree: Integer, {
  relationshipDistribution: String,
  relationshipProperty: Map
})
YIELD name, nodes, relationships, generateMillis, averageDegree, relationshipDistribution, relationshipProperty

Table 9.181. Parameters
Name Type Default Optional Description

name

string

null

no

The name under which the generated graph is stored.

nodeCount

integer

null

no

The number of generated nodes.

averageDistribution

integer

null

no

The average out-degree of generated nodes.

config

map

{}

yes

Additional configuration, see below.

Table 9.182. Configuration
Name Type Default Optional Description

relationshipDistribution

string

UNIFORM

yes

The probablity distribution method used to connect generated nodes. For more information see Section 9.8.2, “Relationship Distribution”.

relationshipSeed

long

null

yes

The seed used for generating relationships.

relationshipProperty

map

{}

yes

Describes the method used to generate a relationship property. By default no relationship property is generated. For more information see Section 9.8.4, “Relationship Property”.

Table 9.183. Results
Name Type Description

name

string

The name under wich the stored graph was stored.

nodes

int

The number of nodes in the graph.

relationships

int

The number of relationships in the graph.

generateMillis

int

Milliseconds for generating the graph.

averageDegree

double

The average out degree of the generated nodes.

relationshipDistribution

string

The probablity distribution method used to connect generated nodes.

relationshipSeed

long

null

yes

The seed used for generating relationships.

relationshipProperty

9.8.2. Relationship Distribution

The relationshipDistribution parameter controls the statistical method used for the generation of new relationships. Currently there are three supported methods:

  • UNIFORM - Distributes the outgoing relationships evenly, i.e., every node has exactly the same out degree (equal to the average degree). The target nodes are selected randomly.
  • RANDOM - Distributes the outgoing relationships using a normal distribution with an average of averageDegree and a standard deviation of 2 * averageDegree. The target nodes are selected randomly.
  • POWER_LAW - Distributes the incoming relationships using a power law distribution. The out degree is based on a normal distribution.

9.8.3. Relationship Seed

The relationshipSeed parameter allows, to generate graphs with the same relationships, if they have no property. Currently the relationshipProperty is not seeded, therefore the generated graphs can differ in their property values. Hence generated graphs based on the same relationshipSeed are not identical.

9.8.4. Relationship Property

The graph generator is capable of generating a relationship property. This can be controlled using the relationshipProperty parameter which accepts the following parameters:

Table 9.184. Configuration
Name Type Default Optional Description

name

string

null

no

The name under which the property values are stored.

type

string

null

no

The method used to generate property values.

min

double

0.0

yes

Minimal value of the generated property (only supported by RANDOM).

max

double

1.0

yes

Maximum value of the generated property (only supported by RANDOM).

value

double

null

yes

Fixed value assigned to every relationship (only supported by FIXED).

Currently, there are two supported methods to generate relationship properties:

  • FIXED - Assigns a fixed value to every relationship. The value parameter must be set.
  • RANDOM - Assigns a random value between the lower (min) and upper (max) bound.