简体   繁体   English

在gremlin中创建多个节点图

[英]Creation of graph of multiple nodes in gremlin

I am creating Tinkergraph in gremlin. 我正在用小怪兽创建Tinkergraph。

Actually, I want to create graph of 50 nodes and they are connected via edges randomly. 实际上,我想创建50个节点的图,它们通过边随机连接。

I have created 50 nodes by: 我通过以下方式创建了50个节点:

(0..<50).each{graph.addVertex().property("NodeId",it)}

that creates 50 nodes. 创建50个节点。

I can't create graph properly, connecting the nodes via edges. 我无法正确创建图形,无法通过边连接节点。 No one node should be left. 不应保留任何节点。

I tried this also: 我也尝试过这个:

v = g.V().has("NodeId",0).next(); (0..<50).each{v.addEdge("childs",g.V().has("NodeId",it).next())}

It creates graph where all nodes are connected to the only one node. 它创建图,其中所有节点都连接到唯一一个节点。

Any ideas how to fix it? 任何想法如何解决?

Create Tinkergraph of 50 nodes and connected via edges. 创建50个节点的Tinkergraph,并通过边连接。

Your question is not very clear to me. 您的问题对我来说不是很清楚。 Are you asking how to connect every vertex with each other? 您是否在问如何将每个顶点相互连接? If so, here you go: 如果是这样,请前往:

gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV().emit().repeat(property("NodeId", loops()).addV()).times(49).as("x").
......1>   sideEffect(hasNot("NodeId").property("NodeId", 49)).barrier().
......2>   V().where(neq("x")).addE("childs").from("x").iterate()

At this point you'll have a graph with 50 vertices, each one connected with a child edge to each other vertex in the graph. 此时,您将拥有一个包含50个顶点的图形,每个顶点都与一个child边连接到该图形中的每个顶点。

gremlin> g
==>graphtraversalsource[tinkergraph[vertices:50 edges:2450], standard]

Let's pick a random vertex to verify that it's in fact connected to all all vertices in the graph except to itself. 让我们选择一个随机顶点,以验证它是否实际上已连接到图中除自身之外的所有所有顶点。

gremlin> g.V().has("NodeId", 30).out("childs").values("NodeId").fold().order(local)
==>[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM