-
-
Notifications
You must be signed in to change notification settings - Fork 342
Add -Dinic’s Algorithm #249
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
The head ref may contain hidden characters: "Add-Dinic\u2019s-Algo"
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
This PR adds a comprehensive implementation of Dinic's Algorithm for computing maximum flow in directed networks. The algorithm uses level graphs (BFS) and blocking flows (DFS) to efficiently find the maximum flow from a source to a sink vertex, offering better performance than classical Ford-Fulkerson approaches.
Key changes:
- Complete Dinic's Algorithm implementation with BFS level graph construction and DFS blocking flow computation
- Support for flow network creation, edge addition, and flow visualization functions
- Four comprehensive examples demonstrating different use cases (basic networks, bipartite matching, multi-source/multi-sink)
|
@siriak please have a look |
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
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
| create_flow_network <- function(n) { | ||
| # Use environment to allow in-place (by-reference) mutation without superassignment | ||
| env <- new.env(parent = emptyenv()) | ||
| env$n <- n | ||
| env$graph <- vector("list", n) # Adjacency list | ||
| env$capacity <- matrix(0, nrow = n, ncol = n) # Capacity matrix | ||
| env$flow <- matrix(0, nrow = n, ncol = n) # Flow matrix | ||
| return(env) | ||
| } |
Copilot
AI
Oct 24, 2025
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.
The function documentation uses an incorrect documentation format. R function documentation should use proper roxygen2 syntax with @param tags, not @param: with colons. The return value should be documented with @return without a colon. Similarly for other functions throughout the file.
| # ========== Example 1: Basic 6-Vertex Network ========== | ||
|
|
||
| cat("========== Example 1: Basic 6-Vertex Flow Network ==========\n\n") |
Copilot
AI
Oct 24, 2025
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.
The file contains executable example code at the module level (lines 251-398). According to repository guidelines, examples should be included as commented code within the script, not as executable statements that run when the file is sourced. Consider commenting out or removing the executable examples or moving them to a separate example/demo file.
PR: Dinic's Algorithm for Maximum Flow
This PR provides a comprehensive R implementation of Dinic's Algorithm, a highly efficient algorithm to compute the maximum flow in a flow network. The algorithm leverages level graphs and blocking flows to improve performance over classical methods like Ford-Fulkerson.
Overview
Dinic's Algorithm operates in two main phases iteratively:
Level Graph Construction (BFS):
Blocking Flow Computation (DFS):
These steps are repeated until no augmenting path exists from the source to the sink. The approach ensures efficient convergence and allows multiple flows per BFS iteration.
Features
Complexity
Applications
Demonstration
Example 1: Basic 6-Vertex Network