diff --git a/doc/attr.xml b/doc/attr.xml index 0aeec90ca..45e688b32 100644 --- a/doc/attr.xml +++ b/doc/attr.xml @@ -2399,3 +2399,29 @@ gap> Length(M); <#/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> \ No newline at end of file diff --git a/doc/oper.xml b/doc/oper.xml index 324951db2..1b9f75875 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 00224832d..3588175ef 100644 --- a/doc/z-chap4.xml +++ b/doc/z-chap4.xml @@ -75,6 +75,8 @@ <#Include Label="HamiltonianPath"> <#Include Label="NrSpanningTrees"> <#Include Label="DigraphDijkstra"> + <#Include Label="DigraphIsKing"> + <#Include Label="Digraph2Kings">

Cayley graphs of groups diff --git a/gap/attr.gd b/gap/attr.gd index 7f57ba5d2..2fa88ab49 100644 --- a/gap/attr.gd +++ b/gap/attr.gd @@ -45,6 +45,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 7debc92dd..ebea3375a 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -2609,3 +2609,15 @@ function(D) M := List(DigraphLoops(D), x -> [x, x]); return Union(M, DIGRAPHS_MateToMatching(D, mateD)); end); + +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); \ No newline at end of file diff --git a/gap/oper.gd b/gap/oper.gd index 45c48ea3c..01a4c7c1e 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -110,6 +110,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 a8f3f65d9..2cd7c01c4 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -1318,6 +1318,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], diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 1dc47d0b5..952efd3ac 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 4c4aedf0a..f10934a49 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?@");