Skip to content

Commit

Permalink
Resolve issue #676
Browse files Browse the repository at this point in the history
Properly transfer the original vertices as labels of the vertices in the
reduced graph in DigraphAllSimpleCircuits.
  • Loading branch information
james-d-mitchell committed Aug 28, 2024
1 parent 15f8517 commit 039d9e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ InstallMethod(DigraphAllSimpleCircuits, "for a digraph by out-neighbours",
[IsDigraphByOutNeighboursRep],
function(D)
local UNBLOCK, CIRCUIT, out, stack, endofstack, C, scc, n, blocked, B,
c_comp, comp, s, loops, i;
c_comp, comp, s, loops, i, d_labels, c_labels;

if IsEmptyDigraph(D) then
return [];
Expand Down Expand Up @@ -1455,9 +1455,15 @@ function(D)
# Reduce the D, remove loops, and store the correct vertex labels
C := DigraphRemoveLoops(ReducedDigraph(DigraphMutableCopyIfMutable(D)));
MakeImmutable(C);
if DigraphVertexLabels(D) <> DigraphVertices(D) then
SetDigraphVertexLabels(C, Filtered(DigraphVertices(D),
x -> OutDegrees(D) <> 0));
if HaveVertexLabelsBeenAssigned(D)
and DigraphVertexLabels(D) <> DigraphVertices(D) then
# We require the labels of the digraph <C> to be the original nodes in <D>
# (this is used in CIRCUIT above). If <D> has other vertex labels, then
# these are copied into <C> by the functions above, and aren't then
# necessarily the original nodes in <D>.
d_labels := DigraphVertexLabels(D);
c_labels := List(DigraphVertexLabels(C), x -> Position(d_labels, x));
SetDigraphVertexLabels(C, c_labels);
fi;

# Strongly connected components of the reduced graph
Expand Down
1 change: 1 addition & 0 deletions gap/labels.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Get vertex labels
DeclareOperation("DigraphVertexLabel", [IsDigraph, IsPosInt]);
DeclareOperation("DigraphVertexLabels", [IsDigraph]);
DeclareOperation("HaveVertexLabelsBeenAssigned", [IsDigraph]);

# Set vertex labels
DeclareOperation("SetDigraphVertexLabel", [IsDigraph, IsPosInt, IsObject]);
Expand Down
3 changes: 3 additions & 0 deletions gap/labels.gi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function(D, v)
"is not a vertex of the digraph <D> that is the 1st argument");
end);

InstallMethod(HaveVertexLabelsBeenAssigned, "for a digraph", [IsDigraph],
D -> IsBound(D!.vertexlabels));

InstallMethod(RemoveDigraphVertexLabel, "for a digraph and positive integer",
[IsDigraph, IsPosInt],
function(D, v)
Expand Down

0 comments on commit 039d9e4

Please sign in to comment.