Databases Reference
In-Depth Information
a similar strategy to the Cypher query we've already looked at: it works its way up the
graph from both the start node and the end node in two separate traversals, until it finds
a delivery base for each leg. It then performs a shortest weighted path search that joins
these two delivery bases.
Here's the beginning of the ParcelRouteCalculator class:
public class ParcelRouteCalculator
{
private static final PathExpander < Interval > DELIVERY_ROUTE_EXPANDER =
new IntervalPathExpander ( withName ( "DELIVERY_ROUTE" ),
Direction . INCOMING );
private static final PathExpander < Interval > CONNECTED_TO_EXPANDER =
new IntervalPathExpander ( withName ( "CONNECTED_TO" ),
Direction . BOTH );
private static final TraversalDescription DELIVERY_BASE_FINDER =
Traversal . description ()
. depthFirst ()
. evaluator ( new Evaluator ()
{
private final RelationshipType DELIVERY_ROUTE =
withName ( "DELIVERY_ROUTE" );
@Override
public Evaluation evaluate ( Path path )
{
if ( isDeliveryBase ( path ) )
{
return Evaluation . INCLUDE_AND_PRUNE ;
}
return Evaluation . EXCLUDE_AND_CONTINUE ;
}
private boolean isDeliveryBase ( Path path )
{
return ! path . endNode (). hasRelationship (
DELIVERY_ROUTE , Direction . INCOMING );
}
} );
private static final CostEvaluator < Double > COST_EVALUATOR =
CommonEvaluators . doubleCostEvaluator ( "cost" );
private final Index < Node > locationIndex ;
public ParcelRouteCalculator ( GraphDatabaseService db )
{
this . locationIndex = db . index (). forNodes ( "location" );
}
Search WWH ::




Custom Search