Skip to content

Commit

Permalink
Attempt to change over to Transformation.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbuck committed Apr 5, 2022
1 parent 3ec1aae commit cff2149
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
61 changes: 39 additions & 22 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -810,52 +810,69 @@ 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
# final output graph. The idea is to map the subdigraph vertices of D2
# 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
# would have been to use DigraphRemoveAllMultipleEdges, but I decided
# 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);

###############################################################################
Expand Down
8 changes: 6 additions & 2 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,9 @@ gap> U := AmalgamDigraphs(D1, D2, [2, 3, 6, 7], [4, 5, 6, 7]);
[ <immutable digraph with 11 vertices, 32 edges>,
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]);
[ <immutable digraph with 15 vertices, 50 edges>,
Expand All @@ -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);
Expand Down

0 comments on commit cff2149

Please sign in to comment.