ArangoDB uniqueVertices 全局不包括第一个和最后一个顶点
ArangoDB uniqueVertices global excluding the first and last vertices
我正在尝试找到从一个朋友到另一个朋友的所有唯一路径。
当我使用 uniqueVertices: 'global' 时,它只返回一条路径,因为结束顶点被认为是全局唯一的一部分。
FOR v,e,p
IN 1..6
ANY "entities/foo"
GRAPH "friendGraph"
OPTIONS {
bfs: true,
uniqueVertices: 'path'
}
SORT e.weight ASC
FILTER v._id == "entities/bar"
RETURN p
有没有办法让 uniqueVertices: 'global' 忽略结束顶点?我知道没有办法专门做到这一点。但是有没有办法完成同样的事情呢?
'path' 导致了很多结果。
谢谢。
为了使用全局唯一的顶点,但对于最后一个顶点,您可以像这样在路径中手动添加最后一步:
FOR v,e,p
IN 0..5
ANY "entities/foo"
GRAPH "friendGraph"
OPTIONS {
bfs: true,
uniqueVertices: 'global'
}
FILTER p.vertices[*]._id ALL != "entities/bar"
FOR w,f
IN 1..1
ANY v
GRAPH "friendGraph"
FILTER w._id == "entities/bar"
SORT f.weight ASC
RETURN { edges: APPEND(p.edges, [f]), vertices: APPEND(p.vertices, [w]) }
我想说明两点:
- 您添加的
SORT
操作可能无法实现您想要的:它根据路径最后一条边的权重对路径进行排序
- 这不会在两个顶点之间找到 all 个唯一路径。为此,使用选项
uniqueVertices: 'path'
是正确的,而且可能会有很多。
我正在尝试找到从一个朋友到另一个朋友的所有唯一路径。
当我使用 uniqueVertices: 'global' 时,它只返回一条路径,因为结束顶点被认为是全局唯一的一部分。
FOR v,e,p
IN 1..6
ANY "entities/foo"
GRAPH "friendGraph"
OPTIONS {
bfs: true,
uniqueVertices: 'path'
}
SORT e.weight ASC
FILTER v._id == "entities/bar"
RETURN p
有没有办法让 uniqueVertices: 'global' 忽略结束顶点?我知道没有办法专门做到这一点。但是有没有办法完成同样的事情呢?
'path' 导致了很多结果。
谢谢。
为了使用全局唯一的顶点,但对于最后一个顶点,您可以像这样在路径中手动添加最后一步:
FOR v,e,p
IN 0..5
ANY "entities/foo"
GRAPH "friendGraph"
OPTIONS {
bfs: true,
uniqueVertices: 'global'
}
FILTER p.vertices[*]._id ALL != "entities/bar"
FOR w,f
IN 1..1
ANY v
GRAPH "friendGraph"
FILTER w._id == "entities/bar"
SORT f.weight ASC
RETURN { edges: APPEND(p.edges, [f]), vertices: APPEND(p.vertices, [w]) }
我想说明两点:
- 您添加的
SORT
操作可能无法实现您想要的:它根据路径最后一条边的权重对路径进行排序 - 这不会在两个顶点之间找到 all 个唯一路径。为此,使用选项
uniqueVertices: 'path'
是正确的,而且可能会有很多。