Databases Reference
In-Depth Information
and therefore have no incoming DELIVERY_ROUTE relationships, we can be confident
that the db1 node at the end of this variable-length path represents a delivery base
and not some other parcel network element.
WHERE applies additional constraints to the path upLeg , ensuring that we only match
DELIVERY_ROUTE relationships whose start_date and end_date properties en‐
compass the supplied delivery period.
The second subquery calculates the second leg of the route, which comprises the path
from the end location to another delivery center elsewhere in the network. This query
is very similar to the first:
WITH e, upLeg, db1
MATCH downLeg = (db2)-[:DELIVERY_ROUTE*1..2]->(e)
WHERE all (r in relationships (downLeg)
WHERE r.start_date <= {intervalStart}
AND r.end_date >= {intervalEnd} )
The WITH clause here chains the first subquery to the second, piping the end location
and the first leg's path and delivery base to the second subquery. The second subquery
uses only the end location, e , in its MATCH clause; the rest is provided so that it can be
piped to subsequent queries.
The third subquery identifies all candidate paths for the third leg of the route, as follows:
WITH db1, db2, upLeg, downLeg
MATCH topRoute = (db1)<-[:CONNECTED_TO]-()-[:CONNECTED_TO*1..3]-(db2)
WHERE all (r in relationships (topRoute)
WHERE r.start_date <= {intervalStart}
AND r.end_date >= {intervalEnd} )
This subquery is broken down as follows:
WITH chains this subquery to the previous one, piping the delivery bases and paths
identified in legs one and two to the current query.
MATCH identifies all paths between the first and second leg delivery bases, to a max‐
imum depth of four, and binds them to the topRoute identifier.
WHERE constrains the topRoute paths to those whose start_date and end_date
properties encompass the supplied delivery period.
The fourth and final subquery selects the shortest path for leg three, and then calculates
the overall route:
WITH upLeg, downLeg, topRoute,
reduce (weight=0, r in relationships (topRoute) : weight+r.cost) AS score
ORDER BY score ASC
LIMIT 1
RETURN ( nodes (upLeg) + tail ( nodes (topRoute)) + tail ( nodes (downLeg))) AS n
Search WWH ::




Custom Search