Pergunta

I need the above functionality for pathfinding.

I'm using the boost queue as it apparently allows me to do this.

I have my queue setup like so:

typedef boost::heap::priority_queue<PathFindingNode *, boost::heap::compare<MyClassCompare> > MyPriorityQueue;

I want to create a method that takes in type PathFindingNode as a parameter, then checks to see if this Node is already in the queue.

I found I could iterate through the queue like this:

typename MyPriorityQueue::iterator begin = self.queue->begin();
typename MyPriorityQueue::iterator end = self.queue->end();

for (typename MyPriorityQueue::iterator it = begin; it != end; ++it)
{
}

But I don't understand how to use the it value to compare against a node passed into the method block?

Foi útil?

Solução

If you iterate over the queue each time, you'll kill the performance guarantees of your algorithm. Instead, you should store the handle returned from the queue upon adding a new entry into the queue and use the handle to potentially update the priority of the entry. You might need to use one of the node-based priority queues, however.

You could e.g. use the Fibonacci Heap whose push() yields a handle_type. You'd store this value with your node and later use with increase() or decrease() to adjust the priority of the node in the heap.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top