操作环境:
tool:ArangoDB 3.3.13
操作系统:Debian 7.2.0-20
概念:
Connected Components即连通体算法。用id标注图中每个连通体,将连通体中序号最小的顶点的id作为连通体的id。
如果在图G中,任意2个顶点之间都存在路径,那么称G为连通图,否则称该图为非连通图,则其中的极大连通子图称为连通体,如下图所示,该图中有两个连通体:
实例:
创建集合
//testv
LET data = [{"_key":"6014c5cac3424d8386dac12c46017c03","host_name":"Salih Tektase"},
{"_key":"6014c5ccca5b4cae893257bf86f0ead0","host_name":"Aditya Bramhan"},
{"_key":"6014c5c80177417fbfd0faf9d5fb31a4","host_name":"Ica palya"},
{"_key":"6014c5c891e54e4a8903cd306d55eb26","host_name":"null"},
{"_key":"6014c5c8f29d426686d6c30152a01459","host_name":"Boanny Patel"},
{"_key":"6014c5ccd2484a4581137ab8aa245ba7","host_name":"El Chapo"},
{"_key":"6014c5c8f1cb47ff886dd1991d19e59d","host_name":"Andrej Altuchov"},
{"_key":"6014c5dd17b54eda83e02e8dd913dba0","host_name":"Maria"},
{"_key":"6014c5e78bfd4051a421bd6adf017e56","host_name":"null"},
{"_key":"6014c5f1c88e40a6a1aa88da08d7c404","host_name":"Aaron Villaflor"}]
for d in data
insert d into testv
//teste
LET data = [{"_key":"2716265062","_from":"testv/6014c5ccca5b4cae893257bf86f0ead0","_to":"testv/6014c5cac3424d8386dac12c46017c03"},
{"_key":"2716265063","_from":"testv/6014c5c80177417fbfd0faf9d5fb31a4","_to":"testv/6014c5cac3424d8386dac12c46017c03"},
{"_key":"2716265064","_from":"testv/6014c5ccd2484a4581137ab8aa245ba7","_to":"testv/6014c5c8f29d426686d6c30152a01459"},
{"_key":"2716265065","_from":"testv/6014c5e78bfd4051a421bd6adf017e56","_to":"testv/6014c5dd17b54eda83e02e8dd913dba0"},
{"_key":"2716265066","_from":"testv/6014c5f1c88e40a6a1aa88da08d7c404","_to":"testv/6014c5dd17b54eda83e02e8dd913dba0"},
{"_key":"2716265067","_from":"testv/6014c5c8f29d426686d6c30152a01459","_to":"testv/6014c5c891e54e4a8903cd306d55eb26"},
{"_key":"2716265068","_from":"testv/6014c5c891e54e4a8903cd306d55eb26","_to":"testv/6014c5ccd2484a4581137ab8aa245ba7"},
{"_key":"2716265069","_from":"testv/6014c5c8f1cb47ff886dd1991d19e59d","_to":"testv/6014c5e78bfd4051a421bd6adf017e56"}]
for d in data
insert d into teste
//teste2
LET data = [{"_key":"3016636","_from":"testv/6014c5cac3424d8386dac12c46017c03","_to":"testv/6014c5ccca5b4cae893257bf86f0ead0"},
{"_key":"3016637","_from":"testv/6014c5cac3424d8386dac12c46017c03","_to":"testv/6014c5c80177417fbfd0faf9d5fb31a4"},
{"_key":"3016639","_from":"testv/6014c5dd17b54eda83e02e8dd913dba0","_to":"testv/6014c5e78bfd4051a421bd6adf017e56"},
{"_key":"3016641","_from":"testv/6014c5c891e54e4a8903cd306d55eb26","_to":"testv/6014c5c8f29d426686d6c30152a01459"},
{"_key":"3016638","_from":"testv/6014c5c8f29d426686d6c30152a01459","_to":"testv/6014c5ccd2484a4581137ab8aa245ba7"},
{"_key":"3016640","_from":"testv/6014c5dd17b54eda83e02e8dd913dba0","_to":"testv/6014c5f1c88e40a6a1aa88da08d7c404"},
{"_key":"3016642","_from":"testv/6014c5ccd2484a4581137ab8aa245ba7","_to":"testv/6014c5c891e54e4a8903cd306d55eb26"},
{"_key":"3016643","_from":"testv/6014c5e78bfd4051a421bd6adf017e56","_to":"testv/6014c5c8f1cb47ff886dd1991d19e59d"}]
for d in data
insert d into teste2
创建图
运行算法
var pregel = require("@arangodb/pregel")
var handle = pregel.start("connectedcomponents", "cc", {maxGSS: 250, resultField: "component"})
查看进程:
var status = pregel.status(handle);
结果