DHART
|
Algorithms to find the shortest path between nodes in a HF::SpatialStructures::Graph. More...
Classes | |
class | BoostGraph |
A graph usable with the BoostGraphLibrary. More... | |
struct | BoostGraphDeleter |
Deleter for the BoostGraph. More... | |
struct | DistanceAndPredecessor |
Holds and maintains a distance and predecessor matrix. More... | |
struct | DistPred |
A single row of a distance and predecessor matrix. More... | |
struct | Edge_Cost |
Data stored for every edge in the BoostGraph. More... | |
struct | vertex_data |
Data stored for every vertex in the BoostGraph. More... | |
Typedefs | |
typedef boost::compressed_sparse_row_graph< boost::directedS, vertex_data, Edge_Cost > | graph_t |
Type of graph held by the BoostGraph. More... | |
typedef boost::graph_traits< graph_t >::vertex_descriptor | vertex_descriptor |
Quick alias to shorten the typename of vertex descriptors for our graph_t type. /summary> More... | |
typedef std::pair< int, int > | pair |
Shorten std::pair to simplify graph construction. More... | |
Functions | |
Path | ConstructShortestPathFromPred (int start, int end, const std::vector< size_t > &pred, const std::vector< float > &distances) |
Construct the shortest path from start to end using the given predecessor and distance vectors. More... | |
Path | ConstructShortestPathFromPred (int start, int end, const DistPred &dist_pred) |
Overload to call this with a distPred instead of the raw arrays. More... | |
DistPred | BuildDistanceAndPredecessor (const graph_t &g, int id) |
Build a row of the distance and predecessor matrices for the node at id. More... | |
Path | FindPath (BoostGraph *bg, int start_id, int end_id) |
Find a path between points A and B using Dijkstra's Shortest Path algorithm. More... | |
vector< Path > | FindPaths (BoostGraph *bg, const std::vector< int > &start_points, const std::vector< int > &end_points) |
Find a path from every id in start_ids to the matching end node in end_ids. More... | |
void | InsertPathsIntoArray (const BoostGraph *bg, const std::vector< int > &start_points, const std::vector< int > &end_points, HF::SpatialStructures::Path **out_paths, HF::SpatialStructures::PathMember **out_path_members, int *out_sizes) |
A special version of FindPaths optimized for the C_Interface. More... | |
DistanceAndPredecessor | GenerateDistanceAndPred (const BoostGraph &bg) |
Generate the distance and predecessor matricies for a specific boost graph. More... | |
std::unique_ptr< BoostGraph, BoostGraphDeleter > | CreateBoostGraph (const HF::SpatialStructures::Graph &g, const std::string &cost_type="") |
Create a new boost graph from a HF::SpatialStructures:Graph. More... | |
void | InsertAllToAllPathsIntoArray (BoostGraph *bg, HF::SpatialStructures::Path **out_paths, HF::SpatialStructures::PathMember **out_path_members, int *out_sizes) |
A special version of FindPaths optimized for the C_Interface, such that all paths possible from each node to every other node are generated. More... | |
std::vector< HF::SpatialStructures::Path > | FindAllPaths (BoostGraph *bg) |
Find a path from every node to every node (NOTE: Not implemented yet.) More... | |
Algorithms to find the shortest path between nodes in a HF::SpatialStructures::Graph.
This namespace utilizes pathfinding algorithms from Boost internally.To make use of the algorithms in this namespace, first you must create a BoostGraph from the HF::SpatialStructures::Graph you want to find paths in.
struct HF::Pathfinding::Edge_Cost |
Data stored for every edge in the BoostGraph.
Each edge in the graph only stores its weight as a float.
Definition at line 99 of file boost_graph.h.
Class Members | ||
---|---|---|
float | weight | Cost of traversing this edge. |
struct HF::Pathfinding::vertex_data |
Data stored for every vertex in the BoostGraph.
Every vertex stores in the graph stores it's index p and a unique double d.
Definition at line 111 of file boost_graph.h.
Class Members | ||
---|---|---|
double | d | Unknown may have been used for the colormap. |
graph_traits< compressed_sparse_row_graph< directedS > >::vertex_descriptor | p | The index of a vertex in the CSR. |
typedef boost::compressed_sparse_row_graph< boost::directedS, vertex_data, Edge_Cost > HF::Pathfinding::graph_t |
Type of graph held by the BoostGraph.
Set the graph as directed, store vertex_data for each vertex store Edge_Cost for each edge.
Definition at line 135 of file boost_graph.h.
typedef std::pair<int, int> HF::Pathfinding::pair |
Shorten std::pair to simplify graph construction.
Definition at line 142 of file boost_graph.h.
typedef boost::graph_traits<graph_t>::vertex_descriptor HF::Pathfinding::vertex_descriptor |
Quick alias to shorten the typename of vertex descriptors for our graph_t type. /summary>
Definition at line 139 of file boost_graph.h.
Build a row of the distance and predecessor matrices for the node at id.
g | Graph to build the predecessor and distance matrices for. |
id | The node to generate the predecessor and distance matrix for. |
Definition at line 146 of file path_finder.cpp.
References HF::Pathfinding::DistPred::distance, HF::Pathfinding::DistPred::predecessor, and HF::Pathfinding::Edge_Cost::weight.
Referenced by FindPath(), FindPaths(), and InsertPathsIntoArray().
|
inline |
Overload to call this with a distPred instead of the raw arrays.
start | Starting point of the path to generate. |
end | End point of the path to generate. |
dist_pred | DistPred containing the predecessor and distance matricies start. |
Definition at line 133 of file path_finder.cpp.
References ConstructShortestPathFromPred(), HF::Pathfinding::DistPred::distance, and HF::Pathfinding::DistPred::predecessor.
|
inline |
Construct the shortest path from start to end using the given predecessor and distance vectors.
start | ID of the starting point. |
end | ID of the end point. |
pred | Predecessor matrix for the start node. |
distances | Distance matrix for pred |
Definition at line 78 of file path_finder.cpp.
References HF::SpatialStructures::Path::AddNode(), HF::SpatialStructures::Path::Reverse(), and HF::SpatialStructures::Path::size().
Referenced by ConstructShortestPathFromPred(), FindPath(), FindPaths(), and InsertPathsIntoArray().
std::unique_ptr< BoostGraph, BoostGraphDeleter > HF::Pathfinding::CreateBoostGraph | ( | const HF::SpatialStructures::Graph & | g, |
const std::string & | cost_type = "" |
||
) |
Create a new boost graph from a HF::SpatialStructures:Graph.
g | The graph to create a BoostGraph from |
cost_type | The name of the cost set in graph that will be used to construct this boost graph Leaving this as blank will use the cost type the graph was constructed with. |
cost_type
is specified, and is not an empty string, then cost_type
must be the key of an already created cost in graph
. graph
must be compressed.HF::Exceptions::NoCost | if cost_type was not left blank and no cost type with the key cost_type exists in graph . |
Definition at line 320 of file path_finder.cpp.
Referenced by CalculateDistanceAndPredecessor(), CreateAllToAllPaths(), CreatePath(), and CreatePaths().
std::vector< HF::SpatialStructures::Path > HF::Pathfinding::FindAllPaths | ( | BoostGraph * | bg | ) |
Find a path from every node to every node (NOTE: Not implemented yet.)
bg | Graph to generate all paths for. traversal |
Calculate a permutation for every combination of nodes in the graph, then call FindPaths, OR Write a unique function inspired by FindPaths that just runs through a range of paths.
std::out_of_memory | if the memory required is too large. |
HF::SpatialStructures::Path HF::Pathfinding::FindPath | ( | BoostGraph * | bg, |
int | start_id, | ||
int | end_id | ||
) |
Find a path between points A and B using Dijkstra's Shortest Path algorithm.
bg | The boost graph containing edges/nodes. |
start_id | ID of the starting node. |
end_id | ID of the ending node. |
To find the path, A row of the predecessor matrix is generated for node a, then followed until node B is reached. This algorithm is implemented using dijkstra_shortest_path from the BoostGraphLibrary https://www.boost.org/doc/libs/1_73_0/libs/graph/doc/dijkstra_shortest_paths_no_color_map.html
Definition at line 166 of file path_finder.cpp.
References BuildDistanceAndPredecessor(), ConstructShortestPathFromPred(), and HF::Pathfinding::BoostGraph::g.
Referenced by CreatePath().
std::vector< HF::SpatialStructures::Path > HF::Pathfinding::FindPaths | ( | BoostGraph * | bg, |
const std::vector< int > & | start_points, | ||
const std::vector< int > & | end_points | ||
) |
Find a path from every id in start_ids to the matching end node in end_ids.
bg | The boost graph containing edges/nodes. |
start_points | Ordered list of starting points. |
end_points | Ordered list of ending points. |
More efficient than calling FindPath manually in a loop. Sorts paths by starting point, calculates only one predecessor matrix per unique starting point, then finds a path for every pair.
Definition at line 178 of file path_finder.cpp.
References BuildDistanceAndPredecessor(), ConstructShortestPathFromPred(), and HF::Pathfinding::BoostGraph::g.
DistanceAndPredecessor HF::Pathfinding::GenerateDistanceAndPred | ( | const BoostGraph & | bg | ) |
Generate the distance and predecessor matricies for a specific boost graph.
bg | Boost graph to generate the matricies from |
[0.000000, 10.000000, 5.000000, 10.000000, 0.000000, 15.000000, -1.000000, -1.000000, 0.000000]
[0, 0, 0, 1, 1, 0, -1, -1, 2]
Definition at line 267 of file path_finder.cpp.
References HF::Pathfinding::BoostGraph::g, HF::Pathfinding::DistanceAndPredecessor::GetRowOfDist(), HF::Pathfinding::DistanceAndPredecessor::GetRowOfPred(), HF::Pathfinding::BoostGraph::p, and HF::Pathfinding::Edge_Cost::weight.
Referenced by CalculateDistanceAndPredecessor().
void HF::Pathfinding::InsertAllToAllPathsIntoArray | ( | BoostGraph * | bg, |
HF::SpatialStructures::Path ** | out_paths, | ||
HF::SpatialStructures::PathMember ** | out_path_members, | ||
int * | out_sizes | ||
) |
A special version of FindPaths optimized for the C_Interface, such that all paths possible from each node to every other node are generated.
bg | Boost graph to generate paths in |
out_paths | Location for the the path pointer array to be created. Paths that could not be generated will be left as null pointers. |
out_path_members | Location for the pathmember pointer array will be created. All path member pointers will point to the PathMembers of the Path in paths at the same location. Paths that could not be generated will be left as null pointers. |
out_sizes | Output raw_array of integers that will cntain the length of every path in path_members. Paths that could not be generated will be left with a length of zero. |
Definition at line 329 of file path_finder.cpp.
References InsertPathsIntoArray(), and HF::Pathfinding::BoostGraph::p.
Referenced by CreateAllToAllPaths().
void HF::Pathfinding::InsertPathsIntoArray | ( | const BoostGraph * | bg, |
const std::vector< int > & | start_points, | ||
const std::vector< int > & | end_points, | ||
HF::SpatialStructures::Path ** | out_paths, | ||
HF::SpatialStructures::PathMember ** | out_path_members, | ||
int * | out_sizes | ||
) |
A special version of FindPaths optimized for the C_Interface.
bg | Boost graph to generate paths in |
start_points | An ordered list of start points to generate paths from. |
end_points | An ordered list of end points to generate paths to. |
out_paths | Location for the the path pointer array to be created. Paths that could not be generated will be left as null pointers. |
out_path_members | Location for the pathmember pointer array will be created. All path member pointers will point to the PathMembers of the Path in paths at the same location. Paths that could not be generated will be left as null pointers. |
out_sizes | Output raw_array of integers that will contain the length of every path in path_members. Paths that could not be generated will be left with a length of zero. |
Definition at line 201 of file path_finder.cpp.
References BuildDistanceAndPredecessor(), ConstructShortestPathFromPred(), HF::Pathfinding::BoostGraph::g, HF::SpatialStructures::Path::GetPMPointer(), and HF::SpatialStructures::Path::size().
Referenced by CreatePaths(), and InsertAllToAllPathsIntoArray().