-1

While running some tests, I was looking for a way that can generate random nodes and edges with random values. I know in postgresql there are some helper functions like random() and generate_series() that can be used to fill in the table easily but what I'm looking for is a way I can create random nodes and edges between them.

ahmed_131313
  • 142
  • 6

7 Answers7

1

You can use the function create_complete_graph to generate the graph, it should look like this:

SELECT * FROM create_complete_graph('graph_name', 5, 'edge_label', 'vertice');

In this example, 5 represents the number of nodes you want in the graph.

Wendel
  • 763
  • 1
  • 12
0

You can also use Python for this to generate random nodes and edges with random values. For this reason You can use utilise using Network X python library.

Official Documentation here

farrukh raja
  • 187
  • 4
0

In Graph Databases, a node is like a memory location which stores data and edges are like memory pointers that connects those nodes, so creating random nodes and edges is not quite logical or intuitive. If you want to create a complete graph i.e a graph with 'n' number of nodes and every node connected with every other node, you can take the help of "create_complete_graph" like as shown in a previous answer.

    SELECT * FROM create_complete_graph('name',n,'edge_label','vertex_label');


    
  • Creating randomly generated graphs with synthetic data is done all the time for testing. It is seldom the case that a complete graph is wanted as real world graphs tend to have communities and outliers. – Kelvin Lawrence May 09 '23 at 11:46
0

You can use neo4j sandbox to generate sample data, and then import it as a csv in Apache AGE.

Check neo4j sandbox here: - https://sandbox.neo4j.com/

Check how to import csv file here: -

https://age.apache.org/age-manual/master/intro/agload.html

0

create_complete_graph function can be used to create a random graph with random nodes and edges.

Prachi
  • 39
  • 3
0

Here's how to create the random nodes:

  1. Firstly create the table for nodes.
CREATE TABLE nodes (
    id SERIAL PRIMARY KEY,
    property1 VARCHAR,
    property2 INTEGER,
    -- add more properties as needed
);
  1. Now try inserting nodes with the help of random() function.
INSERT INTO nodes (property1, property2)
SELECT
    md5(random()::text),
    floor(random() * 100)
FROM generate_series(1, 10); -- generates 10 random nodes
0

For this, you can write a Python script that first creates a random number of nodes and then adds edges between random nodes.

Alternatively, a better solution is to use NetworkX Graph Generators to generate any type of graph with the desired number of nodes, traverse through all the nodes and edges, and insert them in apache age.

abhishek2046
  • 312
  • 1
  • 11