Hi all . . .
The problem:
It's a multiiple origin one destination problem. The origin node is "7" and the origin nodes are: 9,1 and 10.
It has to return de numer of nodes into the diferent path between all the nodes (label:inicio) (Source) and the destination node.
The example:
The traverse that show all nodes: (but it's too slow)
TraversalDescription td = db.traversalDescription()
.depthFirst()
.expand(PathExpanders.forTypeAndDirection(RelTypes.SIGUIENTE, Direction.INCOMING))
.uniqueness( Uniqueness.NODE_PATH)
.evaluator(new Evaluator() {
@Override
public Evaluation evaluate(Path path
if( path.endNode().hasLabel(Labels.Inicio)) {
return Evaluation.INCLUDE_AND_CONTINUE;
}
return Evaluation.EXCLUDE_AND_CONTINUE;
}
});
HashSet<Node> pathNodes = new HashSet<>();
for ( Path path: td.traverse(inicio)) {
for (Node node : path.nodes()) {
pathNodes.add(node);
}
}
return pathNodes.stream().map( item -> new NodeResult(item));
With this other configuration, the traverse shows all the nodes correctly but it is much slower and takes half an hour. The solution 1 takes less than a second.
The question:
How can I solve the problem so that it shows all the nodes that intervene in the process and take a little time?
What kind of configuration do I have to use?
Is it possible to use Traverse to solve the problem? or do I need other functionality?
need I a bi-directional traversal ?
The solution 1 : (paths returned by Traverser) with this config:
TraversalDescription td = db.traversalDescription()
.breadthFirst()
.expand(PathExpanders.forTypeAndDirection(RelTypes.SIGUIENTE, Direction.INCOMING))
.uniqueness(Uniqueness.RELATIONSHIP_PATH)
.evaluator(new Evaluator() {
@Override
public Evaluation evaluate(Path path) {
System.out.println(" - - - - - - - "+ "\n");
System.out.println(" - - dentro eval - - "+ "\n"+Paths.pathToString( path, pathPrinter ));
if( path.endNode().hasLabel(Labels.Inicio)) {
System.out.println("..........INCLUDE_AND_PRUNE");
return Evaluation.INCLUDE_AND_PRUNE;
// return Evaluation.ofContinues(false);
}else {
System.out.println("EXCLUDE_AND_CONTINUE...........");
return Evaluation.EXCLUDE_AND_CONTINUE;
}
}
});
String output=" ";
HashSet<Long> pathNodes = new HashSet<>();
for ( Path path: td.traverse(inicio)) {
for (Node node : path.nodes()) {
pathNodes.add(node.getId());
}
output += "\n"+Paths.pathToString( path, pathPrinter );
System.out.println("______Path dentro del Bucle FOR_________ ");
System.out.println(" rutas: "+ output);
}
return pathNodes.stream().map(item -> new HashSetResult(item));
}
(id7)<--[SIGUIENTE]--(id6)<--[SIGUIENTE]--(id5)<--[SIGUIENTE]--(id10)
(id7)<--[SIGUIENTE]--(id6)<--[SIGUIENTE]--(id5)<--[SIGUIENTE]--(id2)<--[SIGUIENTE]--(id1)
(id7)<--[SIGUIENTE]--(id4)<--[SIGUIENTE]--(id12)<--[SIGUIENTE]--(id11)<--[SIGUIENTE]--(id3)<--[SIGUIENTE]--(id9)
But the Traverser continue with the Evaluation . . .
-
- dentro eval - -
(id7)<--[SIGUIENTE]--(id4)<--[SIGUIENTE]--(id12)<--[SIGUIENTE]--(id11)<--[SIGUIENTE]--(id3)<--[SIGUIENTE]--(id2)
EXCLUDE_AND_CONTINUE...........
-
- dentro eval - -
(id7)<--[SIGUIENTE]--(id4)<--[SIGUIENTE]--(id3)
EXCLUDE_AND_CONTINUE...........
-
- dentro eval - -
(id7)<--[SIGUIENTE]--(id4)
EXCLUDE_AND_CONTINUE...........
And in the following case, it does not include the two elements marked in red
Thanks in advance !