Graph
- Breadth-first search (unweighted shortest path)
- Dijkstra’s algorithm (weighted shortest path)
- A* search (heuristic-guided pathfinding)
Parameters
-
IdVertex identifier type (must be hashable) -
IdHashHash function for Id type (default: std::hash<Id>)
Public Methods
add_edge
inline
Parameters
-
fromSource vertex -
toDestination vertex -
wEdge weight (default: 1.0)
Example:
bfs
const
Parameters
startStarting vertex
Returns
Vector of visited vertices in BFS order Returns empty vector if start not in graph :::note Does not consider edge weights (treats all as weight 1) :::dijkstra
const
Parameters
-
startStarting vertex -
endDestination vertex
Returns
PathResult if path exists, std::nullopt otherwise On success, path contains vertices from start to end cost equals sum of edge weights along path :::note Time complexity: O((V + E) log V) ::: :::note Edge weights must be non-negative :::Example:
astar
const
Parameters
-
startStarting vertex -
endDestination vertex -
hHeuristic function: estimated cost from node to goal Must be admissible (never overestimate)