We will learn how to modify the current Dijkstra algorithm in order to approach the problem using pre-processing techniques and optimizing the path-finding time. It can be seen as three big steps—modifying the main algorithm, creating the pre-processing function (handy in editor mode, for example), and, finally, defining the path retrieval function:
- Modify the main function's signature:
public int[] Dijkstra(GameObject srcObj)
- Change the returning value:
return previous;
- Remove the lines from step 4 of the How to do it section:
if (ReferenceEquals(node.vertex, dst)) { return BuildPath(src.id, node.vertex.id, ref previous); }
Also, delete the following line at the beginning:
Vertex dst = GetNearestVertex(dstObj.transform.position); ...