And*_*rey 1 graph shortest-path cassandra gremlin janusgraph
我正在将JanusGraph与Gremlin一起使用,并且此数据集包含2.6k节点和6.6k边(两侧为3.3k边)。我已经运行查询10分钟,没有找到最短的路径。
使用Gephi,最短路径几乎是瞬时的。
这是我的查询:
g.V(687).repeat(out().simplePath()).until(hasId(1343)).path().limit(1)
Run Code Online (Sandbox Code Playgroud)
使用simplePath()您的查询仍会处理比所需更多的路径。例如,如果688是的直接邻居687,但又是的邻居1000,则在另一条路径上相距10跳,那么为什么您要沿着从1000到的路径行驶688,如果您早已看到了这个十字路口?
因此,您应该过滤掉之前见过的任何十字路口(第一次出现的总是最接近的):
g.V(687).store('x').
repeat(out().where(without('x')).aggregate('x')).
until(hasId(1343)).limit(1).path()
Run Code Online (Sandbox Code Playgroud)
另请注意,我交换了limit(1)和path; 这是因为先收集所有路径然后仅采用第一个路径会浪费资源(CPU和内存)。
更新:
如果其他人想尝试一下,下面是将数据集加载到TinkerGraph中的代码:
g = TinkerGraph.open().traversal()
"http://nrvis.com/download/data/road/road-minnesota.zip".toURL().withInputStream {
new java.util.zip.ZipInputStream(it).with {
while (entry = it.getNextEntry()) {
if ("road-minnesota.mtx" == entry.getName()) {
it.eachLine {
if (it ==~ /[0-9]+ [0-9]+/) {
def (a, b) = it.split()*.toInteger()
g.V(a).fold().
coalesce(unfold(), addV().property(id, a)).
addE("road").
to(V(b).fold().coalesce(unfold(), addV().property(id, b))).inV().
addE("road").to(V(a)).iterate()
}
}
break
}
it.closeEntry()
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及查询和一些基准测试:
gremlin> g.V(687).store('x').
......1> repeat(out().where(without('x')).aggregate('x')).
......2> until(hasId(1343)).limit(1).
......3> path().by(id)
==>[687,689,686,677,676,675,673,626,610,606,607,608,735,732,733,730,729,734,737,738,739,742,786,816,840,829,815,825,865,895,872,874,968,983,1009,1044,1140,1142,1148,1219,1255,1329,1337,1339,1348,1343]
gremlin> clock (100) {
......1> g.V(687).store('x').
......2> repeat(out().where(without('x')).aggregate('x')).
......3> until(hasId(1343)).limit(1).
......4> path().iterate()
......5> }
==>12.5362714
Run Code Online (Sandbox Code Playgroud)
TinkerGraph上的12.5毫秒对我来说看起来不错。期望它在JG上运行更长的时间,但是肯定不会超过10分钟。