-
-
Notifications
You must be signed in to change notification settings - Fork 342
Add Edmonds-Karp Algorithm in R #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new Edmonds–Karp maximum-flow algorithm in R and, additionally, introduces FFT (Cooley–Tukey), Hamiltonian Path (backtracking), and Borůvka’s MST implementations, with accompanying docs and examples.
- Implements edmonds_karp with BFS-based augmenting paths and returns max_flow and residual.
- Adds new algorithms (FFT, Hamiltonian Path, Borůvka) with example code and docs.
- Documentation includes usage and complexity, but some paths reference the wrong directory prefix and examples run unconditionally in code.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| graph_algorithms/edmonds_karp.r | Adds Edmonds–Karp max-flow with BFS and an example; core of the PR. |
| mathematics/fast_fourier_transform.r | Adds recursive Cooley–Tukey FFT with zero-padding and an interactive example. |
| graph_algorithms/hamiltonian_path.r | Adds Hamiltonian Path (backtracking) with example; includes function definitions and execution. |
| graph_algorithms/boruvka_mst.r | Adds Borůvka’s MST implementation with union-find and printed output. |
| documentation/fast_fourier_transform.md | Documents FFT usage/complexity; some path prefixes inconsistent. |
| documentation/hamiltonian_path.md | Documents Hamiltonian Path; includes path prefix inconsistencies. |
| documentation/boruvka_mst.md | Documents Borůvka MST; includes a wrong path prefix. |
Comments suppressed due to low confidence (15)
graph_algorithms/hamiltonian_path.r:1
- The recursion returns only TRUE/FALSE, so the filled path from deeper frames is not propagated back to hamiltonianPath; the printed path will remain largely unchanged (with -1s). Return the path from hamiltonianUtil (e.g., list(found, path)) and capture it in hamiltonianPath, or use superassignment/closure to store the final path.
# Hamiltonian Path (Backtracking)
graph_algorithms/edmonds_karp.r:1
- [nitpick] The example code auto-runs and shadows base functions source() and sink(); this can break subsequent calls in a user session. Gate the example with if (interactive()) and rename these variables (e.g., s <- 1L, t <- 6L) to avoid masking base functions.
# Edmonds-Karp Maximum Flow (Ford-Fulkerson with BFS)
graph_algorithms/boruvka_mst.r:1
- [nitpick] Prefer returning a value without printing from within the algorithm; let callers decide how to handle messages. Consider returning a status field instead of cat(), or guarding output with a verbose flag.
# Boruvka's Minimum Spanning Tree (MST) — improved R translation
graph_algorithms/hamiltonian_path.r:1
- Function names use camelCase (isSafe, hamiltonianUtil), while repository conventions prefer snake_case or dot-separated names. Please rename to is_safe and hamiltonian_util to align with project style.
# Hamiltonian Path (Backtracking)
graph_algorithms/hamiltonian_path.r:1
- Rename hamiltonianPath to hamiltonian_path to follow repository naming conventions for functions.
# Hamiltonian Path (Backtracking)
graph_algorithms/hamiltonian_path.r:1
- [nitpick] Example code executes unconditionally on source, producing side effects during import. Wrap this block with if (interactive()) { ... } or move it to a separate example/test file.
# Hamiltonian Path (Backtracking)
graph_algorithms/hamiltonian_path.r:1
- Adjust path reference to match the actual repository structure; it should be graph_algorithms (without the leading R/).
# Hamiltonian Path (Backtracking)
mathematics/fast_fourier_transform.r:1
- The path prefix 'R/' does not match the file location; update to source('mathematics/fast_fourier_transform.r') or provide a project-root-relative path consistent with other docs.
# Fast Fourier Transform (Cooley-Tukey recursive implementation)
documentation/hamiltonian_path.md:1
- Update the path reference to graph_algorithms/hamiltonian_path.r (remove the leading R/), consistent with the repository structure.
# Hamiltonian Path (Backtracking)
documentation/hamiltonian_path.md:1
- Correct the sourcing path to match the actual location, e.g., Rscript -e "source('graph_algorithms/hamiltonian_path.r')".
# Hamiltonian Path (Backtracking)
documentation/fast_fourier_transform.md:1
- Fix the path to mathematics/fast_fourier_transform.r (remove the leading R/).
# Fast Fourier Transform (FFT)
documentation/fast_fourier_transform.md:1
- Update the command to source('mathematics/fast_fourier_transform.r') to reflect the actual path.
# Fast Fourier Transform (FFT)
documentation/boruvka_mst.md:1
- Correct the path to graph_algorithms/boruvka_mst.r (remove 'R/').
# Boruvka's Minimum Spanning Tree (MST)
graph_algorithms/edmonds_karp.r:1
- Please update DIRECTORY.md to list the new algorithms (edmonds_karp, fast_fourier_transform, hamiltonian_path, boruvka_mst) under their respective sections, per repository contribution guidelines.
# Edmonds-Karp Maximum Flow (Ford-Fulkerson with BFS)
graph_algorithms/edmonds_karp.r:1
- Add basic tests to validate the new algorithm (e.g., assert max flow = 23 on the provided 6-node example, and verify residual capacity properties). The repository guidelines recommend including tests or a test file demonstrating correctness.
# Edmonds-Karp Maximum Flow (Ford-Fulkerson with BFS)
| @@ -0,0 +1,26 @@ | |||
| # Boruvka's Minimum Spanning Tree (MST) | |||
|
|
|||
| This document describes the Boruvka MST implementation located at `R/graph_algorithms/boruvka_mst.r`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't add documentation separately from the code, please remove those files
Overview
The
edmonds_karpfunction finds the maximum flow in a directed network by repeatedly searching for augmenting paths using Breadth-First Search (BFS).At each iteration, it augments the flow along the shortest available path in terms of edge count, ensuring predictable and polynomial runtime.
This implementation follows the repository style conventions:
Features
max_flow— total maximum flow valueresidual— resulting residual capacity matrixComplexity
Demonstration
Run the following example in an R session to test the algorithm: