概述
诱导子图(Induced Subgraph)算法可以根据一组给定的节点计算出相应的诱导子图,它提供了一种深入了解所选节点子集中的局部结构和交互的方法。
基本概念
诱导子图
诱导子图仅包括给定集合中的节点以及连接这些节点的边。
如上例所示,指定节点集S={A, B, I, K, L, M, N}的诱导子图包括节点集S以及两端点均在节点集S中的所有边构成的边集。
嬴图的诱导子图算法返回的是诱导子图中的所有一步路径。
特殊说明
- 诱导子图算法忽略边的方向,按照无向边进行计算。
示例图集
创建示例图集:
// 在空图集中逐行运行以下语句
create().edge_property(@default, "score", int32)
insert().into(@default).nodes([{_id:"A"}, {_id:"B"}, {_id:"C"}, {_id:"D"}, {_id:"E"}, {_id:"F"}, {_id:"G"}, {_id:"H"}, {_id:"I"}])
insert().into(@default).edges([{_from:"A", _to:"B", score:2}, {_from:"C", _to:"A", score:3}, {_from:"E", _to:"C", score:2}, {_from:"E", _to:"A", score:4}, {_from:"C", _to:"D", score:2}, {_from:"D", _to:"A", score:2}, {_from:"D", _to:"A", score:3}, {_from:"F", _to:"G", score:3}, {_from:"G", _to:"G", score:5}, {_from:"F", _to:"I", score:2}, {_from:"H", _to:"G", score:1}])
创建HDC图集
将当前图集全部加载到HDC服务器hdc-server-1
上,并命名为 hdc_subgraph
:
CALL hdc.graph.create("hdc-server-1", "hdc_subgraph", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static",
query: "query",
default: false
})
hdc.graph.create("hdc_subgraph", {
nodes: {"*": ["*"]},
edges: {"*": ["*"]},
direction: "undirected",
load_id: true,
update: "static",
query: "query",
default: false
}).to("hdc-server-1")
参数
算法名:subgraph
参数名 |
类型 |
规范 |
默认值 |
可选 |
描述 |
---|---|---|---|---|---|
ids |
[]_id |
/ | / | 否 | 通过_id 指定参与计算的点;若未设置则计算所有点 |
uuids |
[]_uuid |
/ | / | 否 | 通过_uuid 指定参与计算的点;若未设置则计算所有点 |
return_id_uuid |
String | uuid , id , both |
uuid |
是 | 在结果中使用_uuid 、_id 或同时使用两者来表示点。只能使用_uuid 来表示边 |
limit |
Integer | ≥-1 | -1 |
是 | 限制返回的结果数;-1 返回所有结果 |
文件回写
CALL algo.subgraph.write("hdc_subgraph", {
params: {
return_id_uuid: "id",
ids: ['A','C','D','G']
},
return_params: {
file: {
filename: "paths"
}
}
})
algo(subgraph).params({
project: "hdc_subgraph",
return_id_uuid: "id",
ids: ['A','C','D','G']
}).write({
file: {
filename: "paths"
}
})
结果:
_id
C--[102]--A
D--[107]--A
D--[106]--A
C--[105]--D
G--[109]--G
完整返回
CALL algo.subgraph("hdc_subgraph", {
params: {
return_id_uuid: "id",
ids: ['A','C','D','G']
},
return_params: {}
}) YIELD r
RETURN r
exec{
algo(subgraph).params({
return_id_uuid: "id",
ids: ['A','C','D','G']
}) as r
return r
} on hdc_subgraph
结果:
流式返回
CALL algo.subgraph("hdc_subgraph", {
params: {
return_id_uuid: "id",
ids: ['F','G']
},
return_params: {
stream: {}
}
}) YIELD p
FOR e1 IN pedges(p)
MATCH ()-[e2 WHERE e2._uuid = e1._uuid]->()
RETURN max(e2.score)
exec{
algo(subgraph).params({
return_id_uuid: "id",
ids: ['F','G']
}).stream() as p
uncollect pedges(p) as e1
find().edges({_uuid == e1._uuid}) as e2
return max(e2.score)
} on hdc_subgraph
结果:5