A heap that supports the modification of its elements?

Here is my script. I want to implement A * (in Python) without resorting to minimal time or in operations. I need a bunch to be able to effectively get the lowest weight.

My immediate answer was “Easy! I will use heapq!” Then I found that life is less often as simple as we would like. It turns out that this strategy is suboptimal for one of the critical points A *. When I consider children, I need to periodically update dozens of children already on the heap.

For those whose A * memory is a bit lost, the bottom line is that I want to take the item, change its weight and change the heap to reflect the change, all in sublinear time.

Any suggestions?

+3
source share
3

; , Python, . d-ary . heapq , ( , , , ). . http://en.wikipedia.org/wiki/D-ary_heap , , , .

+3

, heapq, Queue.PriorityQueue . , A: , B: .

0

"" , , " " .

( ) . , : a) (, extractMin ): , . b) (, Graph): , .

Of course, this leads to a lack of space (2 additional pointers / integers per element), but it makes heap rebuilding very cheap (replacing several pointers instead of replacing all elements), which in turn makes it less painful to add some additional satellite data for your elements .

0
source

Source: https://habr.com/ru/post/1794030/


All Articles