nxpp
Header-only graph utilities on top of Boost Graph Library
Loading...
Searching...
No Matches
nxpp::SingleSourceShortestPathResult< NodeID, Distance > Struct Template Reference

Result container for single-source shortest-path routines. More...

#include <shortest_paths.hpp>

Collaboration diagram for nxpp::SingleSourceShortestPathResult< NodeID, Distance >:

Public Member Functions

bool has_path_to (const NodeID &target) const
 Returns true when the target exists in the result and is reachable.
 
std::vector< NodeID > path_to (const NodeID &target) const
 Reconstructs the path from the original source to target.
 

Public Attributes

std::map< NodeID, Distance > distance
 Final shortest-path distance for each node known to the result.
 
std::map< NodeID, NodeID > predecessor
 Predecessor tree keyed by target node ID.
 

Detailed Description

template<typename NodeID, typename Distance = double>
struct nxpp::SingleSourceShortestPathResult< NodeID, Distance >

Result container for single-source shortest-path routines.

Distances and predecessors are materialized eagerly, while concrete source-to-target paths are reconstructed on demand through path_to().

Example:

g.add_edge("A", "B", 1.0);
g.add_edge("B", "C", 2.0);
auto result = g.dijkstra_shortest_paths("A");
auto distance = result.distance.at("C");
auto path = result.path_to("C");
Graph wrapper around Boost Graph Library with Python-inspired helpers.
Definition graph.hpp:272
auto dijkstra_shortest_paths(const NodeID &source_id) const
Returns distances and predecessors for all nodes reachable from a source.
Definition shortest_paths.hpp:446
std::map< NodeID, Distance > distance
Final shortest-path distance for each node known to the result.
Definition shortest_paths.hpp:42

Member Function Documentation

◆ path_to()

template<typename NodeID , typename Distance = double>
std::vector< NodeID > nxpp::SingleSourceShortestPathResult< NodeID, Distance >::path_to ( const NodeID &  target) const
inline

Reconstructs the path from the original source to target.

Parameters
targetTarget node ID.
Returns
A std::vector<NodeID> describing the source-to-target path.
Exceptions
std::runtime_errorIf the target is missing, unreachable, or the predecessor map is inconsistent.

References nxpp::SingleSourceShortestPathResult< NodeID, Distance >::distance, and nxpp::SingleSourceShortestPathResult< NodeID, Distance >::predecessor.


The documentation for this struct was generated from the following file: