feat: Expose widest paths functions as `widest_paths()` and `widest_path_widths()`
Exposes the C widest paths implementation to R users with two new functions mirroring the existing shortest_paths() and distances() API.
Implementation
-
widest_path_widths()- Returns widest path widths matrix between vertices- Automatic algorithm selection (Dijkstra for sparse graphs, Floyd-Warshall for dense)
- Manual override via
algorithmparameter
-
widest_paths()- Returns actual widest paths- Configurable output: vertex paths, edge paths, or both
- Optional predecessors and inbound edges
Weights Requirement
The C implementation requires edge weights (cannot be NULL). Functions handle this by:
- Auto-using
weightedge attribute when present - Clear error when weights unavailable or
weights = NAspecified
Usage
g <- make_ring(10)
E(g)$weight <- seq_len(ecount(g))
# Calculate widest path widths (like distances())
widest_path_widths(g)
# Get actual widest paths (like shortest_paths())
widest_paths(g, from = 5, to = c(1, 3, 7))
Includes 28 tests covering algorithm selection, directed/undirected graphs, multiple targets, and error cases.
Original prompt
This section details on the original issue you should resolve
<issue_title>Expose widest paths functions</issue_title> <issue_description>Expose widest paths functions as
widest_paths()(mirroringshortest_paths())andwidest_path_widths()(mirroringdistances())There's a problem to solve when doing this: The
weightsparameter of the corresponding C functions is not optional. In R, it must be optional to be able to signify that weights are to be taken from attributes. A proper setup that makes this easy to do is not ready yet.</issue_description>Comments on the Issue (you are @copilot in this section)
- Fixes igraph/rigraph#1566
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
I want to have a careful look at this as I get the time.