I am trying to solve one graph traversing problem which might be classical to guys who are familiar with the topic. However, I am not. I have directed graph where nodes are cities and plane can fly from one to another. The network is quite complex. I have to find number of paths from e.g. Atlanta to Orlando with defined (zero, one, two…) number of stops. I do this by multiplying adjacency matrix exact number of times (repeated squaring) which gives distance matrix. The problem is how to eliminate redundant paths e.g. Atlanta-Boston-Atlanta-Orlando. This path has two stops which is O.K. from the algorithm point of view (if we need two stops) but makes no sense. Is there algorithm to eliminate such paths?
Asked
Active
Viewed 38 times
1 Answers
0
This comes down to counting the number of simple paths of length k between two given nodes, a question that is addressed e.g. here: stackoverflow. The problem is #P-complete, so not much hope for an efficient algorithm, I'm afraid.
smapers
- 849
- 5
- 10