Skip to content
5 changes: 5 additions & 0 deletions gap/attr.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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);
39 changes: 39 additions & 0 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

@james-d-mitchell james-d-mitchell Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think G should be changed to D everywhere here, for consistency.

local ecc, c, u, v;
if not IsDigraph(G) then
Error("Input must be a digraph");
elif not IsStronglyConnectedDigraph(G) then
Comment on lines +3439 to +3441
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not IsDigraph(G) then
Error("Input must be a digraph");
elif not IsStronglyConnectedDigraph(G) then
if not IsStronglyConnectedDigraph(G) then

The first if clause is redundant.

Error("Input digraph is not strongly connected; property undefined");
Copy link
Member

@james-d-mitchell james-d-mitchell Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error("Input digraph is not strongly connected; property undefined");
ErrorNoReturn("the argument <G> (a digraph) must be strongly connected");

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please make a similar change for the error message a few lines above.

fi;
ecc := [];
for u in [1 .. DigraphNrVertices(G)] do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for u in [1 .. DigraphNrVertices(G)] do
for u in DigraphVertices(G) do

c := 0;
for v in [1 .. DigraphNrVertices(G)] do
Copy link
Member

@james-d-mitchell james-d-mitchell Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for v in [1 .. DigraphNrVertices(G)] do
for v in DigraphVertices(G) do

if u <> v then
c := Maximum(c, DigraphShortestDistance(G, u, v));
fi;
od;
Add(ecc, c);
od;
return rec(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure but I think the following is not particularly efficient because the computation of Minimum(ecc) and Maximum(ecc) will be repeated for each distinct value of i which is not such a good idea. Better to compute these values prior to this return statement.

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);
8 changes: 8 additions & 0 deletions tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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], []]);
<immutable digraph with 4 vertices, 5 edges>
Expand Down
Loading