Skip to content

Digraph distance attributes #761

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
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)
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);
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