Re: Bus/train timetable search algorithm



Patricia Shanahan wrote:
Alex Fraser wrote:
adamwatson@xxxxxxxxxxxxx wrote:
Does anyone know of public transport routing algorithms that use a
timetable and include changing between services?
[snip]
I'm left with a depth first exhaustive search, but I feel there must
be a better way.

I think in practice an exhaustive search would often not be practical, requiring some sort of approximation instead.

You can use the timetables to construct a graph where the edge weights are the lower bound of the time to get between the nodes. The simplest way would be a directed graph with one edge per unique combination of places A and B where B immediately follows A in a timetable. An undirected graph - with one edge where either A follows B or B follows A - would be more compact and generally nearly equivalent, but may include some impossible hops.

Given this, you can use Dijkstra's algorithm on the graph to find the quickest "theoretical" route from starting point to destination. Then tweak the graph: increase the weights of the edges traversed in the route by some factor, remove edges, etc (I'm not sure what rules would work best). Use Dijkstra's algorithm again to find a possible alternative route. Repeat a few times.

From the above you can create a new, (hopefully much) smaller graph comprising all the nodes/edges that were visited/traversed in the quickest routes, which should be amenable to an exhaustive search - taking into account start time, timetables, minimum connection times, and anything else you want.

I think there may be a simpler approach. For simplicity, I'm going to
use "flight" to mean a single, non-stop segment. Flight A "connects to"
flight flight B if B departs from A's destination, does so long enough
after A arrives that a passenger arriving on A could catch B, and B is
the earliest flight to B's destination that meets those conditions.

Create a graph with the following nodes:

A "flight" node for each flight.
>
A "start" node for the starting point.

An "end" node for each destination.

Create the following edges;

For each pair of flights A and B such that A connects to B, create an
edge connecting A's flight node to B's flight node, with weight equal to
the difference in their departure times.
>
For each flight A that departs from the starting node in the original
graph, create a zero weight edge from the start node to A's flight node.

How about making the weight the difference between the departure time and given start time?

For each flight A, create an edge with weight equal to A's duration from
A's flight node to the end node for its destination.

Apply Dijkstra's algorithm to the new graph.

With the change above, I think this would now give you the route with the earliest arrival based on the given start time.

I like the idea!

Alex
.



Relevant Pages

  • Re: Bus/train timetable search algorithm
    ... the quickest route does not necessarily comprise of the quickest ... Basically the onward journey from a node depends on the arrival time at that node, which is a function of the starting time and route taken. ... The simplest way would be a directed graph with one edge per unique combination of places A and B where B immediately follows A in a timetable. ... From the above you can create a new, smaller graph comprising all the nodes/edges that were visited/traversed in the quickest routes, which should be amenable to an exhaustive search - taking into account start time, timetables, minimum connection times, and anything else you want. ...
    (comp.programming)
  • Re: Python Programming Contest
    ... The thing is, it's fully general, so it works on absolutely any graph; if the graph you're traversing has particular properties, you might be able to leverage those to find a solution faster. ... Flights are then simply edges which link the origin city on the day they depart to the destination city on the next day; their weight is the cost of the flight. ...
    (comp.lang.python)
  • Re: Quick Crosswind Calculation
    ... of the whizwheel calcs. ... graph will only work at one TAS so I have one for 90 for the ... than rooting around with a whizwheel in flight. ... with instinct in most aspects of flying. ...
    (rec.aviation.student)
  • Re: Quick Crosswind Calculation
    ... example variation might only be a couple of degrees, ... use them in flight), I do my pre flight planning wind calcs using ...  of the whizwheel calcs. ... track combination (of course such a graph will only work at one TAS ...
    (rec.aviation.student)
  • Re: Quick Crosswind Calculation
    ... example variation might only be a couple of degrees, ... use them in flight), I do my pre flight planning wind calcs using ... track combination (of course such a graph will only work at one TAS ... had to pass a trigonometry course there wouldn't be ...
    (rec.aviation.student)