2

I'm trying to find a path between two points. Each edge in my graph has two separate weights. I already know the shortest path, if you only take the first weight into account, between the two points. What I need to do is to maximize the second weight whilst making sure the first does not exceed a constraint. The constraint is that the total of the first weight should not exceed its total on the shortest path by more than X%. How do I go about doing that? The final solution need not be an exact solution, as it is intended to be a heuristic.

The graph is directed with edges going from node 1 to 2 and from node 2 to 1 in some cases (but not all).

Please note that:

BFS would simply take too much time. My problem is that I need to go down a path that doesn't exceed the limit for the total of the first weight along it but the total for the second weight along it needs to be maximized. The graph is huge with hundreds of thousands of edges.

cconsta1
  • 737
  • 1
  • 6
  • 20
  • 1
    Pretty sure the "longest path problem" can be reduced to this and therefore it is NP-complete. – Nemo May 11 '15 at 04:02
  • May the path include nodes or edges multiple times? – Jens Schauder May 11 '15 at 05:12
  • Yes but you can't travel on an edge multiple times in the same direction. It's a directed graph as I just mentioned I the top post. – Syed Shahrukh Raza May 11 '15 at 16:07
  • Possible duplicate of [Single-source shortest path with distance and weight for each edge](https://stackoverflow.com/questions/35133996/single-source-shortest-path-with-distance-and-weight-for-each-edge) – nbro Oct 08 '17 at 20:52
  • So you need to find 2 routes? one is the shortest and your question is about the second route? can you put an example for graph and desired solution? – yossico Aug 09 '23 at 16:34

1 Answers1

0

I'd simply do a breadth first search:

Beginning from your starting node collect all possible next nodes and keep track of first and second weight, as long as the first weight meets the constraint.

Build a list of all possible paths from these nodes and iterate.

If a node doesn't produce any more path candidates, because all edges have a first weight that is to high, compare it to the current best path and replace it with the new one, if the new one is better.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • BFS would simply take too much time. My problem is that I need to go down a path that doesn't exceed the limit for the total of the first weight along it but the total for the second weight along it needs to be maximized. The graph is huge with hundreds of thousands of edges. – Syed Shahrukh Raza May 11 '15 at 04:29