rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

feat: Expose widest paths functions as `widest_paths()` and `widest_path_widths()`

Open Copilot opened this issue 4 months ago • 1 comments

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 algorithm parameter
  • 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 weight edge attribute when present
  • Clear error when weights unavailable or weights = NA specified

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() (mirroring shortest_paths())and widest_path_widths() (mirroring distances())

There's a problem to solve when doing this: The weights parameter 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.

Copilot avatar Oct 26 '25 10:10 Copilot

I want to have a careful look at this as I get the time.

szhorvat avatar Oct 28 '25 21:10 szhorvat