Skip to content

Commit 49e5ef5

Browse files
committed
Resolved comments on original function.
1 parent cff2149 commit 49e5ef5

File tree

2 files changed

+30
-59
lines changed

2 files changed

+30
-59
lines changed

gap/oper.gi

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -797,82 +797,53 @@ InstallMethod(AmalgamDigraphs,
797797
"for a digraph, a digraph, a list, and a list",
798798
[IsDigraph, IsDigraph, IsList, IsList],
799799
function(D1, D2, subdigraphVertices1, subdigraphVertices2)
800-
local D, map, vertex, vertexList, size, iterator, edgeList, edge;
800+
local D, n, map, T, vertex, edge;
801801

802802
if not InducedSubdigraph(DigraphImmutableCopyIfMutable(D1),
803-
subdigraphVertices1) =
803+
subdigraphVertices1) =
804804
InducedSubdigraph(DigraphImmutableCopyIfMutable(D2),
805805
subdigraphVertices2) then
806806
ErrorNoReturn(
807-
"the subdigraph induced by the 3rd argument (a list) in the 1st ",
808-
"argument (a digraph) does not equal the subdigraph induced by the ",
809-
"4th argument (a list) in the 2nd argument (a digraph)");
807+
"the subdigraph induced by the 3rd argument (a list) in the 1st ",
808+
"argument (a digraph) does not equal the subdigraph induced by the ",
809+
"4th argument (a list) in the 2nd argument (a digraph)");
810810
fi;
811811

812-
# Create a mutable copy so that the function also works on
813-
# immutable input digraphs and also does not change mutable
814-
# digraphs in place.
815-
D := DigraphMutableCopy(D1);
812+
# Create a mutable copy so that the function also works if
813+
# D1 is immutable. If D1 is a mutable digraph then
814+
# D1 will be changed in place.
815+
D := DigraphMutableCopyIfImmutable(D1);
816+
817+
n := DigraphNrVertices(D2) + DigraphNrVertices(D1);
818+
n := n - Length(subdigraphVertices1);
816819

817820
# 'map' is a mapping from the vertices of D2 to the vertices of the
818821
# final output graph. The idea is to map the subdigraph vertices of D2
819822
# onto the subdigraph vertices of D1 and then map the rest of the vertices
820823
# of D2 to other (higher) values. The mapping from D1 to the output graph
821824
# can be understood as the identity mapping.
822-
map := [1 .. DigraphNrVertices(D2)];
825+
826+
map := [1 .. n];
823827

824828
for vertex in [1 .. Length(subdigraphVertices1)] do
825829
map[subdigraphVertices2[vertex]] := subdigraphVertices1[vertex];
826830
od;
827831

828-
# Delete??
829-
# vertexList := Difference(DigraphVertices(D2), subdigraphVertices2);
830-
# size := DigraphNrVertices(D1);
831-
# iterator := 1;
832-
# for vertex in vertexList do
833-
# map[vertex] := iterator + size;
834-
# iterator := iterator + 1;
835-
# od;
836-
837-
838-
iterator := 1;
839-
for edge in [1 .. DigraphNrEdges(D2)] do
840-
Add(edgeList, []);
841-
for vertex in [1, 2] do
842-
if DigraphEdges(D2)[edge][vertex] in subdigraphVertices2 then
843-
DigraphEdges(D2)[edge][vertex] := DigraphEdges(D2)[edge][vertex] ^ Transformation(map);
844-
else
845-
DigraphEdges(D2)[edge][vertex] := # But we still need a mapping for the non-subdigraph vertices
846-
fi;
847-
od;
848-
od;
832+
map{Difference(DigraphVertices(D2), subdigraphVertices2)} :=
833+
[DigraphNrVertices(D1) + 1 .. n];
849834

835+
T := Transformation(map);
850836

837+
DigraphAddVertices(D, DigraphNrVertices(D2) - Length(subdigraphVertices1));
851838

852-
# The problem with adding edges to the output graph was that the
853-
# edges of the subdigraph were added twice, creating multiple
854-
# edges between certain pairs of points. A quick and readable fix
855-
# would have been to use DigraphRemoveAllMultipleEdges, but I decided
856-
# to check each of the edges being added to see if they were already
857-
# in the subdigraph. This way the function does not end up adding edges
858-
# only to delete them later.
859-
860-
# edgeList := ShallowCopy(DigraphEdges(D2));
861-
# iterator := 1;
862-
# while iterator <= Length(edgeList) do
863-
# if edgeList[iterator][1] in subdigraphVertices2 and
864-
# edgeList[iterator][2] in subdigraphVertices2 then
865-
# Remove(edgeList, iterator);
866-
# else
867-
# edgeList[iterator] := [
868-
# map.(edgeList[iterator][1]), map.(edgeList[iterator][2])];
869-
# iterator := iterator + 1;
870-
# fi;
871-
# od;
839+
for edge in DigraphEdges(D2) do
840+
if not (edge[1] in subdigraphVertices2
841+
and edge[2] in subdigraphVertices2) then
842+
DigraphAddEdge(D, [edge[1] ^ T, edge[2] ^ T]);
843+
fi;
844+
od;
872845

873-
DigraphAddVertices(D, DigraphNrVertices(D2) - Length(subdigraphVertices1));
874-
DigraphAddEdges(D, edgeList);
875-
return [Immutable(DigraphRemoveAllMultipleEdges(D)), map];
846+
return [MakeImmutable(D), T];
876847
end);
877848

878849
###############################################################################

tst/standard/oper.tst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,24 +2762,24 @@ gap> D1 := Digraph([[2, 3], [1, 3], [1, 2], [2], [3, 4]]);;
27622762
gap> D2 := Digraph([[2, 6], [1, 3, 5], [4], [3], [4, 6], [1, 5]]);;
27632763
gap> U := AmalgamDigraphs(D1, D2, [2, 3, 4, 5], [4, 3, 5, 2]);
27642764
[ <immutable digraph with 7 vertices, 15 edges>,
2765-
rec( 1 := 6, 2 := 5, 3 := 3, 4 := 2, 5 := 4, 6 := 7 ) ]
2765+
Transformation( [ 6, 5, 3, 2, 4, 7, 7 ] ) ]
27662766
gap> D1 := Digraph([
27672767
> [2, 3], [1, 3, 4, 6], [1, 2, 5, 7], [2, 6], [3, 7], [2, 4, 7, 8],
27682768
> [3, 5, 6, 8], [6, 7]]);;
27692769
gap> D2 := Digraph([
27702770
> [2, 3], [1, 4], [1, 5], [2, 5, 6], [3, 4, 7], [4, 7], [5, 6]]);;
27712771
gap> U := AmalgamDigraphs(D1, D2, [2, 3, 6, 7], [4, 5, 6, 7]);
27722772
[ <immutable digraph with 11 vertices, 32 edges>,
2773-
rec( 1 := 9, 2 := 10, 3 := 11, 4 := 2, 5 := 3, 6 := 6, 7 := 7 ) ]
2773+
Transformation( [ 9, 10, 11, 2, 3, 6, 7, 8, 9, 10, 11 ] ) ]
27742774
gap> AmalgamDigraphs(D1, D2, [3, 6, 2, 7], [4, 5, 7, 6]);
27752775
Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\
27762776
(a digraph) does not equal the subdigraph induced by the 4th argument (a list\
27772777
) in the 2nd argument (a digraph)
27782778
gap> D1 := PetersenGraph();;
27792779
gap> U := AmalgamDigraphs(D1, D1, [3, 4, 6, 8, 9], [3, 4, 6, 8, 9]);
27802780
[ <immutable digraph with 15 vertices, 50 edges>,
2781-
rec( 1 := 11, 10 := 15, 2 := 12, 3 := 3, 4 := 4, 5 := 13, 6 := 6, 7 := 14,
2782-
8 := 8, 9 := 9 ) ]
2781+
Transformation( [ 11, 12, 3, 4, 13, 6, 14, 8, 9, 15, 11, 12, 13, 14, 15 ] )
2782+
]
27832783

27842784
# AmalgamDigraphsIsomorphic
27852785
gap> D1 := PetersenGraph();;
@@ -2789,7 +2789,7 @@ gap> D2 := Digraph([
27892789
gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 6, 8, 9],
27902790
> [2, 4, 5, 6, 7]);
27912791
[ <immutable digraph with 13 vertices, 42 edges>,
2792-
rec( 1 := 11, 2 := 3, 3 := 12, 4 := 4, 5 := 8, 6 := 9, 7 := 6, 8 := 13 ) ]
2792+
Transformation( [ 11, 3, 12, 4, 8, 9, 6, 13, 9, 10, 11, 12, 13 ] ) ]
27932793
gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 10, 8, 9],
27942794
> [2, 4, 5, 6, 7]);
27952795
Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\

0 commit comments

Comments
 (0)