2

Suppose that I want to change the logic in A*, trying to find the most useful path (i.e., the one with the highest gain) instead of finding the shortest path (i.e., the one with the lowest cost).

In my case, a goal is not fixed as a unique ending node. A node is defined as any node having distance B from the starting point.

In the vanilla version ("finding the shortest path") I am required to not overestimate the cost (i.e., finding a heuristic that is less or equal to the real cost).

In my modified version instead ("finding the most useful path"), edges are tagged with the utility and not with the cost, and I want to maximize the final gain, given a constraint of going through a maximum of B edges. Should I overestimate the utility (i.e., find a heuristic that is greater or equal to the real utility) in order to make A* work?

EDIT: More formalized, let

f(n) = g(n) + h(n)

be the utility of a node, composed by:

  • g(n): what I gain when going from the starting node to n
  • h(n): the heuristic, i.e., an estimate of what I gain when going from n to the goal (where the goal is a node whose distance from the starting point is B)

Should h(n) be overestimated and f(n) be maximized in order to identify the best path?

Notice that B is a budget, and thus it can be spent completely, i.e., it is not necessary to find a path that is shorter than B steps.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Eleanore
  • 1,750
  • 3
  • 16
  • 33
  • Could you just negate all the utilities and use the existing logic? – Charles Marsh Jun 06 '13 at 12:52
  • I could do that I guess, however it should be more valuable for me to do in the other way around. I was wondering whether there is something tested in this case. – Eleanore Jun 06 '13 at 12:53
  • It should be roughly sufficient to make sure that you dequeue nodes from the frontier in maximum (rather than minimum) order. That is, when choosing the next node to expand, choose that with the highest value (utility). Are you using a library or have you written your own solution? – Charles Marsh Jun 06 '13 at 12:57
  • No, I'm going for a custom solution. – Eleanore Jun 06 '13 at 13:05

1 Answers1

1

Your problem is the longest path problem, which is strongly NP-Hard. This means that, not only is there (almost certainly) no fast exact algorithm, but there is also (almost certainly) no good approximate algorithm.

You will unfortunately either have to brute-force it, or resort to various global optimization techniques, like annealing, genetic programming etc.


Negating the sign of the edge-weights, as @Charles suggests, will not work, as A* cannot handle negative edge-weights. And other algorithms which can handle negative edge-weights still cannot handle negative cycles.

BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • @Elanore: The "longest path" does not mean the path with the most nodes, it means the path with the highest total weight; so the problem you've defined in your edit is actually exactly the longest path problem. This should be enough to convince you that there is *(almost certainly)* no variation of A\* or any other algorithm that will efficiently solve your problem, regardless of what heuristic you use. – BlueRaja - Danny Pflughoeft Jun 06 '13 at 16:25
  • Yes, you are right. So, does it mean that in general A* cannot solve maximization problems? Or does it apply just to my problem? – Eleanore Jun 06 '13 at 18:45
  • @Eleanore: A\* only solves the shortest path problem. If you have some maximization problem *(which is a very, very broad term)* that you can phrase as a shortest-path-on-a-graph problem, then A\* *(or at least Djikstra's)* will work. Otherwise, it will not. A\* cannot be used to solve the longest-path problem. – BlueRaja - Danny Pflughoeft Jun 06 '13 at 18:57
  • Ok, got it. One last question: then, if applied in the way I suggested, it would bring to a solution that is not optimal (it would be just a path that is not the shortest one), right? – Eleanore Jun 06 '13 at 19:44
  • @Elanore: I don't know how to describe the path, but it would have a very low probability of being optimal. – BlueRaja - Danny Pflughoeft Jun 06 '13 at 19:50
  • Do these considerations hold also in the case the graph is acyclic? (absence of infinite length paths) – Eleanore Jun 07 '13 at 08:06
  • @Elanore: If the graph is acyclic, then Charles' suggestion of negating all the weights and finding the shortest path (using eg. [Bellman-Ford](http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm)) will work. Alternatively, you could do a simple [Topological sort](http://en.wikipedia.org/wiki/Topological_ordering) as outlined [here](http://en.wikipedia.org/wiki/Longest_path_problem#Acyclic_graphs_and_critical_paths). – BlueRaja - Danny Pflughoeft Jun 07 '13 at 09:40