The path returned is a string of direction digits. Determine FValue (in the priority queue) d = static_cast(sqrt((double)(rd*rd+cd*cd))) Estimation function for the remaining distance to the goal.Ĭonst int & getHValue(const Location& locDest) const Void updateGValue(const int & i) // i: direction Void calculateFValue(const Location& locDest)įValue = GValue + getHValue(locDest) * 10 The program below, gives lower-F the highest priority by overloading operatorĬonst int IDIM = 8 // horizontal size of the squaresĬonst int JDIM = 6 // vertical size size of the squaresĬonst int NDIR = 4 // number of possible directions to go at any position Like stack and queue, priority_queue is an adaptor that is built on top of one of the basic sequences the default sequence being vector. Thus, the priority_queue has nearly the same interface as a stack, but it behaves differently. When we're done with it, we call pop( ) to remove it and bring the next one into place. The priority_queue ensures that when we look at the top( ) element, it will be the one with the highest priority. We can allow the default less template to supply this, or we can provide one of our own as in the code below. When we push( ) an object onto a priority_queue, that object is sorted into the queue according to a comparison function or function object. The C++ code below is based on that article, and it's using priority_queue of STL to store sorted list of nodes.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |