Graph Generator - Set relationship property in a range in Neo4j

I follow this Link to use a graph generator to create a graph scaling to +10000 nodes and to execute the shortest path algorithm between two nodes.

How can I set the relationship property for all the nodes to be in a specific range?

This Link provides more options, but I don't know how to use it. Any help?

Hi @samasamaan

You can use "apoc.generate.er".

CALL apoc.generate.er(10,5,'TestLabel', 'TEST_REL_TYPE');

This command will create this graph.

10 Nodes
5 Relationships
'TestLabel' (Label)
'TEST_REL_TYPE' (Relationship)

Is it the answer you're looking for?

Hello
Ok but I want to set relationship property for all the edges in a specific range (min,max). This APOC doesn't provide such parameter.

Hi @samasamaan

There doesn't seem to be a specific range (min,max) for apoc.generate.
Sorry.
But, You can copy and create a new command from APOC :)

1 Like

Hello @koji
Thanks for you help. I return back to use the queries in this link: https://neo4j.com/labs/apoc/4.1/graph-updates/graph-generators/
You said: But, You can copy and create a new command from APOC. How can I do this? please I want to create & set a relationship property to all the edges in a specific range.

Hi @samasamaan

You can clone APOC and add/modify the function.

Build & install the current development branch from source

git clone http://github.com/neo4j-contrib/neo4j-apoc-procedures cd neo4j-apoc-procedures
./gradlew shadow
cp build/libs/apoc-<version>-all.jar $NEO4J_HOME/plugins/
$NEO4J_HOME/bin/neo4j restart
1 Like

Thanks but I didn't understand how to update an APOC.
Any help will be appreciated.

This how I solve the problem:
CALL apoc.generate.ba(100, 4, 'Node', 'connect')

merge (n)-[c:connect]->(m)
    set c.cost=toInteger(rand() * 10)

CALL gds.graph.create('myGraph', 'Node', 'connect', {relationshipProperties: 'cost'})

CALL gds.shortestPath.dijkstra.stream('myGraph', {
CALL gds.shortestPath.dijkstra.stream('myGraph', {
    sourceNode: 26,
    targetNode: 31,
    relationshipWeightProperty: 'cost'
})
YIELD index, sourceNode, targetNode, totalCost, nodeIds, costs, path
RETURN
    index,
    gds.util.asNode(sourceNode).name AS sourceNodeName,
    gds.util.asNode(targetNode).name AS targetNodeName,
    totalCost,
    [nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames,
    costs,
    nodes(path) as path
ORDER BY index

Suggestions please.