Cheap and Secure Web Hosting Provider : See Now

# [Solved]: Route planning for a car driver picking up people using public transport

, ,
Problem Detail:

We just had an interesting though for a routing algorithm for people carpooling. Imagine the following situation:

Person 1 is driving with his car from the south of city A to city B far in the north. He is picking up person 2 who is starting in the west of city A and person 3 who is starting in the east of city A. Person 2 and 3 only use public transport. Most likely, the optimal solution will be that they meet somewhere in the center or north part of city A and then drive on from there.

Any hints on an algorithm to find that solution?

#### Answered By : Tom van der Zanden

A generalized version of this problem is likely \$NP\$-complete, however given that very few people are sharing the same car, you can probably get away with an exact, exponential time algorithm.

Assuming your road network is given as a graph, for every node you will want to store:

• The earliest time each person using public transport can get to that node

• For every subset of people sharing the car, what is the earliest time the car can get to that point with that subset of people in it

Basically, if you have \$n\$ persons and one car, you would get a graph with \$2^n+n\$ "layers" (one layer for each subset and one layer for each person using public transport).

You can use a Dijkstra-like algorithm to compute these values. You do a multi-start search, starting from the homes of all the people involved. Whenever the car gets to a new node you check whether any people are ready to join the car, if so, you branch (the car continues without picking them up, but also moves to any layers in the graph that can be reached by picking people up). Whenever a person gets to a new node, you check whether the car has already reached that node (and also branch).

Note it is not really branching, but rather pushing more nodes on to the priority queue.