-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypher_generateGraph.txt
25 lines (17 loc) · 990 Bytes
/
cypher_generateGraph.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# I am learning to use Cypher from the Neo4j documentation and from blog posts by Michael Hunger's 'Better Software
# Development' blog (http://jexp.de/blog/about/), especially for insights about making random graphs in Cypher.
#
# In the iGraph model, I created 50,000 nodes with a 5% chance of nodes having opinion B over opinion A. In the Cypher
# version, it's necessary to be more explicit.
FOREACH (r IN range(1, 950) | CREATE (:Agents {id:r, hasOpinion:'A', name:"N"+r}));
# Takes ~1500ms
FOREACH (r IN range(951, 1000) | CREATE (:Agents {id:r, hasOpinion:'B', name:"N"+r}));
# Takes ~100ms
# Generating random edges is much more tricky. Using Hunger's cross-product matching algorithm as a basis and combining
# it with his advice on random sampling, I came up with this version, which creates a random graph but not very quickly.
MATCH (a:Agents),(b:Agents)
WITH a, b, rand() AS c
ORDER BY c
WHERE rand() < .03
CREATE (a)-[:SpeaksTo]->(b);
# ~3000ms for ~30k relationships