Skip to content

Commit 91c80c5

Browse files
committed
Added explanations for each Algorithm and edited gapdocs + tests for implemented methods
1 parent 529beeb commit 91c80c5

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
@@ -1910,6 +1910,46 @@ rec( idom := [ 2, fail, 2, 2, 2 ], preorder := [ 2, 1, 3, 4, 5 ] )
19101910
</ManSection>
19111911
<#/GAPDoc>
19121912

1913+
<#GAPDoc Label="DigraphDominatingSet">
1914+
<ManSection>
1915+
<Oper Name="DigraphDominatingSet" Arg="digraph"/>
1916+
<Returns>A List</Returns>
1917+
<Description>
1918+
This creates a dominating set of <A>digraph</A>, which is a subset of the vertices in
1919+
<A>digraph</A> such that the neighbourhood of this subset of vertices is equal to all
1920+
the vertices in <A>digraph</A>. </P>
1921+
1922+
The domating set returned will be one of potentially multiple possible dominating sets for the digraph.
1923+
<Example><![CDATA[
1924+
D := Digraph([[2,3,4], [],[],[]]);;
1925+
gap> DigraphDominatingSet(D);
1926+
[ 4, 1 ]
1927+
gap> DigraphDominatingSet(D);
1928+
[ 1 ]]]></Example>
1929+
</Description>
1930+
</ManSection>
1931+
<#/GAPDoc>
1932+
1933+
<#GAPDoc Label="DigraphGetNeighbourhood">
1934+
<ManSection>
1935+
<Oper Name="DigraphGetNeighbourhood" Arg="digraph, vertices"/>
1936+
<Returns>A List</Returns>
1937+
<Description>
1938+
This returns the set of vertices that are adjacent to a vertex in <A>vertices</A>,
1939+
not including any vertices that exist in <A>vertices</A>.
1940+
<Example><![CDATA[
1941+
gap> D := Digraph([[2, 3, 4], [1], [], []]);;
1942+
gap> DigraphGetNeighbourhood(D, [1]);
1943+
[ 2, 3, 4 ]
1944+
gap> DigraphGetNeighbourhood(D, [1, 2]);
1945+
[ 3, 4 ]
1946+
gap> D := Digraph([[2, 3, 4], [], [], []]);;
1947+
gap> DigraphGetNeighbourhood(D, [2]);
1948+
[ ]]]></Example>
1949+
</Description>
1950+
</ManSection>
1951+
<#/GAPDoc>
1952+
19131953
<#GAPDoc Label="PartialOrderDigraphMeetOfVertices">
19141954
<ManSection>
19151955
<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
@@ -2513,6 +2513,8 @@ function(D, root)
25132513
end);
25142514

25152515
# For calculating a dominating set for a digraph
2516+
# Algorithm 7 in :
2517+
# https://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
25162518
InstallMethod(DigraphDominatingSet, "for a digraph",
25172519
[IsDigraph],
25182520
function(digraph)

gap/weights.gi

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,27 @@ function(digraph, start, destination)
781781
return flows;
782782
end);
783783

784-
# DigraphEdgeConnectivity calculated using Spanning Trees
784+
#############################################################################
785+
# Digraph Edge Connectivity
786+
#############################################################################
787+
788+
# Algorithms constructed off the algorithms detailed in:
789+
# https://www.cse.msu.edu/~cse835/Papers/Graph_connectivity_revised.pdf
790+
# Each Algorithm uses a different method to decrease the time complexity,
791+
# of calculating Edge Connectivity, though all make use of DigraphMaximumFlow()
792+
# due to the Max-Flow, Min-Cut Theorem
793+
794+
# Algorithm 1: Calculating the Maximum Flow of every possible source and sink
795+
# Algorithm 2: Calculating the Maximum Flow to all sinks of an arbitrary source
796+
# Algorithm 3: Finding Maximum Flow within the non-leaves of a Spanning Tree
797+
# Algorithm 4: Constructing a spanning tree with a high number of leaves
798+
# Algorithm 5: Using the spanning tree^ to find Maximum Flow within non-leaves
799+
# Algorithm 6: Finding Maximum Flow within a dominating set of the digraph
800+
# Algorithm 7: Constructing a dominating set for use in Algorithm 6
801+
802+
# Algorithms 4-7 are used below:
803+
804+
# DigraphEdgeConnectivity calculated using Spanning Trees (Algorithm 4 & 5)
785805
InstallMethod(DigraphEdgeConnectivity, "for a digraph",
786806
[IsDigraph],
787807
function(digraph)
@@ -825,7 +845,6 @@ function(digraph)
825845
Append(added, Difference(OutNeighbours(EdgeD)[v], added));
826846

827847
# Select the neighbour to v with the highest number of not-added neighbours:
828-
829848
notadded := Difference(VerticesED, added);
830849
max := 0;
831850
NextVertex := v;
@@ -848,17 +867,15 @@ function(digraph)
848867

849868
od;
850869

851-
# Algorithm 5: Using Algorithm 4 to find the Edge Connectivity
852-
870+
# Algorithm 5: Iterating through the non-leaves of the
871+
# Spanning Tree created in Algorithm 4 to find the Edge Connectivity
853872
non_leaf := [];
854873
for b in VerticesED do
855874
if not IsEmpty(OutNeighbours(st)[b]) then
856875
Append(non_leaf, [b]);
857876
fi;
858877
od;
859878

860-
# Get the smaller of non_leaf and Difference(Vertices in EdgeD, non_leaf)
861-
862879
if (Length(non_leaf) > 1) then
863880
u := non_leaf[1];
864881

@@ -881,6 +898,7 @@ function(digraph)
881898
else
882899
# In the case of spanning trees with only one non-leaf node,
883900
# the above algorithm does not work
901+
# Revert to iterating through all vertices of the original digraph
884902

885903
u := 1;
886904
for v in [2 .. DigraphNrVertices(EdgeD)] do
@@ -906,7 +924,7 @@ function(digraph)
906924
return min;
907925
end);
908926

909-
# Digraph EdgeConnectivity calculated with Dominating Sets
927+
# Digraph EdgeConnectivity calculated with Dominating Sets (Algorithm 6-7)
910928
InstallMethod(DigraphEdgeConnectivityDS, "for a digraph",
911929
[IsDigraph],
912930
function(digraph)
@@ -932,10 +950,10 @@ function(digraph)
932950
min := -1;
933951

934952
# Algorithm 7: Creating a dominating set of the digraph
935-
953+
936954
D := DigraphDominatingSet(digraph);
937955

938-
# Algorithm 6:
956+
# Algorithm 6: Using the dominating set created to determine the Maximum Flow
939957

940958
if Length(D) > 1 then
941959

@@ -954,6 +972,7 @@ function(digraph)
954972
else
955973
# If the dominating set of EdgeD is of Length 1,
956974
# the above algorithm will not work
975+
# Revert to iterating through all vertices of the original digraph
957976

958977
u := 1;
959978

tst/standard/oper.tst

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

2814+
# DigraphGetNeighbourhood
2815+
gap> D := Digraph([[2, 3, 4], [1], [], []]);;
2816+
gap> DigraphGetNeighbourhood(D, [1]);
2817+
[ 2, 3, 4 ]
2818+
gap> DigraphGetNeighbourhood(D, [1, 2]);
2819+
[ 3, 4 ]
2820+
gap> D := Digraph([[2, 3, 4], [], [], []]);;
2821+
gap> DigraphGetNeighbourhood(D, [2]);
2822+
[ ]
2823+
gap> D := Digraph([[2], [3], [4], [1]]);;
2824+
gap> DigraphGetNeighbourhood(D, [1]);
2825+
[ 2 ]
2826+
gap> DigraphGetNeighbourhood(D, [1, 3]);
2827+
[ 2, 4 ]
2828+
28142829
# IsDigraphPath
28152830
gap> D := Digraph(IsMutableDigraph, Combinations([1 .. 5]), IsSubset);
28162831
<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
@@ -369,6 +369,20 @@ gap> gr := EdgeWeightedDigraph([[2], [3, 6], [4], [1, 6], [1, 3], []],
369369
gap> DigraphMaximumFlow(gr, 5, 6);
370370
[ [ 10 ], [ 3, 7 ], [ 7 ], [ 0, 7 ], [ 10, 4 ], [ ] ]
371371
372+
# EdgeConnectivity
373+
gap> d := Digraph([[2, 3], [2, 3], [1, 2, 3]]);;
374+
gap> DigraphEdgeConnectivity(d);
375+
1
376+
gap> D := RandomDigraph(1);;
377+
gap> DigraphEdgeConnectivity(D);
378+
0
379+
gap> d := Digraph([[2, 4], [3], [1, 5], [3], [4]]);;
380+
gap> DigraphEdgeConnectivity(d);
381+
1
382+
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]]);;
383+
gap> DigraphEdgeConnectivity(D);
384+
4
385+
372386
#############################################################################
373387
# 6. Random edge-weighted digraphs
374388
#############################################################################

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)