diff --git a/gap/oper.gi b/gap/oper.gi index d368e5595..68f11077a 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -797,7 +797,7 @@ InstallMethod(AmalgamDigraphs, "for a digraph, a digraph, a list, and a list", [IsDigraph, IsDigraph, IsList, IsList], function(D1, D2, subdigraphVertices1, subdigraphVertices2) - local D, map, vertex, vertexList, size, iterator, edgeList; + local D, map, vertex, vertexList, size, iterator, edgeList, edge; if not InducedSubdigraph(DigraphImmutableCopyIfMutable(D1), subdigraphVertices1) = @@ -810,7 +810,8 @@ function(D1, D2, subdigraphVertices1, subdigraphVertices2) fi; # Create a mutable copy so that the function also works on - # immutable input digraphs. + # immutable input digraphs and also does not change mutable + # digraphs in place. D := DigraphMutableCopy(D1); # 'map' is a mapping from the vertices of D2 to the vertices of the @@ -818,21 +819,36 @@ function(D1, D2, subdigraphVertices1, subdigraphVertices2) # onto the subdigraph vertices of D1 and then map the rest of the vertices # of D2 to other (higher) values. The mapping from D1 to the output graph # can be understood as the identity mapping. - map := rec(); + map := [1 .. DigraphNrVertices(D2)]; for vertex in [1 .. Length(subdigraphVertices1)] do - map.(subdigraphVertices2[vertex]) := subdigraphVertices1[vertex]; + map[subdigraphVertices2[vertex]] := subdigraphVertices1[vertex]; od; # Delete?? - vertexList := Difference(DigraphVertices(D2), subdigraphVertices2); - size := DigraphNrVertices(D1); + # vertexList := Difference(DigraphVertices(D2), subdigraphVertices2); + # size := DigraphNrVertices(D1); + # iterator := 1; + # for vertex in vertexList do + # map[vertex] := iterator + size; + # iterator := iterator + 1; + # od; + + iterator := 1; - for vertex in vertexList do - map.(vertex) := iterator + size; - iterator := iterator + 1; + for edge in [1 .. DigraphNrEdges(D2)] do + Add(edgeList, []); + for vertex in [1, 2] do + if DigraphEdges(D2)[edge][vertex] in subdigraphVertices2 then + DigraphEdges(D2)[edge][vertex] := DigraphEdges(D2)[edge][vertex] ^ Transformation(map); + else + DigraphEdges(D2)[edge][vertex] := # But we still need a mapping for the non-subdigraph vertices + fi; + od; od; + + # The problem with adding edges to the output graph was that the # edges of the subdigraph were added twice, creating multiple # edges between certain pairs of points. A quick and readable fix @@ -840,22 +856,23 @@ function(D1, D2, subdigraphVertices1, subdigraphVertices2) # to check each of the edges being added to see if they were already # in the subdigraph. This way the function does not end up adding edges # only to delete them later. - edgeList := ShallowCopy(DigraphEdges(D2)); - iterator := 1; - while iterator <= Length(edgeList) do - if edgeList[iterator][1] in subdigraphVertices2 and - edgeList[iterator][2] in subdigraphVertices2 then - Remove(edgeList, iterator); - else - edgeList[iterator] := [ - map.(edgeList[iterator][1]), map.(edgeList[iterator][2])]; - iterator := iterator + 1; - fi; - od; + + # edgeList := ShallowCopy(DigraphEdges(D2)); + # iterator := 1; + # while iterator <= Length(edgeList) do + # if edgeList[iterator][1] in subdigraphVertices2 and + # edgeList[iterator][2] in subdigraphVertices2 then + # Remove(edgeList, iterator); + # else + # edgeList[iterator] := [ + # map.(edgeList[iterator][1]), map.(edgeList[iterator][2])]; + # iterator := iterator + 1; + # fi; + # od; DigraphAddVertices(D, DigraphNrVertices(D2) - Length(subdigraphVertices1)); DigraphAddEdges(D, edgeList); - return [Immutable(D), map]; + return [Immutable(DigraphRemoveAllMultipleEdges(D)), map]; end); ############################################################################### diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index 48baca7f7..492bd614d 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -2772,7 +2772,9 @@ gap> U := AmalgamDigraphs(D1, D2, [2, 3, 6, 7], [4, 5, 6, 7]); [ , rec( 1 := 9, 2 := 10, 3 := 11, 4 := 2, 5 := 3, 6 := 6, 7 := 7 ) ] gap> AmalgamDigraphs(D1, D2, [3, 6, 2, 7], [4, 5, 7, 6]); -Error, the two subdigraphs must be equal. +Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\ + (a digraph) does not equal the subdigraph induced by the 4th argument (a list\ +) in the 2nd argument (a digraph) gap> D1 := PetersenGraph();; gap> U := AmalgamDigraphs(D1, D1, [3, 4, 6, 8, 9], [3, 4, 6, 8, 9]); [ , @@ -2790,7 +2792,9 @@ gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 6, 8, 9], rec( 1 := 11, 2 := 3, 3 := 12, 4 := 4, 5 := 8, 6 := 9, 7 := 6, 8 := 13 ) ] gap> U := AmalgamDigraphsIsomorphic(D1, D2, [3, 4, 10, 8, 9], > [2, 4, 5, 6, 7]); -Error, the two subdigraphs must be isomorphic. +Error, the subdigraph induced by the 3rd argument (a list) in the 1st argument\ + (a digraph) is not ismorphic to the subdigraph induced by the 4th argument (a\ + list) in the 2nd argument (a digraph) #DIGRAPHS_UnbindVariables gap> Unbind(a);