Compute edge-level detour costs and vulnerability ratios for a graph.
Arguments
- graph_df
A data.frame with columns
fromandto, and optionally a cost column. Each row represents one physical edge.- directed
Logical (default:
FALSE). Whether to treat the graph as directed. For undirected graphs, each edge can be traversed in both directions, but the returned result remains aligned with the original rows ofgraph_df.- cost.column
Character string (default:
"cost") or numeric vector. Name of the cost column ingraph_df, or a numeric vector of edge costs with length equal tonrow(graph_df).- nthreads
Integer (default:
1L). Number of OpenMP threads used to parallelize the per-source Dijkstra computations. Has no effect when the package was compiled without OpenMP support.
Value
A data.frame with one row per input edge and columns:
edge- Edge identifier (index of the edge ingraph_df)from- Original from-node IDto- Original to-node IDedge_cost- Cost of traversing the edgedetour_cost- Shortest path cost between the edge endpoints after removing the edgedetour_ratio-detour_cost / edge_cost
Details
The detour cost for edge e = (u, v) is the shortest path cost from u
to v after removing that physical edge row. Parallel edges are kept as distinct
alternatives. If no detour exists, detour_cost and detour_ratio are Inf.
The implementation uses a compiled multi-label Dijkstra routine, run once per unique
from node. For each target node, it tracks the two best distances whose first
physical edge differs, which yields the best endpoint detour for every outgoing edge of
that source without repeated graph deletion. Per-source Dijkstras are independent and
are parallelized across nthreads OpenMP threads.
