在neo4j中求k-最短路径

在neo4j中求k-最短路径,neo4j,shortest-path,Neo4j,Shortest Path,我正在使用GraphAlgoFactory.shortestPath(PathExpander、int-maxDepth、int-maxHitCount)来查找k-最短路径,但问题是,我没有得到两个节点之间的直接路径。比如说,我有一段像这样的关系 n1--n2 n1--n3 n3--n2 如果我试图找到n1和n2之间的路径,我得到的只有一条路径是n1--n3--n2,但实际上,有两条路径,其中一条是从n1到n2的直接路径 CustomPathExpander expander = toExpa

我正在使用GraphAlgoFactory.shortestPath(PathExpander、int-maxDepth、int-maxHitCount)来查找k-最短路径,但问题是,我没有得到两个节点之间的直接路径。比如说,我有一段像这样的关系

n1--n2
n1--n3
n3--n2
如果我试图找到n1和n2之间的路径,我得到的只有一条路径是n1--n3--n2,但实际上,有两条路径,其中一条是从n1到n2的直接路径

CustomPathExpander expander = toExpander(constraints, db, Collections.<FakeNode>emptyList());

List<Path> result = new LinkedList<Path>();
for (Path path : GraphAlgoFactory.shortestPath(expander, 3, 3).findAllPaths(n1, n2)) 
{
result.add(path);
}


static CustomPathExpander toExpander(String constraints, FakeGraphDatabase db, Iterable<FakeNode> extraNodes) {
    return toExpander(toMap(constraints), db, extraNodes);
}


static CustomPathExpander toExpander(Map<String,Object> c, FakeGraphDatabase db, Iterable<FakeNode> extraNodes) {
    Map<String,String> directions = (Map<String, String>) (c == null ? null : c.get("dir"));
    Map<String,Object> constraints = (Map<String, Object>) (c == null ? null : c.get("c"));
    Map<String,Object> inline = (Map<String,Object>)(c == null ? null : c.get("inline"));

    DirectionContraints d = new DirectionContraints(directions);
    IPathConstraint path = PathConstraints.parse(constraints);
    InlineRelationships rel = InlineRelationships.of(inline, db);

    return new CustomPathExpander(d, path, rel, extraNodes, c != null && c.get("acyclic") == Boolean.TRUE);
}
CustomPathExpander=toExpander(约束、db、Collections.emptyList());
列表结果=新建LinkedList();
for(路径:GraphAlgoFactory.最短路径(扩展器,3,3).FindAllPath(n1,n2))
{
结果.添加(路径);
}
静态CustomPathExpander-toExpander(字符串约束、FakeGraphDatabase db、Iterable外部节点){
返回到Expander(toMap(约束)、db、extraNodes);
}
静态CustomPathExpander-toExpander(映射c、FakeGraphDatabase db、Iterable extraNodes){
映射方向=(Map)(c==null?null:c.get(“dir”);
映射约束=(映射)(c==null?null:c.get(“c”);
Map inline=(Map)(c==null?null:c.get(“inline”);
方向约束d=新方向约束(方向);
IPathConstraint路径=路径约束.parse(约束);
InlineRelationships rel=的InlineRelationships.of(inline,db);
返回新的CustomPathExpander(d,path,rel,extraNodes,c!=null&&c.get(“非循环”)==Boolean.TRUE);
}

您能否粘贴使用的java代码,以便我们更好地帮助您添加代码片段