【发布时间】:2015-08-12 05:10:12
【问题描述】:
我正在使用这个自定义扩展器来嵌入使用最短路径算法的Neo4j。然而,最短路径算法不允许我在它构建的路径中查找最后一个关系,因为他们没有实现它。我得到一个不受支持的异常。
我只需要检查最后一个关系的属性以继续扩展。有没有办法做到这一点?
public class CustomExpander implements PathExpander {
private Integer conditionFromTime;
private Integer conditionToTime;
private Integer conditionDayInd;
private Node startNode;
private Node endNode;
public CustomExpander( Integer fromTime, Integer toTime, Integer dayInd, Node startNode ) {
this.conditionFromTime = fromTime;
this.conditionToTime = toTime;
this.conditionDayInd = dayInd;
this.startNode = startNode;
this.endNode = endNode;
}
public CustomExpander( Integer fromTime, Integer toTime, Integer dayInd, Node startNode,Node endNode ) {
this.conditionFromTime = fromTime;
this.conditionToTime = toTime;
this.conditionDayInd = dayInd;
this.startNode = startNode;
this.endNode = endNode;
}
public Iterable expand(Path path, BranchState bs) {
Iterable<Relationship> something = path.endNode().getRelationships(TripGraphRelTypes.VISITS,Direction.BOTH);
return new FilteringIterable<Relationship>( something
, new Predicate<Relationship>() {
public boolean accept(Relationship t) {
//boolean result = tripRange.contains((Integer)t.getProperty(TripGraphProperties.VisitedByRel.departureToDsec.name()));
if ( (Integer)t.getProperty("departureToDsec") <= conditionFromTime ) {
return false;
}
if ((Integer)t.getProperty("arrivalToDsec") >= conditionToTime) {
return false;
}
if ( path.length() > 0 && (Integer) path.lastRelationship().getProperty("arrivalToDsec") < (Integer)t.getProperty("departureToDsec")){
return false; }
return true;
}
});
}
@Override
public PathExpander reverse() {
//System.out.println("reverse");
return this;
}
}
PathFinder<Path> finderGood = GraphAlgoFactory.shortestPath(expander, 10);
validPaths = filterValid2(finderGood.findAllPaths(n1, n2));
java.lang.UnsupportedOperationException
at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionDataPath.lastRelationship(ShortestPath.java:394)
at au.com.company.tripresolver.CustomExpander$1.accept(CustomExpander.java:104)
at org.neo4j.helpers.collection.FilteringIterator.fetchNextOrNull(FilteringIterator.java:49)
at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
at org.neo4j.helpers.collection.NestingIterator.fetchNextOrNull(NestingIterator.java:69)
at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextRelOrNull(ShortestPath.java:351)
at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextOrNull(ShortestPath.java:296)
at org.neo4j.graphalgo.impl.path.ShortestPath$DirectionData.fetchNextOrNull(ShortestPath.java:234)
at org.neo4j.helpers.collection.PrefetchingIterator.peek(PrefetchingIterator.java:60)
at org.neo4j.helpers.collection.PrefetchingIterator.hasNext(PrefetchingIterator.java:46)
at org.neo4j.graphalgo.impl.path.ShortestPath.internalPaths(ShortestPath.java:138)
at org.neo4j.graphalgo.impl.path.ShortestPath.findAllPaths(ShortestPath.java:110)
【问题讨论】:
-
请添加完整的堆栈跟踪