当前位置: 动力学知识库 > 问答 > 编程问答 >

Dijkstra's algorithm with Direction in Neo4j

问题描述:

I have added all of my nodes and relationships. But an issue is that when using Dijikstra, I don't get it in a single direction:

(0)--[PROGRESSED_TO,3812]-->(1)<--[PROGRESSED_TO,3965]--(26)--[PROGRESSED_TO,4932]-->(63) weight:0.07873392808600001

As we see we have A -> B <- C -> D

Why is my path not just going forward?

My algo is created by:

PathFinder dijkstra = dijkstra(Traversal.expanderForAllTypes(), CommonEvaluators.doubleCostEvaluator("length"));

Whereby I iterate through paths:

Iterator<WeightedPath> paths = dijkstra.findAllPaths(node_a, node_b ).iterator();

网友答案:

You have to tell the expander to only go in one particular direction:

Traversal.expanderForAllTypes(Direction.OUTGOING);

As an aside, if you are using Neo4j 2.0 or greater, you should aim at using traversal components in org.neo4j.graphdb.traversal, rather than the ones from org.neo4j.kernel. The kernel ones are internal code and may change. Something like this:

PathExpanders.forDirection(Direction.OUTGOING);
分享给朋友:
您可能感兴趣的文章:
随机阅读: