diff --git a/gap/attr.gd b/gap/attr.gd index 7afe2359e..69eb908f8 100644 --- a/gap/attr.gd +++ b/gap/attr.gd @@ -141,3 +141,8 @@ DeclareProperty("IsLowerSemimodularDigraph", IsDigraph); DeclareAttribute("DigraphJoinTable", IsDigraph); DeclareAttribute("DigraphMeetTable", IsDigraph); + +DeclareAttribute("DigraphDistanceMetrics", IsDigraph); +DeclareAttribute("DigraphRadius", IsDigraph); +DeclareAttribute("DigraphCentre", IsDigraph); +DeclareAttribute("DigraphPeriphery", IsDigraph); \ No newline at end of file diff --git a/gap/attr.gi b/gap/attr.gi index 345a24620..c341082ff 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -3431,3 +3431,42 @@ D -> DIGRAPHS_IsJoinSemilatticeAndJoinTable(D)[2]); InstallMethod(DigraphMeetTable, "for a digraph", [IsDigraph], D -> DIGRAPHS_IsMeetSemilatticeAndMeetTable(D)[2]); + +InstallMethod(DigraphDistanceMetrics, "for a digraph", +[IsDigraph], +function(G) + local ecc, c, u, v; + if not IsDigraph(G) then + Error("Input must be a digraph"); + elif not IsStronglyConnectedDigraph(G) then + Error("Input digraph is not strongly connected; property undefined"); + fi; + ecc := []; + for u in [1 .. DigraphNrVertices(G)] do + c := 0; + for v in [1 .. DigraphNrVertices(G)] do + if u <> v then + c := Maximum(c, DigraphShortestDistance(G, u, v)); + fi; + od; + Add(ecc, c); + od; + return rec( + Radius := Minimum(ecc), + DigraphCentre := Filtered([1 .. DigraphNrVertices(G)], + i -> ecc[i] = Minimum(ecc)), + Periphery := Filtered([1 .. DigraphNrVertices(G)], + i -> ecc[i] = Maximum(ecc))); +end); + +InstallMethod(DigraphRadius, "for a digraph", +[IsDigraph], +D -> DigraphDistanceMetrics(D).Radius); + +InstallMethod(DigraphCentre, "for a digraph", +[IsDigraph], +D -> DigraphDistanceMetrics(D).DigraphCentre); + +InstallMethod(DigraphPeriphery, "for a digraph", +[IsDigraph], +D -> DigraphDistanceMetrics(D).Periphery); \ No newline at end of file diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index 53e3126d1..1b2db89fd 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -3173,6 +3173,14 @@ true gap> B[14, 15] = z; true +# DigraphDistanceMetrics +gap> DigraphRadius(CycleDigraph(5)); +4 +gap> DigraphCentre(Digraph([[2], [3], [1]])); +[ 1, 2, 3 ] +gap> DigraphPeriphery(CycleDigraph(13)); +[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ] + # DigraphAbsorptionProbabilities gap> gr := Digraph([[2, 3, 4], [3], [2], []]);