1

I have a variant on the classic 'shortest path' problem and I don't know how to approach it. My graph topology is as such:

There is one source and one sink.

Other nodes are designated by a letter and subscript integer (e.g., A1,B1,C1,A2,B2,C2,....A30,B30,C30). There is one node per possible letter/integer combination.

There is one zero-cost directed edge from the source to each of A1, B1, C1. There is one zero-cost directed edge from each of the nodes with the largest integer to the sink (e.g., when the integers go up to 30, there is one zero-cost directed edge from A30 to the 'Final Destination Node', and an identical edge from B30 and from C30).

From each node there is a directed, weighted edge to one other node of each of the other letters with a larger integer.

For example, there may be a directed weighted edge from A1 to B3 and from A1 to C10; however you won't see edges from A1 to both B3 and B5 because the destinations are both 'B' edges. There are no edges that move from one node with a letter, to another node with a letter (e.g., no B3 to B10) and no edges that move from a node with a higher integer to one with a lower integer (e.g., no B30 to C10).

I know that I can use Djikstra's algorithm to find a singular shortest path from origin to destination, but my goal is somewhat different. I want to:

1) Find a single shortest path from source to sink that visits each of the 'letters' once and only once. Any group of integers will work as long as I visit all the letters. Eg. visiting the node set A1, B22, and C27 between the source and sink is acceptable; visiting A10, A15, B22 is not. 2) Find two paths that, combined, visit each of the letters once and only once. If the 'letter set' was ABCDEF, one route could visit ABD and the other CEF; but we couldn't have one route visit ABCD and the other visit DEF, because D would overlap. The goal is to identify two paths that find the minimal longer route - I don't care about the total time as much as about this minimax. 3) Same question as #2 but with 3 paths, 4 paths, etc.

I assume I could make a very complicated integer program but didn't know if there were shortest-path algorithms already available to solve this. Bonus points if it's ready-made in an R package.

Ralph

Ralph
  • 255
  • 2
  • 18
  • Are you interested in more of a coding or algorithmic answer? If you are looking for an algorithm this may be more appropriate for cross validated. If you want a coding answer can you give some example code to construct a graph that meets the rules? To accomplish your first goal you could just eliminate all edges that start and end at the same letter and use the shortest path functions. You could use get.edgelist() and grep() to find these edges. – Ryan Haunfelder Jun 23 '16 at 15:54
  • I am more interested in an established algorithmic method. And I can't just eliminate all edges that start and end at the same letter - I need to also ensure that each route only 1) visits only one node from each letter, and 2) visits at most one node at each integer. So it's different than your standard shortest-path algos since a shortest-path may violate either of these rules. Also how can I crosspost to CV? – Ralph Jun 23 '16 at 19:18
  • Can you have edges between nodes with different letters but the same integer? Ex. B2 to C2? From your problem statement it appears not. – Matei Florescu Sep 24 '16 at 10:50
  • No. Edges are not prohibited between nodes with the same letter, or nodes with the same integer. Also prohibited are directed edges where the origin node has a higher integer than the destination node. So for instance a directed edge from B2 to C5 may be included (but isn't required, it is dependent upon the specific problem) however you will never see a directed edge from C5 to B2, or C5 to B5. – Ralph Sep 24 '16 at 17:25

0 Answers0