Using Breadth-First Search
The Breadth-first search (BFS) is a new algorithm as part of GraphFrames that finds the shortest path from one set of vertices to another. In this section, we will use BFS to traverse our tripGraph
to quickly find the desired vertices (that is, airports) and edges (that is, flights). Let's try to find the shortest number of connections between cities based on the dataset. Note that these examples do not consider time or distance, just hops between cities. For example, to find the number of direct flights between Seattle and San Francisco, you can run the following query:
# Obtain list of direct flights between SEA and SFO filteredPaths = tripGraph.bfs( fromExpr = "id = 'SEA'", toExpr = "id = 'SFO'", maxPathLength = 1) # display list of direct flights display(filteredPaths)
fromExpr
and toExpr
are the expressions indicating the origin and destination airports (that is, SEA and SFO, respectively). The maxPathLength = 1
indicates that we only want one edge between...