File        :  PFAII.ZIP
Name        :  Path Finder Algorithms II
Author      :  legion, legion@inside3d.com
Date        :  March 24, 1998

Credits     :  William van der Sterren, Dijkstra's algorithm
               Michael Smit, Navigator Algorithm (a Dijkstra's variant)
               Terry Hendrix II (for ideas on file i/o)



This file contains the source code to Path Finder Algorithms II, the sequel to
the original Path Finder Algorithm.  Only two algorithms are presented in the
sequel.  If you wish to use the other algorithms (e.g. Floyd's), you will need
to download the original, pfa.zip.

The first algorithm used is a variant of Dijkstra's given to me by William
van der Sterren.  It will calculate a path from a source node to a destination
node.  It is pretty fast but the draw back to this algorithm is that it only
calculates a single path.  Any other path it calculates is "lost".  The number
of calculations is at-most NxN for each path.  However, in a given system,
there can be at-most (N-1)x(N-1) number of paths.  This algorithm, then,
will take an enormous amount of time to calculate ALL the paths.  So
the order of magnitude is around NxNxNxN.  Should only be used if only a
handful of paths is needed at a time.

The second algorithm is the "Navigator" created by Michael Smit
(http://www.mathcs.carleton.edu/courses/course_resources/cs227_w/96/smitm/).
Unfortunately, however, it is rougly 8 times slower than the above algorithm
in calculating a single path.  However, it is much much faster than the above
algorithm in calculating ALL paths.  The order of magntitude for the Navigator
is roughly 2xNxNxN which is considerably less than NxNxNxN.  However, the
algorithm has its weakness.  In short, it requires twice the number of
iterations as Floyd's and since each iteration uses more calculations than
Floyd's, it is much, much slower than Floyd by a factor of three.

Additionally, the original Navigator is not to friendly to one-way paths.  The
paths it calculates can be questionable paths.  This is the same with Floyd's.
Neither algorithm should be used for systems containing one-way paths.

There are actually three variations of the Navigator in PFA II.  Besides the
original, there is a "hacked" version and the so-called "new" version.  The
hacked version is one step removed from the "new" version.  It shows the
progression from the original to the "new".  The new version uses a linked
list of non-visited nodes.  Once a node has been "visited", it is removed from
the list.  The "hacked" version is a tad bit slower than the original.  It
is not recommended over the original unless your system has one-way paths.
The hacked version has been modified to be more user-friendly to one-way
paths; it is a lot more user-friendly.  It does, however, requires less memory
than the new Navigator.

Linked-lists eat up more CPU than arrays or simple integer variables.  So
for small number of nodes, the speed improvements decreases.  For 128 nodes,
the new navigator is slightly faster than than the original Navigator.
At 256 nodes, the new Navigator is almost twice as fast.  For 512 nodes, the
new Navigator is more than twice as fast( ~2.2 faster).  It takes the new
Navigator roughly 50 seconds on a P200 to calculate ALL the paths to ALL
nodes in a 512 node system.  For 1024 nodes, the new Navigator takes roughly
500 seconds using a P200.  (This assumes PFA was recompiled to use less
memory.  That is, the MAX_NODES has been set properly.  It is currently set
to 2048 nodes which is more than you need.)

PFA II also contains a list of *.dat files.  These are data files for nodes.
Not only does it contain the "location" of each node but it contains the
links and distances as well.  The data files can be made smaller if the
distances were NOT saved to a file.  Since the location is also stored, these
distances can be calculated "on-the-fly" as the file is being loaded.
However, for speed considerations, the distances were also stored in the file.

PFA uses nodes.dat to read/save the data.  If you wish to use a specific
data file, you will need to rename it to nodes.dat.  If you wish to save
a specific data file (i.e., you don't want to overwrite an existing file),
you will need to rename nodes.dat (e.g. rename nodes.dat to myfile.dat).

The size of the data files should not be alarming.  The data file for 2048
nodes is only 280k.  In this file, each node is linked to 16 other nodes.  In
a typical game, it is unlikely that every node will be linked to 16 other
nodes.  If you set it up so that each node can only be a certain distance from
each other, then on any x-y plane, there can only be 6 nodes that can link to
a "center" node.  This, of course, does not include any nodes that are higher
than a "center" node.  A more appropriate number would be around 8 to 10
links which will include such nodes.

The graph matrix containing the calculated paths are the same for both the
new navigator and the William's Dijkstra's.  However, the graph matrix for the
original navigator is not compatible; the paths are in reverse.  Graph matrix
contains the paths; it is saved in the nodes.pth file.  If a nodes.pth file
is found, it will load the data from that file instead for the new Navigator
algorithm.  You will find that saving the path file allows for much faster
game.  The loading of the data is longer, but the calculations is much, much
faster since the only calculations involved is simply looking up the path.
Thus, this will allow you to devote more CPU to actual bot "AI".  The price
for this is obvious: you will need more space on the hard-drive and the
loading time will be longer (though, not much longer).  The path files are
huge.  For 512 nodes, the path file is approximately 2 megabytes in size.
For 1024 nodes, it would be 8 megabytes.  This should tell you that for 1024
nodes, the graph matrix takes up at least 8 megabytes of memory!  If you want
a 2048 nodes path file, you will need 32 megabytes of memory for the graph
matrix alone (as well as 32 megs of hard-disk space.)  The path file for 128
nodes is included.

MAKE SURE THAT THE nodes.pth AND THE nodes.dat CORRESPOND TO EACH OTHER.
OTHERWISE, YOU WILL END UP WITH WIERD COMPARISONS.  THAT IS, THE PATHS
CALCULATED USING THE NEW NAVIGATOR WILL BE DIFFERENT FROM THE PATHS CALCULATED
FROM THE OTHER ALGORITHMS.  If in doubt, delete nodes.pth prior to running
the program.

NOTE: If you have the path file, then the nodes.dat is not needed by the
new Navigator algorithm since all path calculations are already finished.




