Skip to content

Commit cff2149

Browse files
committed
Attempt to change over to Transformation.
1 parent 3ec1aae commit cff2149

File tree

2 files changed

+45
-24
lines changed

2 files changed

+45
-24
lines changed

gap/oper.gi

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ 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;
800+
local D, map, vertex, vertexList, size, iterator, edgeList, edge;
801801

802802
if not InducedSubdigraph(DigraphImmutableCopyIfMutable(D1),
803803
subdigraphVertices1) =
@@ -810,52 +810,69 @@ function(D1, D2, subdigraphVertices1, subdigraphVertices2)
810810
fi;
811811

812812
# Create a mutable copy so that the function also works on
813-
# immutable input digraphs.
813+
# immutable input digraphs and also does not change mutable
814+
# digraphs in place.
814815
D := DigraphMutableCopy(D1);
815816

816817
# 'map' is a mapping from the vertices of D2 to the vertices of the
817818
# final output graph. The idea is to map the subdigraph vertices of D2
818819
# onto the subdigraph vertices of D1 and then map the rest of the vertices
819820
# of D2 to other (higher) values. The mapping from D1 to the output graph
820821
# can be understood as the identity mapping.
821-
map := rec();
822+
map := [1 .. DigraphNrVertices(D2)];
822823

823824
for vertex in [1 .. Length(subdigraphVertices1)] do
824-
map.(subdigraphVertices2[vertex]) := subdigraphVertices1[vertex];
825+
map[subdigraphVertices2[vertex]] := subdigraphVertices1[vertex];
825826
od;
826827

827828
# Delete??
828-
vertexList := Difference(DigraphVertices(D2), subdigraphVertices2);
829-
size := DigraphNrVertices(D1);
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+
830838
iterator := 1;
831-
for vertex in vertexList do
832-
map.(vertex) := iterator + size;
833-
iterator := 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;
834848
od;
835849

850+
851+
836852
# The problem with adding edges to the output graph was that the
837853
# edges of the subdigraph were added twice, creating multiple
838854
# edges between certain pairs of points. A quick and readable fix
839855
# would have been to use DigraphRemoveAllMultipleEdges, but I decided
840856
# to check each of the edges being added to see if they were already
841857
# in the subdigraph. This way the function does not end up adding edges
842858
# only to delete them later.
843-
edgeList := ShallowCopy(DigraphEdges(D2));
844-
iterator := 1;
845-
while iterator <= Length(edgeList) do
846-
if edgeList[iterator][1] in subdigraphVertices2 and
847-
edgeList[iterator][2] in subdigraphVertices2 then
848-
Remove(edgeList, iterator);
849-
else
850-
edgeList[iterator] := [
851-
map.(edgeList[iterator][1]), map.(edgeList[iterator][2])];
852-
iterator := iterator + 1;
853-
fi;
854-
od;
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;
855872

856873
DigraphAddVertices(D, DigraphNrVertices(D2) - Length(subdigraphVertices1));
857874
DigraphAddEdges(D, edgeList);
858-
return [Immutable(D), map];
875+
return [Immutable(DigraphRemoveAllMultipleEdges(D)), map];
859876
end);
860877

861878
###############################################################################

tst/standard/oper.tst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,9 @@ gap> U := AmalgamDigraphs(D1, D2, [2, 3, 6, 7], [4, 5, 6, 7]);
27722772
[ <immutable digraph with 11 vertices, 32 edges>,
27732773
rec( 1 := 9, 2 := 10, 3 := 11, 4 := 2, 5 := 3, 6 := 6, 7 := 7 ) ]
27742774
gap> AmalgamDigraphs(D1, D2, [3, 6, 2, 7], [4, 5, 7, 6]);
2775-
Error, the two subdigraphs must be equal.
2775+
Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\
2776+
(a digraph) does not equal the subdigraph induced by the 4th argument (a list\
2777+
) in the 2nd argument (a digraph)
27762778
gap> D1 := PetersenGraph();;
27772779
gap> U := AmalgamDigraphs(D1, D1, [3, 4, 6, 8, 9], [3, 4, 6, 8, 9]);
27782780
[ <immutable digraph with 15 vertices, 50 edges>,
@@ -2790,7 +2792,9 @@ gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 6, 8, 9],
27902792
rec( 1 := 11, 2 := 3, 3 := 12, 4 := 4, 5 := 8, 6 := 9, 7 := 6, 8 := 13 ) ]
27912793
gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 10, 8, 9],
27922794
> [2, 4, 5, 6, 7]);
2793-
Error, the two subdigraphs must be isomorphic.
2795+
Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\
2796+
(a digraph) is not ismorphic to the subdigraph induced by the 4th argument (a\
2797+
list) in the 2nd argument (a digraph)
27942798

27952799
#DIGRAPHS_UnbindVariables
27962800
gap> Unbind(a);

0 commit comments

Comments
 (0)