Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
cazador7907 last edited by
I am not sure where to post this question as it concerns an algorithm and not an aspect of C++ or Qt.
Anyway, I am working on the development of a path finding routine. I put the pseudo code below and wanted to ask for people opinions and thoughts. The routine will search for a path across a sparsely populated Graph Object. The F-Cost is calculated based on the Heuristic of a node, the length of the edge connecting two nodes and efficiency of the edge.
The MasterList is a QMap Object
The OpenList is a Binary Heap
The Path object is a QVector
Path finding pseudo code
- Initialize the two heaps: Open and Master.
- Initialize the return Path vector object.
- Is the starting node equal to the ending node?
a. Add the end node to the return Path.
- Create a new Path element from the starting node. F-Cost will be 0.0.
- Add the Path element to the Master and Open heaps.
- Examine each edge connected to the starting node.
a. If the edge is owned, skip it and move to the next edge.
b. If the edge is un-owned
i. Create a new path node out of the destination node
ii. Calculate the F-Cost for the destination node.
iii. Set its parent property to the current node.
iv. If the destination node equals the end point
1. Add the destination node to the Path vector
v. If the destination node is not the end point
1. Add the destination node to the Master and Open Heaps.
- Find the current node in the Master heap and mark it closed.
a. Set its closed property to true.
- Pop the path node having the lowest F-Cost off of the Open heap and make it the current node.
- Repeat the above process starting at #6.
leon.anavi last edited by
In my opinion it is always easier to explain such kind of algorithm with a block diagram (espesially if it is executed by a single thread) :) You can also get inspiration for optimal solution from existing solutions for path finding algorithms such as the different implementations of the traveling salesman problem ;)