terrabl
ATApache TinkerPop
•Created by terrabl on 8/3/2023 in #questions
Getting Property Out of a Variable in Python Gremlin Query
I've been working on attempting to find a performance way to route from point A to point B.
Right now my schema is as follows
Vertex Labels:
1. Airport:
- Properties: airport: Airport code.
2. Day:
- Properties: Datestamp representing the day.
Edge Labels:
1. has_flights_on:
- Connects Airport to Day.
- Indicates an airport has flights on a specific day.
2. flight:
- Connects Day to Airport (destination).
- Properties: flight_id, origin, destination, start_timestamp, end_timestamp, capacity, tail_number, equipment_type.
Graph Structure:
- Airport vertex for each airport.
- Day vertex for specific days connected to airports with flights.
- has_flights_on edges connect Airport to Day.
- flight edges connect Day to Airport, representing flights.
Example:
- Airport (JFK) -> has_flightson -> Day (2023-08-03) -> flight -> Airport (LAX)
- Indicates a flight from JFK to LAX on August 3, 2023.
This is my query right now
```
g.V().has('Airport', 'airport', origin) # find origin airport
.as('current_airport')
.repeat(
.out('has_flights_on') # Go to the corresponding Day vertex
.has('date', gte(start_datestamp))
.has('date', lte(end_datestamp))
.outE('flight') # Go to the Flight edge .where(.values('origin').is_(.select('currentairport').values('airport'))) # this is the problem
.inV().hasLabel('Airport') # Go to the destination Airport vertex
.as('current_airport') # Update the current airport alias
.simplePath() # Ensure that the path doesn't contain cycles
)
.until(.has('airport', destination).or().loops().is(4)) # Finish when destination is reached or max hops exceeded
.has('airport', destination)
.path()
.by(__.valueMap('airport', 'flight_id', 'start_timestamp', 'end_timestamp'))
.toList()
```
The problem is the where, see below for more context.
20 replies
ATApache TinkerPop
•Created by terrabl on 7/24/2023 in #questions
Route from origin to destination between two datetimes
Hey, I'm attempting to create a graph DB that will allow me to efficiently find a route from origin to destination between two times stamps. I've created two different graph DBs were different levels of success.
I have one graph that has AirportDay vertices and Flight edges between them. This was my first attempt, and while it worked, since the Flights were edges I was not able to guarantee that the next flight in the route took off before the previous one landed.
This caused me to create my second graph, which is Flights as vertices and a connects_to edge to connect Flights to other Flights. This one works very well (besides inserting into the DB but that's not too big of a problem).
I have a few questions
1. Are these optimal designs for this type of problem, I'm sure someone has had this problem before, I tried following this blog (https://maxdemarzi.com/2017/05/24/flight-search-with-neo4j/) but couldn't get it to work
2. Why does my second query output paths that go through the destination?
For example it output this path for when my origin was MIA and destination is ATL. I want this query to stop once it hits ATL...
1912MIA20230612 -> 0957ATL20230612 -> 2455DEN20230612
5 replies