Alex Rivera | Logout

What algorithm can I use to find the shortest path between specified node types in a graph?

Asked 2009-07-17T12:35:43.547
10

This is the problem:

I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x.

Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...).

The input of the method is the path I want to follow, for example "A-B-C-A-D-B".

The output is the shortest path connecting the points of the type I give in input so for example "p1-p4-p32-p83-p43-p12" where p1 is an A-type, p4 a B-type, p32 a C-type, p83 an A-type, p43 a D-type and p12 a B-type.

The "easy" solution consists of calculating ALL the possible paths but the computational cost is very high!

Can someone find a better algorithm?

As I said in title, I don't know if it exists!

Update:

The key point that prevents me from using Dijkstra and the other similar algorithms is that I have to link the points according to type.

As input I have an array of types and I have to link in that order.

This is an image of Kent Fredric (thanks a lot) which describes the initial situation (in red allowed links)!

alt text

A real life example:

A man wants to visit a church in the morning, go to restaurant and finally visit a museum in the afternoon.

In the map there are 6 churchs, 30 restaurants and 4 museums.

He wants that the distance church-rest-museum is the minimum possible.

Edit
Report

2 Answers

4

alt text

This is how I presently interpret your problem.

Red arrows are me manually tracing the paths that conform to the given ordering constraint.

Costs are not provided, but it is assumed all links incur a cost, and the link costs are different.

If this accurately describes the scenario you are trying to solve, please say so, so that others can better answer the question.

answered 2009-07-17T13:15:18.640
2

On the revision of your question it seems you ask for one node per letter - in that case it is a simple dynamic programming solution: Calculate all the shortest paths of length 1, which satisfy the beginning of your sequence, between each pair of nodes. Then having for k all such paths for all node pairs, it is trivial to construct for k+1.

answered 2009-07-17T12:54:07.250

Your Answer