diff --git a/doc/attr.xml b/doc/attr.xml index c2cba764d..9017d14eb 100644 --- a/doc/attr.xml +++ b/doc/attr.xml @@ -944,21 +944,44 @@ gap> DigraphShortestDistances(D); <#/GAPDoc> +<#GAPDoc Label="DigraphEccentricities"> + + + A list of non-negative integers or fail. + + This function returns a list of the eccentricities of each vertex in + digraph. If digraph is strongly connected and has at least 1 + vertex, then the eccentricity of a vertex v is the maximum + shortest distance between v and any other vertex; see + .

+ + If digraph is not strongly connected, then the value fail + is returned. + DigraphEccentricities(Digraph([[2], [1, 3], [2]])); +[ 2, 1, 2 ] +gap> DigraphEccentricities(CycleDigraph(3)); +[ 2, 2, 2 ] +gap> DigraphEccentricities(ChainDigraph(2)); +fail +gap> DigraphEccentricities(EmptyDigraph(0)); +fail +]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphDiameter"> - An integer or fail. + A non-negative integer or fail. - This function returns the diameter of the digraph digraph. -

- - If a digraph digraph is strongly connected and has at least 1 - vertex, then the diameter is the maximum shortest distance between - any pair of distinct vertices. Otherwise then the diameter of - digraph is undefined, and this function returns the value - fail.

- - See .

+ This function returns the diameter of digraph. If + digraph is strongly connected and has at least 1 vertex, then its + diameter is the maximum eccentricity over its vertices; see + . Otherwise, the diameter of + digraph is undefined, and the value fail is returned. D := Digraph([[2], [3], [4, 5], [5], [1, 2, 3, 4, 5]]); @@ -979,6 +1002,75 @@ gap> DigraphDiameter(D); <#/GAPDoc> +<#GAPDoc Label="DigraphRadius"> + + + A non-negative integer or fail. + + This function returns the radius of digraph. If + digraph is strongly connected and has at least 1 vertex, then its + radius is the minimum eccentricity over its vertices; see + . Otherwise, the radius of + digraph is undefined, and the value fail is returned. + D := CycleDigraph(5);; +gap> DigraphRadius(D); +4 +gap> D := CompleteDigraph(5);; +gap> DigraphRadius(D); +1 +]]> + + +<#/GAPDoc> + +<#GAPDoc Label="DigraphCentre"> + + + + A list of vertices or fail. + + This function returns the centre of digraph. If digraph is + strongly connected and has at least 1 vertex, then its centre is the + set of all vertices whose eccentricities equal the radius of + digraph; see . Otherwise, the + centre of digraph is undefined, and the value fail is + returned.

+ + is a synonym for . + D := Digraph([[2], [1, 3], [2, 4], [3]]);; +gap> DigraphRadius(D); +2 +gap> DigraphCentre(D); +[ 2, 3 ] +]]> + + +<#/GAPDoc> + +<#GAPDoc Label="DigraphPeriphery"> + + + A list of vertices or fail. + + This function returns the periphery of digraph. If + digraph is strongly connected and has at least 1 vertex, then its + periphery is the set of all vertices whose eccentricities equal the + diameter of digraph; see . + Otherwise, the periphery of digraph is undefined, and the + value fail is returned. + D := Digraph([[2], [1, 3], [2, 4], [3]]);; +gap> DigraphDiameter(D); +3 +gap> DigraphPeriphery(D); +[ 1, 4 ] +]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphGirth"> diff --git a/doc/z-chap4.xml b/doc/z-chap4.xml index 059e10eea..c800a428e 100644 --- a/doc/z-chap4.xml +++ b/doc/z-chap4.xml @@ -47,7 +47,11 @@

Reachability and connectivity + <#Include Label="DigraphEccentricities"> <#Include Label="DigraphDiameter"> + <#Include Label="DigraphRadius"> + <#Include Label="DigraphCentre"> + <#Include Label="DigraphPeriphery"> <#Include Label="DigraphShortestDistance"> <#Include Label="DigraphShortestDistances"> <#Include Label="DigraphLongestDistanceFromVertex"> diff --git a/gap/attr.gd b/gap/attr.gd index 09d171f6a..8e706a88c 100644 --- a/gap/attr.gd +++ b/gap/attr.gd @@ -49,6 +49,11 @@ DeclareAttribute("DigraphDegeneracyOrdering", IsDigraph); DeclareAttribute("DIGRAPHS_Degeneracy", IsDigraph); DeclareAttribute("DigraphShortestDistances", IsDigraph); DeclareAttribute("DigraphDiameter", IsDigraph); +DeclareAttribute("DigraphEccentricities", IsDigraph); +DeclareAttribute("DigraphRadius", IsDigraph); +DeclareAttribute("DigraphCentre", IsDigraph); +DeclareSynonymAttr("DigraphCenter", DigraphCentre); +DeclareAttribute("DigraphPeriphery", IsDigraph); DeclareAttribute("DigraphGirth", IsDigraph); DeclareAttribute("DigraphOddGirth", IsDigraph); DeclareAttribute("DigraphUndirectedGirth", IsDigraph); diff --git a/gap/attr.gi b/gap/attr.gi index ebaf86487..af420ba17 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -1508,6 +1508,42 @@ function(D) return DIGRAPH_DIAMETER(D); end); +InstallMethod(DigraphEccentricities, "for a digraph", +[IsDigraph], +function(D) + if not IsStronglyConnectedDigraph(D) or DigraphNrVertices(D) = 0 then + return fail; + fi; + return List(DigraphShortestDistances(D), Maximum); +end); + +InstallMethod(DigraphRadius, "for a digraph", +[IsDigraph], +function(D) + if not IsStronglyConnectedDigraph(D) or DigraphNrVertices(D) = 0 then + return fail; + fi; + return Minimum(DigraphEccentricities(D)); +end); + +InstallMethod(DigraphCentre, "for a digraph", +[IsDigraph], +function(D) + if not IsStronglyConnectedDigraph(D) or DigraphNrVertices(D) = 0 then + return fail; + fi; + return Positions(DigraphEccentricities(D), DigraphRadius(D)); +end); + +InstallMethod(DigraphPeriphery, "for a digraph", +[IsDigraph], +function(D) + if not IsStronglyConnectedDigraph(D) or DigraphNrVertices(D) = 0 then + return fail; + fi; + return Positions(DigraphEccentricities(D), DigraphDiameter(D)); +end); + InstallMethod(DigraphUndirectedGirth, "for a digraph", [IsDigraph], function(D) # This is only defined on undirected graphs (i.e. symmetric digraphs) diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 6105bfae1..abf6cec5e 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -3389,6 +3389,42 @@ true gap> B[14, 15] = z; true +# DigraphEccentricities, DigraphRadius, DigraphCentre, and DigraphPeriphery +gap> D := ChainDigraph(2);; +gap> DigraphEccentricities(D); +fail +gap> DigraphRadius(D); +fail +gap> DigraphCentre(D); +fail +gap> DigraphPeriphery(D); +fail +gap> D := EmptyDigraph(0);; +gap> DigraphEccentricities(D); +fail +gap> DigraphRadius(D); +fail +gap> DigraphCentre(D); +fail +gap> DigraphPeriphery(D); +fail +gap> D := Digraph([[2], [1, 3], [2, 4], [3]]);; +gap> DigraphRadius(D); +2 +gap> DigraphDiameter(D); +3 +gap> DigraphCentre(D); +[ 2, 3 ] +gap> DigraphPeriphery(D); +[ 1, 4 ] +gap> D := Digraph([[1, 1]]);; +gap> DigraphRadius(D); +0 +gap> DigraphCentre(D) = DigraphPeriphery(D); +true +gap> DigraphCenter = DigraphCenter; +true + # DigraphAbsorptionProbabilities gap> gr := Digraph([[2, 3, 4], [3], [2], []]);