0
votes

My question can best be answered with a concrete scenario.

Suppose that I am modeling airline travel. Airports are modeled as nodes and flights as relationships.

Suppose that I have a one way path from Peoria to Chicago to Los Angeles.

PIA -> ORD -> LAX

Thus this path has three airports and two flights: PIA -> ORD and ORD -> LAX. Each flight has an arrival and departure time.

Is it possible to perform calculations/comparisons between every pair of relationships and use them for filtering?

e.g. I would like to calculate the layover time which is the departure time of ORD -> LAX minus the arrival time of PIA - > ORD. If that layover time is less/greater than some minimum/maximum then filter that path out.

Do the above for every pair of relationships in the graph.

I can certainly perform this calculation after the fact. That is, I can find all paths of length N or the shortest path then filter out paths programmatically which don't meet the layover constraints.

I've looked at options using the Java API like Dijkstra but it's too limiting.

I am relatively new to Cypher; most of my work has been with the Java API. Despite my lack of experience with Cypher, I am familiar with using WHERE clauses to exclude nodes and relationships. My question is focused on using WHERE clauses to filter on calculations between every pair of relationships on a path.

Thank you

1

1 Answers

0
votes

To find all 2-leg flights that meet your layover constraints (e.g., minimum = 20, maximum = 90). This simple model assumes the times are stored in minutes.

MATCH p = (a:Airport)-[l1:LEG]->(b:Airport)-[l2:LEG]->(c:Airport)
WITH l2.departure - l1.arrival AS layover, p
WHERE layover <= 90 AND layover >= 20
RETURN p;