Skip to content

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

Draft
Copilot wants to merge 9 commits intomainfrom
copilot/expose-widest-paths-functions
Draft

feat: Expose widest paths functions as widest_paths() and widest_path_widths()#2408
Copilot wants to merge 9 commits intomainfrom
copilot/expose-widest-paths-functions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 26, 2025

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)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits October 26, 2025 10:55
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Co-authored-by: krlmlr <1741643+krlmlr@users.noreply.github.com>
Copilot AI changed the title [WIP] Expose widest paths functions as optional feat: Expose widest paths functions as widest_paths() and widest_path_widths() Oct 26, 2025
Copilot AI requested a review from krlmlr October 26, 2025 11:13
Comment thread R/paths.R Outdated
@krlmlr krlmlr requested a review from szhorvat October 26, 2025 11:14
@krlmlr krlmlr removed their assignment Oct 26, 2025
@szhorvat
Copy link
Copy Markdown
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose widest paths functions

3 participants