简体   繁体   中英

Longest Path A*, Admissible Heuristics, and Optimality

I'm working on a modified A-Star algorithm. It tries to find the highest-weighted path instead of attempting to find the shortest path.

I have some number of classes, each with a list of unique nodes. Each node has its own value. I'm attempting to determine the best possible combination of nodes from each class to determine the combination or path having the greatest weight. To do this, I am viewing these classes as a tree, with each level containing the nodes in a single class.

Then I search through this tree using A-Star or more specifically, im searching through my tree based on a search stack. Once a node is explored, its children are inserted in a sorted order based on their weight (plus their ancestors weight) plus the possible future weight (my heuristic). Then the top of the stack, with the highest value is selected to search next.

To do this I have an overestimating heuristic; it never underestimates the optimal solution.

If I am looking for the highest weight and not the lowest weight, is this heuristic admissible, and thus is my algorithm optimal?

I should also say my algorithm is currently working, and it is working much faster than brute forcing all possible paths, I'm just wondering if my solution is optimal.

PS: A FormalIsh defination of the current algorithm.

Let S = {S 1 , S 2 , ... , S n }

and each S i has a set of items and a NULL, which represents an item not chosen from this set.

S i = {I 1 , I 2 , ... , I m , NULL}

Also each item only ever exists in one set, IE S i US j = S i + S j

Each Item, I i has an associated value, V i .

The problem is to select a maximum of M offers, one from each set, when summed yield the highest value. I call this selection a Path, P i . A path can be complete, meaning it has a selection from all S, or it can be partial where only x offers are contained within it. Also M

In addition, there exists a function IsCompatable(path) that returns true if a path is compatible. Whether a path is compatible or is completely arbitrary. The Max valued path must be compatible. This is why I can not trivially select the M largest Items from each set.

In addition each set contains a NULL item, so that an item need not be selected from that set.

The Trivial Algorithm would to make a search tree and generate all possible combinations of items in S, with each path to the trees leaves said to be a path.

let G(P) be the current value (the summed value of each item) of the partial path. Let H(P) be an estimation (heuristic) of the value of the future path. H(P) = The Y values from Y items from YS i in S. Each item is the item with the maximum value in the S i where i > len(P). Y = M - the current length of the partial path P.

To Find the path with the greatest value, I keep a sorted Queue of partial paths, sorted on their values + their possible future values, ie G(P i ) + H(P i ). I Initialize this Queue by adding paths contained in S 1 .

While the Queue is not empty or a path has not been found:
    p = Pop the path from the top of Q
    if p is Complete:
        A full path has been found
        return p
    find the possible children of p by adding an item to p from the next set.
    for child in Children:
        if IsCompatable(child):
            add child back to Q in sorted order on G(child) + H(child)

There it is, now is my Heuristic admissible?

Problem description

(This has been added on in an attempt to formalize the problem description. It is incomplete.)

Consider a set U, partitioned into disjoint subsets S 1 , ..., S n .

Let f : U → ℝ be a function that assigns a value to each item in U.

Let V be the set of all subsets of U containing at most one item from each S i , and let V' ⊂ V be the set of permissible solutions. Membership in V' can be easily computed.

The goal is to find the solution P ∈ V' which maximizes ∑ x∈P f(x).

A* is not designed for this. Such a heuristic would not work because you must reject loops (otherwise there is no solution), and the heuristic would always underestimate the distance from a given node if there were no path to the target that did not create a loop... but there is no way to know this.

There is no known good general way to solve this problem, because longest-path problem is NP-hard, as shown by reduction from the Hamiltonian path problem (see Wikipedia ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM