Friday 15 February 2013

algorithm - Modifying A* to find a path to closest of multiple goals on a rectangular grid -



algorithm - Modifying A* to find a path to closest of multiple goals on a rectangular grid -

the problem: finding path closest of multiple goals on rectangular grid obstacles. moving up/down/left/right allowed (no diagonals). did see this question , answers, and this, and that, among others. didn't see utilize or suggest particular approach. have major error in approach?

my of import constraint here is inexpensive me represent path (or list, matter) "stack", or "singly-linked-list", if want. is, constant time access top element, o(n) reversing.

the obvious (to me) solution search path of goals starting point, using manhattan distance heuristic. first path goal starting point shortest path closest goal (one of many, possibly), , don't need reverse path before next (it in "correct" order, starting point on top , goal @ end).

in pseudo-code:

a*(start, goals) : init_priority_queue(start, goals, p_queue) homecoming path(start, p_queue) init_priority_queue(start, goals, q_queue) : (g in goals) : h = manhattan_distance(start, g) insert(h, g, q_queue) path(start, p_queue) : h, path = extract_min(q_queue) if (top(path) == start) : homecoming path else : expand(start, path, q_queue) homecoming path(start, q_queue) expand(start, path, q_queue) : = top(path) (n in next(this)) : h = mahnattan_distance(start, n) new_path = push(n, path) insert(h, new_path, p_queue)

to me seems natural reverse search in way. there think-o in here?

and question: assuming priority queue stable on elements same priority (if 2 elements have same priority, 1 inserted later come out earlier). have left next above undefined on purpose: randomizing order in possible next tiles on rectangular grid returned seems inexpensive way of finding unpredictable, rather zig-zaggy path through rectangular area free of obstacles, instead of going along 2 of edges (a zig-zag path statistically more probable). correct?

it's right , efficient in big o far can see (n log n long heuristic admissible , consistent, n = number of cells of grid, assuming utilize priority queue operations work in log n). zig-zag work.

p.s. these sort of problem there more efficient "priority queue" works in o(1). these sort of problem mean case effective distance between every pair of nodes little constant (3 in problem).

edit: requested in comment, here details constant time "priority queue" problem.

first, transform graph next graph: allow potential of nodes in graph (i.e., cell in grid) manhattan distance node goal (i.e., heuristic). phone call potential of node p(i). previously, there border between adjacent cells , weight 1. in modified graph, weight w(i, j) changed w(i, j) - p(i) + p(j). same graph in proof why a* optimal , terminates in polynomial time in case heuristic admissible , consistent. note manhattan distance heuristic problem both admissible , consistent.

the first key observation a* in original graph same dijkstra in modified graph. since "value" of node in modified graph distance origin node plus p(i). sec key observation weight of every border in our transformed graph either 0 or 2. thus, can simulate a* using "deque" (or bidirectional linked list) instead of ordinary queue: whenever encounter border weight 0, force front end of queue, , whenever encounter border weight 2, force end of queue.

thus, algorithm simulates a* , works in linear time in worst case.

algorithm search linked-list a-star

No comments:

Post a Comment