A collection of algorithms used for Any-Angle Pathfinding with visualisations.
The implementation of Anya 2016, from here, and JGraphT, from here, are licensed under their respective licenses.
Everything else is unlicensed.
Visualisations of the implemented algorithms:
Testing functions that test computed path lengths and running times.
Map Generators to generate grid maps:
Maps can also be imported from files. Refer to the uiandio/GraphImporter.java comments for details on how to create a grid file.
Language: Java 8 Required
Visualisation: Java Swing
Dependencies: JUnit (not required if using ant build script)
If you want to load existing pre-generated maps, the maps can be downloaded here:
To use them, unzip them and place the mazedata/
and originalbenchmarks/
directories in the root of the repository.
The larger maps used for the comparison in these slides and this paper are stored only as code in StoredTestMazes (they are loaded by running the respective generation code). The exact maps used for the tests are found in AlgoTest. The large maps come from these four test sets: "scaledmazes", "tiledmazes", "automatadcmazes", "mazemaps".
I have also pre-generated the above maps for convenience. They are available here:
To build and run the code, run the following from the base directory (where build.xml is).
ant
java -jar dist/AAP.jar -Xmx4096m
To clean up generated files from the build script,
ant clean
The main class is in AnyAnglePathfinding.java.
Setting the choice variable in main() chooses which component of the program is to be run. More details of each component are given in the Components section.
In general, the maze to be used is configured in loadMaze(), and the algorithm to be run is configured in setDefaultAlgoFunction(), by setting the choice variable.
Components I use most often:
Use this to generate a trace of the algorithm's search tree.
The initial view will be the completed path in blue. Step through the frames to view the algorithm's trace. Generally, blue circles are explored nodes, red lines are parent pointers. The start point and goal points are marked with circles.
Left/Right: Move backward/forward one step at a time.
PgUp/PgDown: Move backward/forward multiple steps at a time.
Up/Down: Move backward/forward one step at a time, will not loop around to the first frame from the last frame.
A/D and S/W: Move backward/forward multiple steps at a time, will not loop around to the first frame from the last frame.
O: Moves a step forward and takes a screenshot at the same time.
P: Same as O, but does not loop around to the first frame from the last frame.
L: Same as P, but jumps multiple steps at a time.
Use this to test algorithm runtimes/pathlength using the test suite defined in the code
The test to be run is specified in the function AlgoTest.run()
in main/Algotest.java
. The test parameters can be edited there.
String[] algoNames = new String[]{
// Define algorithms to test here
"Anya16",
"BasicThetaStar",
};
String[] mapSetNames = new String[]{
// Define the map sets to test on here
"benchmarks",
"automatadcmazes",
};
The list of algorithm names can be found in AlgoTest.getAlgo()
and the list of map sets can be found in AlgoTest.testSequence
.
The following map sets are used for the tests in these slides:
Used to run various experiments on the algorithm. Check Experiment.run()
for details
The Experiment.run()
function has a bunch of commented-out experiments. I usually just define these on the fly as I need to test certain properties of certain algorithms.
Examples of some more notable experiments:
testAlgorithmOptimality()
: Compares an algorithm's computed path length against a known optimal algorithm over an infinite sequence of randomly generated test cases. Very useful for quickly finding example test cases where an algorithm is suboptimal.Used to generate/export grid maps to external files
I don't use this very frequently. (after all, I only need to generate test data once)
Used to preview a map
A very useful tool. It generates a visualisation of the currently-selected grid map. Press any unused key to print the list of hotkeys to the console. (e.g. arrow keys)
Use the left/right mouse buttons to place the start/goal points (respectively).
(Current) list of hotkeys:
ESC: Close the window.
9: Generates the path file from the currently selected points.
0: Generates the maze analysis for the maze.
A: Prints the maze analysis for the maze.
P: Prints the path analysis for the current selected path.
S: Generates a .map and a .scen file from the maze.
Z: Switch mode: Automatically display path between points.
X: Switch mode: Automatically display search tree between points.
C: Switch mode: Disable path computation.
V: Hold down for real-time pathfinding to mouse location
A common use of this tool is to find a good pair of start/goal points to use in [0] Visualisation. My usual workflow:
AnyAnglePathfinding.loadMaze()
by setting the choice
variableZ
to automatically display the shortest path between the start/goal points (powered by ENLSVGs)P
to print the path analysis + coordinates of the two points.Used to generate an algorithm trace from a string
I use this to view algorithm traces of algorithms not implemented in this framework. (e.g. implemented in C++). To do so, I run the algorithm on a certain map, and insert print statements to print out the algorithm trace.
(e.g., when it explores (5,8) with parent (2,4), I print out "2 4 5 8"). One item is printed per line.
The trace is terminated with a #
character.
The trace should be printed in chronological order for the visualisation to make sense.
Each line of the trace is sequence of integers, seperated by spaces.
The following formats can be used in the trace:
<x1> <y1> <x2> <y2>
: Draws a line from (x1,y1)
to (x2,y2)
<x> <y>
: Draws a point at (x,y)
<y> <xLn> <xLd> <xRn> <xRd> <px> <py>
: Generates a fractional horizontal interval on row y
, from xLn/xLd
(left) to xRn/xRd
(right). Also draws lines ot the base point (px, py)
. Used to trace Anya.<y> <xLn> <xLd> <xRn> <xRd>
: Same as above, but without the base point.(Note: These are defined in the function GridObjects.create()
)
Similar to AlgoTest, but we run with test parameters from the command line instead.
The arguments are as follows:
java -jar dist/AAP.jar <algorithmName> <mapSetName> <testType> <outputDirectory>
Example bash script used for running tests:
runtest() {
java -jar dist/AAP.jar -Xmx4096m "$@"
}
runtest Anya16 benchmarks default output_benchmarks
runtest BasicThetaStar benchmarks default output_benchmarks
runtest Anya16 benchmarksrandom default output_benchmarksrandom
runtest BasicThetaStar benchmarksrandom default output_benchmarksrandom
The list of algorithm names can be found in AlgoTest.getAlgo()
and the list of map sets and test types can be found in AlgoTest.testSequence
.