@@ -797,7 +797,7 @@ InstallMethod(AmalgamDigraphs,
797797" for a digraph, a digraph, a list, and a list" ,
798798[ IsDigraph, IsDigraph, IsList, IsList] ,
799799function (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] ;
859876end );
860877
861878# ##############################################################################
0 commit comments