This repository provides a minimal working example of running A* graph search with Boost Graph Library. There are more general examples of this use case [1,2], but this example focuses on the use case for roadmap-based path planning.
Here, each vertex has an attribute which is the configuration space point that it represents, and each edge has attributes for the edge weight (typically some distance function between vertices) and the edge status (whether collision-free or not).
The following behaviour is exemplified here :
- Loading a Boost
.graphml
file that defines the configuration that each vertex represents, and the edges connecting vertices. This is sometimes called an explicit roadmap (graph). - Defining the
struct
types that represent the attributes of the vertices and edges of the graph. - Creating a
Boost Graph
(specifically an undirected graph represented as an adjacency list), as well as the property maps that map the vertices and edges to their attributes. - Defining a heuristic function for A* search that depends on the underlying configurations of the vertices (as they typically should).
- Running
boost::astar_search
in its most general form with all the relevant arguments, to obtain the shortest path between two randomly chosen vertices.
This has been tested on Ubuntu 14.04 and 16.04 as well as MacOS Sierra (with some particular tweaks mentioned below). Following are the dependencies:
A Note on MacOS - What worked for me was to replace ${Boost_INCLUDE_DIRS}
with ${Boost_INCLUDE_DIR}
and ${EIGEN3_INCLUDE_DIRS}
with ${EIGEN3_INCLUDE_DIR}
in CMakeLists.txt
.
To run, clone the repo and do the following inside the top-level directory of the repo:
mkdir build && cd build
cmake ..
make
./example --r ../data/halton_2d_withedges.graphml --d 2
The data/
folder has an example .graphml
file where the vertices are sampled on a 2D unit grid. The roadmap has 30 vertices and the configurations are generated from a 2D Halton sequence, and edges connect vertices with mutual Euclidean distance less than some threshold. The graphs themselves were generated with NetworkX where the configurations are specified as vertex attributes.
It is not best practice to place everything in one .cpp
file, especially when there are reusable modules, but I have done so for the purposes of this minimal example to make it easier to follow. Finally, I have put in some NOTE:
tags in the commands to highlight important points about usage.