DHART
Loading...
Searching...
No Matches
HF::SpatialStructures::CostAlgorithms Namespace Reference

Functions

double to_radians (double degrees)
 
double to_degrees (double radians)
 
double CalculateSlope (Node &parent, Node &child)
 
EdgeSet CalculateEnergyExpenditure (const Subgraph &sg)
 
std::vector< EdgeSetCalculateEnergyExpenditure (const Graph &g)
 
std::vector< IntEdgeCalculateCrossSlope (const Subgraph &sg)
 
std::vector< std::vector< IntEdge > > CalculateCrossSlope (const Graph &g)
 
template<size_t dimension, typename float_precision = float>
float_precision euclidean_distance (float_precision point_a[], float_precision point_b[])
 
template<size_t dimension, typename float_precision = float>
float_precision dot_product (float_precision vec_U[], float_precision vec_V[])
 
template<size_t dimension, typename float_precision = float>
bool is_perpendicular (float_precision vec_U[], float_precision vec_V[])
 
template<size_t dimension, typename float_precision = float>
std::vector< EdgeGetPerpendicularEdges (const Subgraph &sg, const Node &child_node_a)
 

Function Documentation

◆ CalculateCrossSlope() [1/2]

std::vector< std::vector< IntEdge > > HF::SpatialStructures::CostAlgorithms::CalculateCrossSlope ( const Graph g)

\summary Calculates cross slope for all subgraphs in Graph g

Parameters
gThe Graph to calculate cross slopes with
Returns
A container of vector<IntEdge>, ordered by parent node ID
// for brevity
// Create 7 nodes
Node n0(0, 0, 0);
Node n1(1, 3, 5);
Node n2(3, -1, 2);
Node n3(1, 2, 1);
Node n4(4, 5, 7);
Node n5(5, 3, 2);
Node n6(-2, -5, 1);
// Adding 9 edges
g.addEdge(n0, n1);
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n1, n4);
g.addEdge(n2, n4);
g.addEdge(n3, n5);
g.addEdge(n5, n6);
g.addEdge(n4, n6);
// Always compress the graph after adding edges!
// Get a container of vector<IntEdge>, ordered by parent ID.
// These consist of alternate edge costs for all subgraphs in g.
std::vector<std::vector<IntEdge>> all_edge_costs = CalculateCrossSlope(g);
std::vector< IntEdge > CalculateCrossSlope(const Subgraph &sg)
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Definition: graph.h:486
void addEdge(const Node &parent, const Node &child, float score=1.0f, const std::string &cost_type="")
Add a new edge to the graph from parent to child.
void Compress()
Compress the graph to a CSR and enable the usage of several functions.
A point in space with an ID.
Definition: node.h:38

Definition at line 283 of file cost_algorithms.cpp.

References CalculateCrossSlope(), HF::SpatialStructures::Graph::GetSubgraph(), and HF::SpatialStructures::Graph::Nodes().

+ Here is the call graph for this function:

◆ CalculateCrossSlope() [2/2]

std::vector< IntEdge > HF::SpatialStructures::CostAlgorithms::CalculateCrossSlope ( const Subgraph sg)

\summary Calculates cross slope for this subgraph (a parent node and all edges by this parent)

Parameters
sgA Subgraph type, which consists of a Node (parent node) and a std::vector<Edge> (all edges by this parent)
Returns
A container of IntEdge
// for brevity
// Create 7 nodes
Node n0(2, 6, 6);
Node n1(0, 0, 0);
Node n2(-5, 5, 4);
Node n3(-1, 1, 1);
Node n4(2, 2, 2);
Node n5(5, 3, 2);
Node n6(-2, -5, 1);
// Adding 9 edges
g.addEdge(n0, n1); // [ -2, -6, -6 ]
g.addEdge(n1, n2); // [ -5, 5, 4 ]
g.addEdge(n1, n3); // [ -1, 1, 1 ]
g.addEdge(n1, n4); // [ 2, 2, 2 ]
g.addEdge(n2, n4); // [ -9, -3, -2 ]
g.addEdge(n3, n5); // [ -6, 2, 1 ]
g.addEdge(n5, n6); // [ -7, -8, -1 ]
g.addEdge(n4, n6); // [ -6, -7, -1 ]
// Always compress the graph after adding edges!
// Retrieve a subgraph of your choice, provide a parent node or parent node ID.
Subgraph sg = g.GetSubgraph(n1);
// Get a container of vector<IntEdge>, ordered by parent ID.
// These consist of alternate edge costs for Subgraph sg.
std::vector<IntEdge> edge_costs = CalculateCrossSlope(sg);
A Subgraph consists of a parent Node m_parent and a container of Edge m_edges such that all Edge in m...
Definition: graph.h:364
Subgraph GetSubgraph(const Node &parent_node, const std::string &cost_type="") const
Retrieves a Subgraph using a Node.

Definition at line 189 of file cost_algorithms.cpp.

References HF::SpatialStructures::Node::id, HF::SpatialStructures::Subgraph::m_edges, HF::SpatialStructures::Subgraph::m_parent, and HF::SpatialStructures::Node::z.

Referenced by CalculateAndStoreCrossSlope(), and CalculateCrossSlope().

+ Here is the caller graph for this function:

◆ CalculateEnergyExpenditure() [1/2]

std::vector< EdgeSet > HF::SpatialStructures::CostAlgorithms::CalculateEnergyExpenditure ( const Graph g)

\summary Calculates energy expenditure for all subgraphs in Graph g

Parameters
gThe graph to calculate energy expenditures with
Returns
A container of vector<EdgeSet>, ordered by parent node ID
// for brevity
// Create 7 nodes
Node n0(0, 0, 0);
Node n1(1, 3, 5);
Node n2(3, -1, 2);
Node n3(1, 2, 1);
Node n4(4, 5, 7);
Node n5(5, 3, 2);
Node n6(-2, -5, 1);
// Adding 9 edges
g.addEdge(n0, n1);
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n1, n4);
g.addEdge(n2, n4);
g.addEdge(n3, n5);
g.addEdge(n5, n6);
g.addEdge(n4, n6);
// Always compress the graph after adding edges!
// Get a container of vector<EdgeSet>, ordered by parent ID.
// These consist of alternate edge costs for all subgraphs in g.
std::vector<std::vector<EdgeSet>> all_edge_costs = CalculateEnergyExpenditure(g);
EdgeSet CalculateEnergyExpenditure(const Subgraph &sg)

Definition at line 162 of file cost_algorithms.cpp.

References CalculateEnergyExpenditure(), HF::SpatialStructures::Graph::GetSubgraph(), and HF::SpatialStructures::Graph::Nodes().

+ Here is the call graph for this function:

◆ CalculateEnergyExpenditure() [2/2]

EdgeSet HF::SpatialStructures::CostAlgorithms::CalculateEnergyExpenditure ( const Subgraph sg)

\summary Calculate energy expenditure for this subgraph (a parent node and all edges by this parent)

Parameters
sgA subgraph type which consists of a Node (parent node) and a std::vector<Edge> (all edges by this parent)
Returns
A container of EdgeSet
// For brevity
// Create 7 nodes
Node n0(0, 0, 0);
Node n1(1, 3, 5);
Node n2(3, -1, 2);
Node n3(1, 2, 1);
Node n4(4, 5, 7);
Node n5(5, 3, 2);
Node n6(-2, -5, 1);
// Adding 9 edges
g.addEdge(n0, n1);
g.addEdge(n1, n2);
g.addEdge(n1, n3);
g.addEdge(n1, n4);
g.addEdge(n2, n4);
g.addEdge(n3, n5);
g.addEdge(n5, n6);
g.addEdge(n4, n6);
// Always compress the graph after adding edges!
// Retrieve a subgraph of your choice, provide a parent node or parent node ID.
Subgraph sg = g.GetSubgraph(n1);
// Get a container of vector<EdgeSet>, ordered by parent ID.
// These consist of alternate edge costs for Subgraph sg.
std::vector<EdgeSet> edge_costs = CalculateEnergyExpenditure(sg);

Definition at line 96 of file cost_algorithms.cpp.

References CalculateSlope(), HF::SpatialStructures::IntEdge::child, HF::SpatialStructures::Node::directionTo(), HF::SpatialStructures::Node::distanceTo(), HF::SpatialStructures::Node::id, HF::SpatialStructures::Subgraph::m_edges, HF::SpatialStructures::Subgraph::m_parent, and to_radians().

Referenced by CalculateAndStoreEnergyExpenditure(), and CalculateEnergyExpenditure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalculateSlope()

double HF::SpatialStructures::CostAlgorithms::CalculateSlope ( Node parent,
Node child 
)

Definition at line 34 of file cost_algorithms.cpp.

References to_degrees().

Referenced by CalculateEnergyExpenditure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dot_product()

template<size_t dimension, typename float_precision = float>
float_precision HF::SpatialStructures::CostAlgorithms::dot_product ( float_precision  vec_U[],
float_precision  vec_V[] 
)

\summary Determines the dot product of vec_U and vec_V (vectors, as components)

Template Parameters
dimensionof a real coordinate space R^n, where n is dimension, an integral value (i.e. R^2 is 2D, R^3 is 3D)
float_precisiona floating-point data type, i.e. float, double, long double, etc.
Parameters
vec_UThe components of vector U
vec_VThe components of vector V
Returns
The dot product of vec_U and vec_V, by the specified dimension
// Requires #include "cost_algorithms.h"
// for brevity
// components of a 2D vector, { v_x, v_y }
float vec_u[] = { 4, 0 };
float vec_v[] = { 0, 4 };
// There are two template parameters for dot_product:
// - dimension (2 for 2D, 3 for 3D, etc)
// - float_precision (defaults to float if unspecified)
float dot_prod = dot_product<2>(vec_u, vec_v); // 0.00000
// vec_u and vec_v are perpendicular.
float_precision dot_product(float_precision vec_U[], float_precision vec_V[])

Definition at line 132 of file cost_algorithms.h.

◆ euclidean_distance()

template<size_t dimension, typename float_precision = float>
float_precision HF::SpatialStructures::CostAlgorithms::euclidean_distance ( float_precision  point_a[],
float_precision  point_b[] 
)

\summary Determines the distance between two points, point_a and point_b

Template Parameters
dimensionof a real coordinate space R^n, where n is dimension, an integral value (i.e. R^2 is 2D, R^3 is 3D)
float_precisiona floating-point data type, i.e. float, double, long double, etc.
Parameters
point_aThe starting point of a line segment
point_bThe ending point of a line segment
Returns
The euclidean distance from point_a to point_b, by the specified dimension
// Requires #include "cost_algorithms.h"
// for brevity;
// 2D coordinates, { x, y }
float pos_a[] = { 0, 0 };
float pos_b[] = { 4, 3 };
// There are two template parameters for euclidean_distance:
// - dimension (2 for 2D, 3 for 3D, etc)
// - float_precision (defaults to float if unspecified)
float distance = euclidean_distance<2>(pos_a, pos_b); // 5.00000
float_precision euclidean_distance(float_precision point_a[], float_precision point_b[])

Definition at line 94 of file cost_algorithms.h.

◆ GetPerpendicularEdges()

template<size_t dimension, typename float_precision = float>
std::vector< Edge > HF::SpatialStructures::CostAlgorithms::GetPerpendicularEdges ( const Subgraph sg,
const Node child_node_a 
)

\summary Obtains a container of Edge that are perpendicular to the vector formed by parent_node and child_node_a

Parameters
sgA Subgraph that consists of a parent node and a container of Edges by that parent node \paramchild_node_a The child node that forms a vector (edge) with parent_node, that will be compared with all Edge in edges
Returns
A container of Edge that were found to be perpendicular to the edge formed by parent_node and child_node_a
// Requires #include "cost_algorithms.h"
// for brevity
// Create 7 nodes
Node n0(2, 6, 6);
Node n1(0, 0, 0);
Node n2(-5, 5, 4);
Node n3(-1, 1, 1);
Node n4(2, 2, 2);
Node n5(5, 3, 2);
Node n6(-2, -5, 1);
// Adding 9 edges
g.addEdge(n0, n1); // [ -2, -6, -6 ]
g.addEdge(n1, n2); // [ -5, 5, 4 ]
g.addEdge(n1, n3); // [ -1, 1, 1 ]
g.addEdge(n1, n4); // [ 2, 2, 2 ]
g.addEdge(n2, n4); // [ -9, -3, -2 ]
g.addEdge(n3, n5); // [ -6, 2, 1 ]
g.addEdge(n5, n6); // [ -7, -8, -1 ]
g.addEdge(n4, n6); // [ -6, -7, -1 ]
// Always compress the graph after adding edges!
// We will find all edges in g that are perpendicular to the edge (vector)
// formed by n1 and n4 -- they will be stored in perp_edges.
// Note that we have specifically chosen to check for 2D perpendicularity,
// as seen by the template parameter, despite these nodes being 3D.
auto perp_edges = GetPerpendicularEdges<2>(g.GetSubgraph(n1), n4);
// The edge formed by n1 and n4 is perpendicular to
// - the edge formed by n1 and n2
// - the edge formed by n1 and n3
std::vector< Edge > GetPerpendicularEdges(const Subgraph &sg, const Node &child_node_a)

Definition at line 231 of file cost_algorithms.h.

References HF::SpatialStructures::Node::directionTo(), HF::SpatialStructures::Subgraph::m_edges, and HF::SpatialStructures::Subgraph::m_parent.

+ Here is the call graph for this function:

◆ is_perpendicular()

template<size_t dimension, typename float_precision = float>
bool HF::SpatialStructures::CostAlgorithms::is_perpendicular ( float_precision  vec_U[],
float_precision  vec_V[] 
)

\summary Determines if vec_U and vec_V (vectors, as components) are perpendicular, or not

Template Parameters
dimensionof a real coordinate space R^n, where n is dimension, an integral value (i.e. R^2 is 2D, R^3 is 3D)
float_precisiona floating-point data type, i.e. float, double, long double, etc.
Parameters
vec_UThe components of vector U
vec_VThe components of vector V
Returns
True, if vec_U and vec_V have a dot product close to 0, false otherwise
// Requires #include "cost_algorithms.h"
// for brevity
// components of a 2D vector, { v_x, v_y }
float vec_u[] = { 4, 0 };
float vec_v[] = { 0, 4 };
// There are two template parameters for is_perpendicular:
// - dimension (2 for 2D, 3 for 3D, etc)
// - float_precision (defaults to float if unspecified)
bool is_perp = is_perpendicular<2>(vec_u, vec_v); // true
// vec_u and vec_v are perpendicular.
bool is_perpendicular(float_precision vec_U[], float_precision vec_V[])

Definition at line 169 of file cost_algorithms.h.

References HF::SpatialStructures::ROUNDING_PRECISION.

◆ to_degrees()

double HF::SpatialStructures::CostAlgorithms::to_degrees ( double  radians)

\summary Converts floating-point value radians into an equivalent value in degrees

Parameters
radiansThe value (in radians) to convert into degrees
Returns
The value, radians, in degrees
// Requires #include "cost_algorithms.h"
// for brevity
// The macro M_PI requires
// #define _USE_MATH_DEFINES
// #include <cmath>
//
// Use M_PI in place of approximate_pi when the value pi is needed.
double approximate_pi = 3.14159;
double in_radians = 2 * approximate_pi;
double in_degrees = to_degrees(in_radians);
// 359.99969592100859, about 360.0 degrees

Definition at line 30 of file cost_algorithms.cpp.

Referenced by CalculateSlope().

+ Here is the caller graph for this function:

◆ to_radians()

double HF::SpatialStructures::CostAlgorithms::to_radians ( double  degrees)

\summary Converts floating-point value degrees into an equivalent value in radians

Parameters
degreesThe value (in degrees) to convert into radians
Returns
The value, degrees, in radians
// Requires #include "cost_algorithms.h"
// for brevity
double in_degrees = 360.0;
double in_radians = to_radians(in_degrees); // 6.2831853.., about 2 * M_PI

Definition at line 26 of file cost_algorithms.cpp.

Referenced by CalculateEnergyExpenditure().

+ Here is the caller graph for this function: