use of org.neo4j.graphdb.traversal.Traverser in project graphdb by neo4j-attic.
the class TreeGraphTest method pathsIteratorReturnAllNodes.
@Test
public void pathsIteratorReturnAllNodes() throws Exception {
Traverser traverser = Traversal.description().traverse(referenceNode());
int count = 0;
for (Path path : traverser) {
assertNotNull("returned paths should not be null. path #" + count, path);
count++;
}
assertEquals(13, count);
}
use of org.neo4j.graphdb.traversal.Traverser in project graphdb by neo4j-attic.
the class ExactDepthPathFinder method paths.
private Iterator<Path> paths(final Node start, final Node end) {
TraversalDescription base = Traversal.description().uniqueness(Uniqueness.RELATIONSHIP_PATH).order(new BranchOrderingPolicy() {
public BranchSelector create(TraversalBranch startSource) {
return new LiteDepthFirstSelector(startSource, startThreshold);
}
});
final int firstHalf = onDepth / 2;
Traverser startTraverser = base.prune(Traversal.pruneAfterDepth(firstHalf)).expand(expander).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == firstHalf;
}
}).traverse(start);
final int secondHalf = onDepth - firstHalf;
Traverser endTraverser = base.prune(Traversal.pruneAfterDepth(secondHalf)).expand(expander.reversed()).filter(new Predicate<Path>() {
public boolean accept(Path item) {
return item.length() == secondHalf;
}
}).traverse(end);
final Iterator<Path> startIterator = startTraverser.iterator();
final Iterator<Path> endIterator = endTraverser.iterator();
final Map<Node, Visit> visits = new HashMap<Node, Visit>();
return new PrefetchingIterator<Path>() {
@Override
protected Path fetchNextOrNull() {
Path[] found = null;
while (found == null && (startIterator.hasNext() || endIterator.hasNext())) {
found = goOneStep(start, startIterator, visits);
if (found == null) {
found = goOneStep(end, endIterator, visits);
}
}
return found != null ? toPath(found, start) : null;
}
};
}
use of org.neo4j.graphdb.traversal.Traverser in project graphdb by neo4j-attic.
the class ExperimentalAStar method findAllPaths.
public Iterable<WeightedPath> findAllPaths(Node start, final Node end) {
Predicate<Path> filter = new Predicate<Path>() {
public boolean accept(Path position) {
return position.endNode().equals(end);
}
};
final Traverser traverser = traversalDescription.order(new SelectorFactory(end)).filter(filter).traverse(start);
return new Iterable<WeightedPath>() {
public Iterator<WeightedPath> iterator() {
return new StopAfterWeightIterator(traverser.iterator(), costEvaluator);
}
};
}
use of org.neo4j.graphdb.traversal.Traverser in project graphdb by neo4j-attic.
the class SmallestGraphEverTest method execute.
private void execute(TraversalDescription traversal, Uniqueness uniqueness) {
Traverser traverser = traversal.uniqueness(uniqueness).traverse(referenceNode());
assertFalse("empty traversal", IteratorUtil.count(traverser) == 0);
}
use of org.neo4j.graphdb.traversal.Traverser in project graphdb by neo4j-attic.
the class DepthPitfallGraphTest method testAllRelationshipsAreReturnedOnce.
private void testAllRelationshipsAreReturnedOnce(TraversalDescription description) throws Exception {
Traverser traverser = Traversal.description().uniqueness(Uniqueness.RELATIONSHIP_GLOBAL).traverse(referenceNode());
expectRelationships(traverser, THE_WORLD_AS_WE_KNOW_IT);
}
Aggregations