-
Notifications
You must be signed in to change notification settings - Fork 61
Implementing DigraphEdgeConnectivity #884
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
Open
RheyaM
wants to merge
15
commits into
digraphs:main
Choose a base branch
from
RheyaM:EdgeConnectivity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
571435b
Added SwapDigraphs and DigraphsRemoveAllEdges functions
rm387 d2fe700
Fixed gaplint errors
rm387 c32aca6
Changes made to SwapDigraphs and DigraphRemoveAllEdges
rm387 f1ac56e
Changes made to DigraphRemoveAllEdges
rm387 c6dabf9
More changes made to DigraphRemoveAllEdges
rm387 c498734
DigraphEdgeConnectivity and additional functions (Dominating Set func…
rm387 0634eed
Added explanations for each Algorithm and edited gapdocs + tests for …
rm387 7719d52
Minor gaplint/test changes made
rm387 c0e4068
Added DigraphEdgeConnectivityDS tests to weights.tst
rm387 4f36fde
Added tests for DigraphDominatingSet()
rm387 f15c6ea
Fixes made to Spanning Tree Algorithm + tests added to weights.tst
rm387 462d1a0
Tests added to testinstall.tst for DigraphEdgeConnectivityDS()
rm387 9238e88
Removing Spanning Tree Algorithm
rm387 d3b581f
Documentation changes + some DigraphsDominatingSet implementation cha…
rm387 cfb696c
Removing DigraphsOutNeighbourhood
rm387 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -772,6 +772,92 @@ function(D, start, destination) | |
| return flows; | ||
| end); | ||
|
|
||
| ############################################################################# | ||
| # Digraph Edge Connectivity | ||
| ############################################################################# | ||
|
|
||
| # Algorithms constructed off the algorithms detailed in: | ||
| # https://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf | ||
| # Each Algorithm uses a different method to decrease the time complexity, | ||
| # of calculating Edge Connectivity, though all make use of DigraphMaximumFlow() | ||
| # due to the Max-Flow, Min-Cut Theorem | ||
|
|
||
| # Algorithm 1: Calculating the Maximum Flow of every possible source and sink | ||
| # Algorithm 2: Calculating the Maximum Flow to all sinks of an arbitrary source | ||
| # Algorithm 3: Finding Maximum Flow within the non-leaves of a Spanning Tree | ||
| # Algorithm 4: Constructing a spanning tree with a high number of leaves | ||
| # Algorithm 5: Using the spanning tree^ to find Maximum Flow within non-leaves | ||
| # Algorithm 6: Finding Maximum Flow within a dominating set of the digraph | ||
| # Algorithm 7: Constructing a dominating set for use in Algorithm 6 | ||
|
|
||
| # Algorithms 4-7 are used below: | ||
|
|
||
| # Digraph EdgeConnectivity calculated with Dominating Sets (Algorithm 6-7) | ||
| InstallMethod(DigraphEdgeConnectivity, "for a digraph", | ||
| [IsDigraph], | ||
| function(digraph) | ||
| # Form an identical but edge weighted digraph with all edge weights as 1: | ||
| local weights, i, u, v, w, neighbourhood, EdgeD, | ||
| maxFlow, min, sum, a, b, V, added, st, non_leaf, max, | ||
| notAddedNeighbours, notadded, NextVertex, NeighboursV, | ||
| neighbour, Edges, D, VerticesLeft, VerticesED; | ||
|
|
||
| if DigraphNrVertices(digraph) = 1 or | ||
| DigraphNrStronglyConnectedComponents(digraph) > 1 then | ||
| return 0; | ||
| fi; | ||
|
|
||
| weights := List([1 .. DigraphNrVertices(digraph)], | ||
| x -> List([1 .. Length(OutNeighbours(digraph)[x])], | ||
| y -> 1)); | ||
| EdgeD := EdgeWeightedDigraph(digraph, weights); | ||
|
|
||
| min := -1; | ||
|
|
||
| # Algorithm 7: Creating a dominating set of the digraph | ||
| D := DigraphDominatingSet(digraph); | ||
|
|
||
| # Algorithm 6: Using the dominating set created to determine the Maximum Flow | ||
|
|
||
| if Length(D) > 1 then | ||
|
|
||
| v := D[1]; | ||
| for i in [2 .. Length(D)] do | ||
| w := D[i]; | ||
| a := DigraphMaximumFlow(EdgeD, v, w)[v]; | ||
| b := DigraphMaximumFlow(EdgeD, w, v)[w]; | ||
|
|
||
| sum := Minimum(Sum(a), Sum(b)); | ||
| if (sum < min or min = -1) then | ||
| min := sum; | ||
| fi; | ||
| od; | ||
|
|
||
| else | ||
| # If the dominating set of EdgeD is of Length 1, | ||
| # the above algorithm will not work | ||
| # Revert to iterating through all vertices of the original digraph | ||
|
|
||
| u := 1; | ||
|
|
||
| for v in [2 .. DigraphNrVertices(EdgeD)] do | ||
| a := DigraphMaximumFlow(EdgeD, u, v)[u]; | ||
| b := DigraphMaximumFlow(EdgeD, v, u)[v]; | ||
|
|
||
| sum := Minimum(Sum(a), Sum(b)); | ||
| if (sum < min or min = -1) then | ||
| min := sum; | ||
| fi; | ||
|
|
||
| od; | ||
| fi; | ||
|
Comment on lines
+836
to
+853
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part of code is almost the same across the two |
||
|
|
||
| return Minimum(min, | ||
| Minimum(Minimum(OutDegrees(EdgeD)), | ||
| Minimum(InDegrees(EdgeD)))); | ||
|
|
||
| end); | ||
|
|
||
| ############################################################################# | ||
| # 6. Random edge weighted digraphs | ||
| ############################################################################# | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does the method work for all digraphs or only symmetric digraphs? If its only intended for symmetric digraphs, then this should be explicitly checked for in the function and mentioned in the documentation.
If its meant to work for all digraphs, it matters whether the dominating set is with respect to in-neighbours or out-neighbours, so the function name should be updated (I think the currently implemented function returns the out-dominating set), say
DigraphOutDominatingSet, and a dual function for in-neighbours should be implemented.Alternatively, the function could also take the symmetric closure of the digraph, this way it would be a dominating set with respect the notion of undirected adjacency (this might be called a weak dominating set for a directed graph? Not sure).