0
我正在使用Traversal API,但似乎Traversal.expanderForTypes()棄用,我不知道如何找到兩個節點之間的最短路徑。Neo4j 3.1遍歷API,如何找到兩個節點之間的最短路徑?
我的方法
public Iterable<Path> shortestPath(long firstNodeId, long secondNodeId) {
Node firstNode = null;
Node secondNode = null;
try (Transaction tx = mainServiceBean.getDatabaseService().beginTx()) {
firstNode = mainServiceBean.getDatabaseService().getNodeById(firstNodeId);
secondNode = mainServiceBean.getDatabaseService().getNodeById(secondNodeId);
PathExpander expander = Traversal.expanderForTypes();//?
PathFinder<Path> shortestPath = GraphAlgoFactory.shortestPath(expander, 4, 4);
tx.success();
return shortestPath.findAllPaths(firstNode, secondNode);
}
}
我的節點之間這樣
Node nodeACity = mainServiceBean.getDatabaseService().createNode(ProjectLabels.City);
nodeACity .setProperty(City.NAME, CityNames.ACiTY.name());
Node nodeBCity = mainServiceBean.getDatabaseService().createNode(ProjectLabels.City);
nodeBCity.setProperty(City.NAME, CityNames.BCity.name());
Relationship ab= nodeACity .createRelationshipTo(nodeBCity , NodesRelationship.DISTANCE_TO);
ab.setProperty("distance", 124.31);
Relationship ba= nodeBCity .createRelationshipTo(nodeACity , NodesRelationship.DISTANCE_TO);
ba.setProperty("distance", 124.31);
所以關係具有價值屬性距離城市和關係。
如何使用neo4j 3的遍歷API?似乎很多改變。
只是爲了澄清:你真的在談論Neo4j 3.1 - 這不是GA,里程碑8已經出來。或者你指的是Neo4j 3.0.x--這是GA。 –
是的,它大約是3.0.x –