0

I have a directed acyclic weighted graph which I want to traverse.

The constraints for a valid solution route are:

  1. The sum of the weights of all edges traversed in the route must be the highest possible in the graph, taking in mind the second constraint.
  2. Exactly N vertices must have been visited in the chosen route (including the start and end vertex).

Typically the graph will have a high amount of vertices and edges, so trying all possibilities is not an option, and requires quite an efficient algorithm.

Looking for some pointers or a suitable algorithm for this problem. I know the first condition is easily fulfilled using Dijkstra's algorithm, but I am not sure how to incorporate the second condition, or even where to begin to look.

Please let me know if any additional information is needed.

ЯegDwight
  • 23,615
  • 10
  • 43
  • 51

1 Answers1

0

I'm not sure if you are interested in any path of length N in the graph or just path between two specific vertices; I suspect the latter, but you did not mention that constraint in your question.

If the former, the solution should be a trivial Dijkstra-like algorithm where you sort all edges by their potential path value that starts at the edge weight and gets adjusted by already built adjecent paths. In each iteration, take the node with the best potential path value and add it to an adjecent path. Stop when you get a path of length N (or longer that you cut off at the sides). There are some other technical details esp. wrt. creating long paths, but I won't go into details as I suspect this is not what you are interested in. :-)

If you have fixed source and sink, I think there is no deep magic involved - just run a basic Dijkstra where a path will be associated with each vertex added to the queue, but do not insert vertices with path length >= N into the queue and do not insert sink into the queue unless its path length is N.

Petr Baudis
  • 1,128
  • 8
  • 13
  • That is correct, I'm only interested in the exactly N-vertices long path between two set vertices, with the highest possible sum of edge weights for a path of that length. :) Will try your suggestion later today, thanks! – Jimmy S Sep 30 '12 at 08:17