From d1af3ab93b54d14d512b436ce274c894a7433ba7 Mon Sep 17 00:00:00 2001 From: Harry Jack Date: Sun, 14 Nov 2021 13:19:20 +0000 Subject: [PATCH 1/4] Add DigraphIsKing to oper.gi and oper.gd --- gap/oper.gd | 2 ++ gap/oper.gi | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gap/oper.gd b/gap/oper.gd index fbfe4c554..066d7db95 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -115,6 +115,8 @@ DeclareOperation("IsDigraphPath", DeclareOperation("IsDigraphPath", [IsDigraph, IsList]); # 9. Connectivity . . . +DeclareOperation("DigraphIsKing", [IsDigraph, IsPosInt, IsPosInt]); + DeclareOperation("DigraphFloydWarshall", [IsDigraph, IsFunction, IsObject, IsObject]); DeclareOperation("DigraphDijkstra", diff --git a/gap/oper.gi b/gap/oper.gi index d934269b6..40e784aef 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -1579,6 +1579,21 @@ end); # 9. Connectivity ############################################################################# +InstallMethod(DigraphIsKing, +"for a digraph and two positive integers", +[IsDigraph, IsPosInt, IsPosInt], +function(D, v, k) + local layers; + if not v in DigraphVertices(D) then + ErrorNoReturn("the 2nd argument is not a vertex of the ", + "1st argument ,"); + elif not IsTournament(D) then + ErrorNoReturn("the 1st argument must be a tournament,"); + fi; + layers := DigraphLayers(D, v); + return ((Length(layers) <= k + 1) and (Union(layers) = DigraphVertices(D))); +end); + InstallMethod(DigraphFloydWarshall, "for a digraph by out-neighbours, function, object, and object", [IsDigraphByOutNeighboursRep, IsFunction, IsObject, IsObject], From 1d5b2d08b65337a6c5088001bfa885b3c81e0389 Mon Sep 17 00:00:00 2001 From: Harry Jack Date: Wed, 17 Nov 2021 16:00:43 +0000 Subject: [PATCH 2/4] Add Digraph2Kings with tests + docs for it & DigraphIsKing --- doc/attr.xml | 26 ++++++++++++++++++++++++++ doc/oper.xml | 31 +++++++++++++++++++++++++++++++ doc/z-chap4.xml | 2 ++ gap/attr.gd | 1 + gap/attr.gi | 12 ++++++++++++ tst/standard/attr.tst | 16 ++++++++++++++++ tst/standard/oper.tst | 18 ++++++++++++++++++ 7 files changed, 106 insertions(+) diff --git a/doc/attr.xml b/doc/attr.xml index bb66a0b95..1ec744854 100644 --- a/doc/attr.xml +++ b/doc/attr.xml @@ -2770,3 +2770,29 @@ fail <#/GAPDoc> + +<#GAPDoc Label="Digraph2Kings"> + + + A list. + + If D is a tournament then this operation returns a list of the + 2-kings in the tournament. If the tournament contains a source, then the + source is the only 2-king (see ). The number + of 2-kings in a tournament without a source is at least three. A tournament + cannot have exactly two 2-kings. + + gr := Digraph([[2, 3, 4], [3, 5], [5], [2, 3], [1, 4]]); + +gap> Digraph2Kings(gr); +[ 1, 2, 5 ] +gap> gr := Digraph([[2, 3, 4, 5], [3, 5], [5], [2, 3], [4]]); + +gap> DigraphSources(gr); +[ 1 ] +gap> Digraph2Kings(gr); +[ 1 ]]]> + + +<#/GAPDoc> diff --git a/doc/oper.xml b/doc/oper.xml index 8c55db1ac..769c9d02b 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -8,6 +8,37 @@ ############################################################################# ## +<#GAPDoc Label="DigraphIsKing"> + + + true or false. + + If D is a tournament and v is a vertex in the tournament, + then this operation returns true if every other vertex of D + is reachable from v by a path of length at most k. Else, + false is returned.

+ + If true is returned, then the vertex, v, is a k-king.

+ + gr := Digraph([[2, 3, 4], [3, 5], [5], [2, 3], [1, 4]]); + +gap> DigraphIsKing(gr, 2, 2); +true +gap> DigraphIsKing(gr, 3, 2); +false +gap> OutNeighboursOfVertex(gr, 3); +[ 5 ] +gap> OutNeighboursOfVertex(gr, 5); +[ 1, 4 ] +gap> Union(last, last2); +[ 1, 4, 5 ] +gap> DigraphIsKing(gr, 3, 4); +true]]> + + +<#/GAPDoc> + <#GAPDoc Label="IsSubdigraph"> diff --git a/doc/z-chap4.xml b/doc/z-chap4.xml index 4a0feb10b..cedc594de 100644 --- a/doc/z-chap4.xml +++ b/doc/z-chap4.xml @@ -89,6 +89,8 @@ <#Include Label="NrSpanningTrees"> <#Include Label="DigraphDijkstra"> <#Include Label="DigraphCycleBasis"> + <#Include Label="DigraphIsKing"> + <#Include Label="Digraph2Kings">

Cayley graphs of groups diff --git a/gap/attr.gd b/gap/attr.gd index 7afe2359e..f2954f065 100644 --- a/gap/attr.gd +++ b/gap/attr.gd @@ -48,6 +48,7 @@ DeclareAttribute("DigraphDegeneracy", IsDigraph); DeclareAttribute("DigraphDegeneracyOrdering", IsDigraph); DeclareAttribute("DIGRAPHS_Degeneracy", IsDigraph); DeclareAttribute("DigraphShortestDistances", IsDigraph); +DeclareAttribute("Digraph2Kings", IsDigraph); DeclareAttribute("DigraphDiameter", IsDigraph); DeclareAttribute("DigraphGirth", IsDigraph); DeclareAttribute("DigraphOddGirth", IsDigraph); diff --git a/gap/attr.gi b/gap/attr.gi index 345a24620..8002d63fa 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -3431,3 +3431,15 @@ D -> DIGRAPHS_IsJoinSemilatticeAndJoinTable(D)[2]); InstallMethod(DigraphMeetTable, "for a digraph", [IsDigraph], D -> DIGRAPHS_IsMeetSemilatticeAndMeetTable(D)[2]); + +InstallMethod(Digraph2Kings, "for a digraph", [IsDigraph], +function(D) + local v, kings; + kings := []; + for v in DigraphVertices(D) do + if DigraphIsKing(D, v, 2) then + Add(kings, v); + fi; + od; + return kings; +end); diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 53e3126d1..5041e8834 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -14,6 +14,22 @@ gap> LoadPackage("digraphs", false);; # gap> DIGRAPHS_StartTest(); +# Digraph2Kings: for a digraph +gap> gr := Digraph([[2], [3, 4], [1, 4], [1]]); + +gap> Digraph2Kings(gr); +[ 1, 2, 3 ] +gap> gr := Digraph([[], [3, 4], [1, 4], [1]]); + +gap> Digraph2Kings(gr); +Error, the 1st argument must be a tournament, +gap> gr := RandomTournament(10); + +gap> Length(Digraph2Kings(gr)) >= 1; +true +gap> Length(Digraph2Kings(gr)) <> 2; +true + # DigraphSource and DigraphRange gap> nbs := [[12, 22, 17, 1, 10, 11], [23, 21, 21, 16], > [15, 5, 22, 11, 12, 8, 10, 1], [21, 15, 23, 5, 23, 8, 24], diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index e8460bc84..1eb29b2a5 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -14,6 +14,24 @@ gap> LoadPackage("digraphs", false);; # gap> DIGRAPHS_StartTest(); +# DigraphIsKing: for a digraph, a node and a positive integer +gap> gr := Digraph([[2], [3, 4], [1, 4], [1]]); + +gap> IsTournament(gr); +true +gap> DigraphIsKing(gr, 2, 2); +true +gap> DigraphIsKing(gr, 4, 2); +false +gap> DigraphIsKing(gr, 4, 3); +true +gap> DigraphIsKing(gr, 5, 2); +Error, the 2nd argument is not a vertex of the 1st argument , +gap> gr := Digraph([[], [3, 4], [1, 4], [1]]); + +gap> DigraphIsKing(gr, 2, 2); +Error, the 1st argument must be a tournament, + # DigraphRemoveLoops gap> gr := DigraphFromDigraph6String("&EhxPC?@"); From 0a3864493377b1e873e2d3e772f1a2ff98ac074b Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Fri, 11 Apr 2025 14:56:59 +0200 Subject: [PATCH 3/4] move DigraphKings to oper --- doc/attr.xml | 26 --------------------- doc/oper.xml | 38 ++++++++++++++++++++++++++++--- doc/z-chap4.xml | 2 +- extern/bliss-0.73/.deps/.dirstamp | 0 extern/bliss-0.73/.dirstamp | 0 gap/attr.gd | 1 - gap/attr.gi | 12 ---------- gap/oper.gd | 2 ++ gap/oper.gi | 13 +++++++++++ tst/standard/attr.tst | 10 ++++---- 10 files changed, 56 insertions(+), 48 deletions(-) delete mode 100644 extern/bliss-0.73/.deps/.dirstamp delete mode 100644 extern/bliss-0.73/.dirstamp diff --git a/doc/attr.xml b/doc/attr.xml index 1ec744854..bb66a0b95 100644 --- a/doc/attr.xml +++ b/doc/attr.xml @@ -2770,29 +2770,3 @@ fail <#/GAPDoc> - -<#GAPDoc Label="Digraph2Kings"> - - - A list. - - If D is a tournament then this operation returns a list of the - 2-kings in the tournament. If the tournament contains a source, then the - source is the only 2-king (see ). The number - of 2-kings in a tournament without a source is at least three. A tournament - cannot have exactly two 2-kings. - - gr := Digraph([[2, 3, 4], [3, 5], [5], [2, 3], [1, 4]]); - -gap> Digraph2Kings(gr); -[ 1, 2, 5 ] -gap> gr := Digraph([[2, 3, 4, 5], [3, 5], [5], [2, 3], [4]]); - -gap> DigraphSources(gr); -[ 1 ] -gap> Digraph2Kings(gr); -[ 1 ]]]> - - -<#/GAPDoc> diff --git a/doc/oper.xml b/doc/oper.xml index 769c9d02b..908c6bd7e 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -8,6 +8,37 @@ ############################################################################# ## +<#GAPDoc Label="DigraphKings"> + + + A list. + + If D is a tournament, then this operation returns a list of the + n-kings in the tournament (see ).

+ + If D is not tournament, then an error is given + (see ). + + If the tournament contains a source, then the source is the only 2-king + (see ). The number of 2-kings in a tournament + without a source is at least three. A tournament cannot have exactly two + 2-kings. + + gr := Digraph([[2, 3, 4], [3, 5], [5], [2, 3], [1, 4]]); + +gap> DigraphKings(gr, 2); +[ 1, 2, 5 ] +gap> gr := Digraph([[2, 3, 4, 5], [3, 5], [5], [2, 3], [4]]); + +gap> DigraphSources(gr); +[ 1 ] +gap> DigraphKings(gr, 2); +[ 1 ]]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphIsKing"> @@ -15,10 +46,11 @@ If D is a tournament and v is a vertex in the tournament, then this operation returns true if every other vertex of D - is reachable from v by a path of length at most k. Else, - false is returned.

+ is reachable from v by a path of length at most k. Otherwise, + an error is given. - If true is returned, then the vertex, v, is a k-king.

+ If true is returned, then the vertex, v, is a k-king. +

gr := Digraph([[2, 3, 4], [3, 5], [5], [2, 3], [1, 4]]); diff --git a/doc/z-chap4.xml b/doc/z-chap4.xml index cedc594de..999d01486 100644 --- a/doc/z-chap4.xml +++ b/doc/z-chap4.xml @@ -90,7 +90,7 @@ <#Include Label="DigraphDijkstra"> <#Include Label="DigraphCycleBasis"> <#Include Label="DigraphIsKing"> - <#Include Label="Digraph2Kings"> + <#Include Label="DigraphKings">

Cayley graphs of groups diff --git a/extern/bliss-0.73/.deps/.dirstamp b/extern/bliss-0.73/.deps/.dirstamp deleted file mode 100644 index e69de29bb..000000000 diff --git a/extern/bliss-0.73/.dirstamp b/extern/bliss-0.73/.dirstamp deleted file mode 100644 index e69de29bb..000000000 diff --git a/gap/attr.gd b/gap/attr.gd index f2954f065..7afe2359e 100644 --- a/gap/attr.gd +++ b/gap/attr.gd @@ -48,7 +48,6 @@ DeclareAttribute("DigraphDegeneracy", IsDigraph); DeclareAttribute("DigraphDegeneracyOrdering", IsDigraph); DeclareAttribute("DIGRAPHS_Degeneracy", IsDigraph); DeclareAttribute("DigraphShortestDistances", IsDigraph); -DeclareAttribute("Digraph2Kings", IsDigraph); DeclareAttribute("DigraphDiameter", IsDigraph); DeclareAttribute("DigraphGirth", IsDigraph); DeclareAttribute("DigraphOddGirth", IsDigraph); diff --git a/gap/attr.gi b/gap/attr.gi index 8002d63fa..345a24620 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -3431,15 +3431,3 @@ D -> DIGRAPHS_IsJoinSemilatticeAndJoinTable(D)[2]); InstallMethod(DigraphMeetTable, "for a digraph", [IsDigraph], D -> DIGRAPHS_IsMeetSemilatticeAndMeetTable(D)[2]); - -InstallMethod(Digraph2Kings, "for a digraph", [IsDigraph], -function(D) - local v, kings; - kings := []; - for v in DigraphVertices(D) do - if DigraphIsKing(D, v, 2) then - Add(kings, v); - fi; - od; - return kings; -end); diff --git a/gap/oper.gd b/gap/oper.gd index 066d7db95..6e03bf11b 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -116,6 +116,8 @@ DeclareOperation("IsDigraphPath", [IsDigraph, IsList]); # 9. Connectivity . . . DeclareOperation("DigraphIsKing", [IsDigraph, IsPosInt, IsPosInt]); +DeclareOperation("DigraphKings", [IsDigraph, IsPosInt]); + DeclareOperation("DigraphFloydWarshall", [IsDigraph, IsFunction, IsObject, IsObject]); diff --git a/gap/oper.gi b/gap/oper.gi index 40e784aef..13a42a6b0 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -2698,3 +2698,16 @@ function(D, i, j) return fail; end); + +InstallMethod(DigraphKings, "for a digraph and a positive integer", +[IsDigraph, IsPosInt], +function(D, n) + local v, kings; + kings := []; + for v in DigraphVertices(D) do + if DigraphIsKing(D, v, n) then + Add(kings, v); + fi; + od; + return kings; +end); diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 5041e8834..a7d9ce951 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -14,20 +14,20 @@ gap> LoadPackage("digraphs", false);; # gap> DIGRAPHS_StartTest(); -# Digraph2Kings: for a digraph +# DigraphKings: for a digraph gap> gr := Digraph([[2], [3, 4], [1, 4], [1]]); -gap> Digraph2Kings(gr); +gap> DigraphKings(gr, 2); [ 1, 2, 3 ] gap> gr := Digraph([[], [3, 4], [1, 4], [1]]); -gap> Digraph2Kings(gr); +gap> DigraphKings(gr, 2); Error, the 1st argument must be a tournament, gap> gr := RandomTournament(10); -gap> Length(Digraph2Kings(gr)) >= 1; +gap> Length(DigraphKings(gr, 2)) >= 1; true -gap> Length(Digraph2Kings(gr)) <> 2; +gap> Length(DigraphKings(gr, 2)) <> 2; true # DigraphSource and DigraphRange From 50bfb14366753fb75a0e2076471948988ce8387f Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Fri, 11 Apr 2025 23:14:16 +0200 Subject: [PATCH 4/4] Fix whitespace --- doc/oper.xml | 6 +++--- gap/oper.gd | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/oper.xml b/doc/oper.xml index 908c6bd7e..6e4cbc556 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -17,8 +17,8 @@ n-kings in the tournament (see ).

If D is not tournament, then an error is given - (see ). - + (see ). + If the tournament contains a source, then the source is the only 2-king (see ). The number of 2-kings in a tournament without a source is at least three. A tournament cannot have exactly two @@ -47,7 +47,7 @@ gap> DigraphKings(gr, 2); If D is a tournament and v is a vertex in the tournament, then this operation returns true if every other vertex of D is reachable from v by a path of length at most k. Otherwise, - an error is given. + an error is given. If true is returned, then the vertex, v, is a k-king.

diff --git a/gap/oper.gd b/gap/oper.gd index 6e03bf11b..619de1db3 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -118,7 +118,6 @@ DeclareOperation("IsDigraphPath", [IsDigraph, IsList]); DeclareOperation("DigraphIsKing", [IsDigraph, IsPosInt, IsPosInt]); DeclareOperation("DigraphKings", [IsDigraph, IsPosInt]); - DeclareOperation("DigraphFloydWarshall", [IsDigraph, IsFunction, IsObject, IsObject]); DeclareOperation("DigraphDijkstra",