Skip to content

Commit 0634eed

Browse files
committed
Added explanations for each Algorithm and edited gapdocs + tests for implemented methods
1 parent c498734 commit 0634eed

File tree

7 files changed

+124
-18
lines changed

7 files changed

+124
-18
lines changed

doc/oper.xml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,46 @@ rec( idom := [ 2, fail, 2, 2, 2 ], preorder := [ 2, 1, 3, 4, 5 ] )
19541954
</ManSection>
19551955
<#/GAPDoc>
19561956

1957+
<#GAPDoc Label="DigraphDominatingSet">
1958+
<ManSection>
1959+
<Oper Name="DigraphDominatingSet" Arg="digraph"/>
1960+
<Returns>A List</Returns>
1961+
<Description>
1962+
This creates a dominating set of <A>digraph</A>, which is a subset of the vertices in
1963+
<A>digraph</A> such that the neighbourhood of this subset of vertices is equal to all
1964+
the vertices in <A>digraph</A>. </P>
1965+
1966+
The domating set returned will be one of potentially multiple possible dominating sets for the digraph.
1967+
<Example><![CDATA[
1968+
D := Digraph([[2,3,4], [],[],[]]);;
1969+
gap> DigraphDominatingSet(D);
1970+
[ 4, 1 ]
1971+
gap> DigraphDominatingSet(D);
1972+
[ 1 ]]]></Example>
1973+
</Description>
1974+
</ManSection>
1975+
<#/GAPDoc>
1976+
1977+
<#GAPDoc Label="DigraphGetNeighbourhood">
1978+
<ManSection>
1979+
<Oper Name="DigraphGetNeighbourhood" Arg="digraph, vertices"/>
1980+
<Returns>A List</Returns>
1981+
<Description>
1982+
This returns the set of vertices that are adjacent to a vertex in <A>vertices</A>,
1983+
not including any vertices that exist in <A>vertices</A>.
1984+
<Example><![CDATA[
1985+
gap> D := Digraph([[2, 3, 4], [1], [], []]);;
1986+
gap> DigraphGetNeighbourhood(D, [1]);
1987+
[ 2, 3, 4 ]
1988+
gap> DigraphGetNeighbourhood(D, [1, 2]);
1989+
[ 3, 4 ]
1990+
gap> D := Digraph([[2, 3, 4], [], [], []]);;
1991+
gap> DigraphGetNeighbourhood(D, [2]);
1992+
[ ]]]></Example>
1993+
</Description>
1994+
</ManSection>
1995+
<#/GAPDoc>
1996+
19571997
<#GAPDoc Label="PartialOrderDigraphMeetOfVertices">
19581998
<ManSection>
19591999
<Oper Name="PartialOrderDigraphMeetOfVertices"

doc/weights.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,31 @@ gap> Sum(flow[1]);
272272
</ManSection>
273273
<#/GAPDoc>
274274

275+
<#GAPDoc Label="DigraphEdgeConnectivity">
276+
<ManSection>
277+
<Attr Name="DigraphEdgeConnectivity" Arg="digraph"/>
278+
<Returns>An integer</Returns>
279+
<Description>
280+
This returns a record representing the edge connectivity of <A>digraph</A>.<P/>
281+
282+
It makes use of <C>DigraphMaximumFlow(<A>digraph</A>)</C>, by constructing an edge-weighted Digraph
283+
with edge weights of 1, then using the Max-flow min-cut theorem to determine the size of the minimum cut.
284+
For a digraph, the minimum cut is the set of edges that need to be removed to ensure the digraph is
285+
no longer Strongly Connected. </P>
286+
<Example><![CDATA[
287+
gap> D := Digraph([[2, 3, 4], [1, 3, 4], [1, 2], [2, 3]]);;
288+
gap> DigraphEdgeConnectivity(D);
289+
2
290+
gap> D := Digraph([[], [1, 2], [2]]);;
291+
gap> DigraphEdgeConnectivity(D);
292+
0
293+
gap> D := Digraph([[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]);;
294+
gap> DigraphEdgeConnectivity(D);
295+
4]]></Example>
296+
</Description>
297+
</ManSection>
298+
<#/GAPDoc>
299+
275300
<#GAPDoc Label="RandomUniqueEdgeWeightedDigraph">
276301
<ManSection>
277302
<Oper Name="RandomUniqueEdgeWeightedDigraph" Arg="[filt, ]n[, p]"/>

gap/oper.gi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,6 +2523,8 @@ function(D, root)
25232523
end);
25242524

25252525
# For calculating a dominating set for a digraph
2526+
# Algorithm 7 in :
2527+
# https://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
25262528
InstallMethod(DigraphDominatingSet, "for a digraph",
25272529
[IsDigraph],
25282530
function(digraph)

gap/weights.gi

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,27 @@ function(D, start, destination)
772772
return flows;
773773
end);
774774

775-
# DigraphEdgeConnectivity calculated using Spanning Trees
775+
#############################################################################
776+
# Digraph Edge Connectivity
777+
#############################################################################
778+
779+
# Algorithms constructed off the algorithms detailed in:
780+
# https://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
781+
# Each Algorithm uses a different method to decrease the time complexity,
782+
# of calculating Edge Connectivity, though all make use of DigraphMaximumFlow()
783+
# due to the Max-Flow, Min-Cut Theorem
784+
785+
# Algorithm 1: Calculating the Maximum Flow of every possible source and sink
786+
# Algorithm 2: Calculating the Maximum Flow to all sinks of an arbitrary source
787+
# Algorithm 3: Finding Maximum Flow within the non-leaves of a Spanning Tree
788+
# Algorithm 4: Constructing a spanning tree with a high number of leaves
789+
# Algorithm 5: Using the spanning tree^ to find Maximum Flow within non-leaves
790+
# Algorithm 6: Finding Maximum Flow within a dominating set of the digraph
791+
# Algorithm 7: Constructing a dominating set for use in Algorithm 6
792+
793+
# Algorithms 4-7 are used below:
794+
795+
# DigraphEdgeConnectivity calculated using Spanning Trees (Algorithm 4 & 5)
776796
InstallMethod(DigraphEdgeConnectivity, "for a digraph",
777797
[IsDigraph],
778798
function(digraph)
@@ -816,7 +836,6 @@ function(digraph)
816836
Append(added, Difference(OutNeighbours(EdgeD)[v], added));
817837

818838
# Select the neighbour to v with the highest number of not-added neighbours:
819-
820839
notadded := Difference(VerticesED, added);
821840
max := 0;
822841
NextVertex := v;
@@ -839,17 +858,15 @@ function(digraph)
839858

840859
od;
841860

842-
# Algorithm 5: Using Algorithm 4 to find the Edge Connectivity
843-
861+
# Algorithm 5: Iterating through the non-leaves of the
862+
# Spanning Tree created in Algorithm 4 to find the Edge Connectivity
844863
non_leaf := [];
845864
for b in VerticesED do
846865
if not IsEmpty(OutNeighbours(st)[b]) then
847866
Append(non_leaf, [b]);
848867
fi;
849868
od;
850869

851-
# Get the smaller of non_leaf and Difference(Vertices in EdgeD, non_leaf)
852-
853870
if (Length(non_leaf) > 1) then
854871
u := non_leaf[1];
855872

@@ -872,6 +889,7 @@ function(digraph)
872889
else
873890
# In the case of spanning trees with only one non-leaf node,
874891
# the above algorithm does not work
892+
# Revert to iterating through all vertices of the original digraph
875893

876894
u := 1;
877895
for v in [2 .. DigraphNrVertices(EdgeD)] do
@@ -897,7 +915,7 @@ function(digraph)
897915
return min;
898916
end);
899917

900-
# Digraph EdgeConnectivity calculated with Dominating Sets
918+
# Digraph EdgeConnectivity calculated with Dominating Sets (Algorithm 6-7)
901919
InstallMethod(DigraphEdgeConnectivityDS, "for a digraph",
902920
[IsDigraph],
903921
function(digraph)
@@ -923,10 +941,10 @@ function(digraph)
923941
min := -1;
924942

925943
# Algorithm 7: Creating a dominating set of the digraph
926-
944+
927945
D := DigraphDominatingSet(digraph);
928946

929-
# Algorithm 6:
947+
# Algorithm 6: Using the dominating set created to determine the Maximum Flow
930948

931949
if Length(D) > 1 then
932950

@@ -945,6 +963,7 @@ function(digraph)
945963
else
946964
# If the dominating set of EdgeD is of Length 1,
947965
# the above algorithm will not work
966+
# Revert to iterating through all vertices of the original digraph
948967

949968
u := 1;
950969

tst/standard/oper.tst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,21 @@ rec( idom := [ fail ], preorder := [ 1 ] )
28612861
gap> DominatorTree(D, 6);
28622862
rec( idom := [ ,,,,, fail ], preorder := [ 6 ] )
28632863

2864+
# DigraphGetNeighbourhood
2865+
gap> D := Digraph([[2, 3, 4], [1], [], []]);;
2866+
gap> DigraphGetNeighbourhood(D, [1]);
2867+
[ 2, 3, 4 ]
2868+
gap> DigraphGetNeighbourhood(D, [1, 2]);
2869+
[ 3, 4 ]
2870+
gap> D := Digraph([[2, 3, 4], [], [], []]);;
2871+
gap> DigraphGetNeighbourhood(D, [2]);
2872+
[ ]
2873+
gap> D := Digraph([[2], [3], [4], [1]]);;
2874+
gap> DigraphGetNeighbourhood(D, [1]);
2875+
[ 2 ]
2876+
gap> DigraphGetNeighbourhood(D, [1, 3]);
2877+
[ 2, 4 ]
2878+
28642879
# IsDigraphPath
28652880
gap> D := Digraph(IsMutableDigraph, Combinations([1 .. 5]), IsSubset);
28662881
<mutable digraph with 32 vertices, 243 edges>

tst/standard/weights.tst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ gap> gr := EdgeWeightedDigraph([[2], [3, 6], [4], [1, 6], [1, 3], []],
368368
gap> DigraphMaximumFlow(gr, 5, 6);
369369
[ [ 10 ], [ 3, 7 ], [ 7 ], [ 0, 7 ], [ 10, 4 ], [ ] ]
370370
371+
# EdgeConnectivity
372+
gap> d := Digraph([[2, 3], [2, 3], [1, 2, 3]]);;
373+
gap> DigraphEdgeConnectivity(d);
374+
1
375+
gap> D := RandomDigraph(1);;
376+
gap> DigraphEdgeConnectivity(D);
377+
0
378+
gap> d := Digraph([[2, 4], [3], [1, 5], [3], [4]]);;
379+
gap> DigraphEdgeConnectivity(d);
380+
1
381+
gap> D := Digraph([[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]);;
382+
gap> DigraphEdgeConnectivity(D);
383+
4
384+
371385
#############################################################################
372386
# 6. Random edge-weighted digraphs
373387
#############################################################################

tst/testinstall.tst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -554,21 +554,12 @@ gap> OutNeighbours(C);
554554
gap> D := Digraph([[2, 3, 4], [1, 3, 4], [1, 2], [2, 3]]);;
555555
gap> DigraphEdgeConnectivity(D);
556556
2
557-
gap> C := Digraph([[2, 3], [2, 3], [1, 2, 3]]);;
558-
gap> DigraphEdgeConnectivity(C);
559-
1
560557
gap> D := Digraph([[], [1, 2], [2]]);;
561558
gap> DigraphEdgeConnectivity(D);
562559
0
563560
gap> C := Digraph([[3, 4], [1, 3, 4], [2], [3]]);;
564561
gap> DigraphEdgeConnectivity(C);
565562
1
566-
gap> D := RandomDigraph(1);;
567-
gap> DigraphEdgeConnectivity(D);
568-
0
569-
gap> C := Digraph([[2, 4], [3], [1, 5], [3], [4]]);;
570-
gap> DigraphEdgeConnectivity(C);
571-
1
572563
gap> D := Digraph([[ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ], [ 1, 2, 3, 4, 5 ]]);;
573564
gap> DigraphEdgeConnectivity(D);
574565
4

0 commit comments

Comments
 (0)