【发布时间】:2014-02-26 20:45:00
【问题描述】:
有什么方法可以根据属性从 Neo4j Dijkstra 算法中排除某些特定节点?
我知道,我可以在方法 forTypeAndDirection 中设置允许的关系和方向,但这对我的情况没有帮助。
假设我有以下代码:
try (Transaction tx = graphDb.beginTx()) {
Node startNode = graphDb.getNodeById(12353);
Node endNode = graphDb.getNodeById(12356);
CostEvaluator<Double> costEvaluator = new CostEvaluator<Double>() {
@Override
public Double getCost(Relationship relationship, Direction direction) {
Integer cost = Integer.parseInt(relationship.getProperty("cost").toString());
return cost.doubleValue();
}
};
PathFinder<WeightedPath> finder = GraphAlgoFactory.dijkstra(
PathExpanders.forTypeAndDirection( RelationshipTypes.RELATED, Direction.OUTGOING), costEvaluator );
WeightedPath path = finder.findSinglePath( startNode, endNode );
System.out.println(path.length());
tx.success();
}
}
当 Dijkstra 通过属性名称为:'London' 的节点时,如何停止执行此路径并在其他地方继续执行?
【问题讨论】: