DHART
Loading...
Searching...
No Matches
HF::Pathfinding::BoostGraph Class Reference

A graph usable with the BoostGraphLibrary. More...

#include <boost_graph.h>

+ Collaboration diagram for HF::Pathfinding::BoostGraph:

Public Member Functions

 BoostGraph (const HF::SpatialStructures::Graph &graph, const std::string &cost_type="")
 Create a boost graph from a HF::SpatialStructures::Graph. More...
 
 ~BoostGraph ()
 Explicit Destructor required for BoostGraphDeleter to work in path_finder.h. More...
 

Public Attributes

graph_t g
 The underlying graph in boost. More...
 
std::vector< vertex_descriptorp
 Vertex array preallocated to the number of nodes in the graph. More...
 
std::vector< doubled
 Distance array preallocated to the number of nodes in the graph. More...
 

Detailed Description

A graph usable with the BoostGraphLibrary.

Contains a CSR in boost created from a graph in DHARTAPI. This is necessary for using any of the BoostGraphLibrary functions.

Invariant
This class will always carry a valid boost graph.
Remarks
None of the memebers of this class should need to be modified after the class is created. This is intended to be a pseudo-wrapper to make the HF::SpatialStructures::Graph usable with boost. You can read more about the boost graph libary in the official boost documentation: https://www.boost.org/doc/libs/1_73_0/libs/graph/doc/quick_tour.html Boost's graphs can be difficult to use due to the extensive use of templates. This limits their usage outside of the HF::Pathfinder, so there aren't any functions to interact with the boost graph after creation.
See also
HF::SpatialStructures::Graph for a graph that's better supported in DHARTAPI.
graph_t for info about the graph in boost this class holds.

Definition at line 166 of file boost_graph.h.

Constructor & Destructor Documentation

◆ BoostGraph()

HF::Pathfinding::BoostGraph::BoostGraph ( const HF::SpatialStructures::Graph graph,
const std::string &  cost_type = "" 
)

Create a boost graph from a HF::SpatialStructures::Graph.

Parameters
graphGraph to create a graph in boost from.
cost_typeThe 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.

Every edge and node in the graph is used to create a graph in Boost. This will also allocate space equal to the number of nodes in g for this class's p and d arrays for use in FindPath as an optimization.

Precondition
1) If cost_type is specified, and is not an empty string, then cost_type must be the key of an already created cost in graph.
2) graph must be compressed.
Exceptions
HF::Exceptions::NoCostif cost_type was not left blank and no cost type with the key cost_type exists in graph.
// be sure to #include "boost_graph.h", #include "node.h", #include "graph.h",
// and #include <vector>
// In order to create a BoostGraph, we must first create a Graph instance first.
// We must prepare the nodes, their edges, and the weights (distances) of each edge.
// Create the nodes
HF::SpatialStructures::Node node_0(1.0f, 1.0f, 2.0f);
HF::SpatialStructures::Node node_1(2.0f, 3.0f, 4.0f, 5);
HF::SpatialStructures::Node node_2(11.0f, 22.0f, 140.0f);
// Create a container (vector) of nodes
std::vector<HF::SpatialStructures::Node> nodes = { node_0, node_1, node_2 };
// Create matrices for edges and distances, edges.size() == distances().size()
std::vector<std::vector<int>> edges = { { 1, 2 }, { 2 }, { 1 } };
std::vector<std::vector<float>> distances = { { 1.0f, 2.5f }, { 54.0f }, { 39.0f } };
// Now you can create a Graph - note that nodes, edges, and distances are passed
// by reference
HF::SpatialStructures::Graph graph(edges, distances, nodes);
// Passing Graph graph to BoostGraph bg, by reference
A graph usable with the BoostGraphLibrary.
Definition: boost_graph.h:166
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Definition: graph.h:486
A point in space with an ID.
Definition: node.h:38

Definition at line 23 of file boost_graph.cpp.

References d, g, HF::SpatialStructures::Graph::GetEdges(), HF::SpatialStructures::Graph::MaxID(), p, HF::SpatialStructures::Graph::size(), and HF::Pathfinding::Edge_Cost::weight.

+ Here is the call graph for this function:

◆ ~BoostGraph()

HF::Pathfinding::BoostGraph::~BoostGraph ( )
default

Explicit Destructor required for BoostGraphDeleter to work in path_finder.h.

Calls the default destruction behavior.

Warning
Do not modify this function! This class is still using the default destructor, but unique pointer requires the destructor to be declared.
// be sure to #include "boost_graph.h", #include "node.h", #include "graph.h",
// and #include <vector>
// In order to create a BoostGraph, we must first create a Graph instance first.
// We must prepare the nodes, their edges, and the weights (distances) of each edge.
// Create the nodes
HF::SpatialStructures::Node node_0(1.0f, 1.0f, 2.0f);
HF::SpatialStructures::Node node_1(2.0f, 3.0f, 4.0f, 5);
HF::SpatialStructures::Node node_2(11.0f, 22.0f, 140.0f);
// Create a container (vector) of nodes
std::vector<HF::SpatialStructures::Node> nodes = { node_0, node_1, node_2 };
// Create matrices for edges and distances, edges.size() == distances().size()
std::vector<std::vector<int>> edges = { { 1, 2 }, { 2 }, { 1 } };
std::vector<std::vector<float>> distances = { { 1.0f, 2.5f }, { 54.0f }, { 39.0f } };
// Now you can create a Graph - note that nodes, edges, and distances are passed
// by reference
HF::SpatialStructures::Graph graph(edges, distances, nodes);
// Begin scope
{
// Create a BoostGraph bg, from a Graph graph (passing g by reference)
}
// End scope
// When bg goes out of scope, BoostGraph::~BoostGraph is called An explicit call
// to BoostGraph::~BoostGraph is also made when invoking operator delete on a
// (BoostGraph *)

Member Data Documentation

◆ d

std::vector<double> HF::Pathfinding::BoostGraph::d

Distance array preallocated to the number of nodes in the graph.

Definition at line 170 of file boost_graph.h.

Referenced by BoostGraph().

◆ g

graph_t HF::Pathfinding::BoostGraph::g

◆ p

std::vector<vertex_descriptor> HF::Pathfinding::BoostGraph::p

Vertex array preallocated to the number of nodes in the graph.

Definition at line 169 of file boost_graph.h.

Referenced by BoostGraph(), HF::Pathfinding::GenerateDistanceAndPred(), and HF::Pathfinding::InsertAllToAllPathsIntoArray().


The documentation for this class was generated from the following files: