@@ -989,6 +989,170 @@ function(D1, D2, edge_function)
989
989
return Digraph(edges);
990
990
end );
991
991
992
+ InstallMethod(AmalgamDigraphs,
993
+ " for a digraph, a digraph, a digraph, a transformation, and a transformation" ,
994
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation, IsTransformation] ,
995
+ function (D1, D2, S, map1, map2 )
996
+ local D, n, imageList1, imageList2, map, edge, T;
997
+
998
+ if IsMultiDigraph(D1) then
999
+ ErrorNoReturn(
1000
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
1001
+ elif IsMultiDigraph(D2) then
1002
+ ErrorNoReturn(
1003
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
1004
+ elif IsMultiDigraph(S) then
1005
+ ErrorNoReturn(
1006
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
1007
+ fi ;
1008
+
1009
+ if not IsDigraphEmbedding(S, D1, map1) then
1010
+ ErrorNoReturn(
1011
+ " the 4th argument (a transformation) is not " ,
1012
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
1013
+ " the 1st argument (a digraph)" );
1014
+ fi ;
1015
+ if not IsDigraphEmbedding(S, D2, map2) then
1016
+ ErrorNoReturn(
1017
+ " the 5th argument (a transformation) is not " ,
1018
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
1019
+ " the 2nd argument (a digraph)" );
1020
+ fi ;
1021
+
1022
+ # Create a mutable copy so that the function also works if
1023
+ # D1 is immutable. If D1 is a mutable digraph then
1024
+ # D1 will be changed in place.
1025
+ D := DigraphMutableCopyIfImmutable(D1);
1026
+
1027
+ n := DigraphNrVertices(D2) + DigraphNrVertices(D1) - DigraphNrVertices(S);
1028
+
1029
+ # 'map' is an embedding of D2 into the final output graph.
1030
+ # The embedding of D1 into the final output graph is the identity mapping.
1031
+
1032
+ map := [ 1 .. n] ;
1033
+
1034
+ imageList1 := OnTuples([ 1 .. DigraphNrVertices(S)] , map1);
1035
+ imageList2 := OnTuples([ 1 .. DigraphNrVertices(S)] , map2);
1036
+
1037
+ map{ imageList2} := imageList1;
1038
+ map{ Difference(DigraphVertices(D2), imageList2)} :=
1039
+ [ DigraphNrVertices(D1) + 1 .. n] ;
1040
+
1041
+ T := Transformation(map);
1042
+
1043
+ DigraphAddVertices(D, DigraphNrVertices(D2) - DigraphNrVertices(S));
1044
+
1045
+ for edge in DigraphEdges(D2) do
1046
+ if not (edge[ 1 ] in imageList2
1047
+ and edge[ 2 ] in imageList2) then
1048
+ DigraphAddEdge(D, [ edge[ 1 ] ^ T, edge[ 2 ] ^ T] );
1049
+ fi ;
1050
+ od ;
1051
+
1052
+ return [ MakeImmutable(D), T] ;
1053
+ end );
1054
+
1055
+ InstallMethod(AmalgamDigraphs,
1056
+ " for a digraph, a digraph, a digraph, and a transformation" ,
1057
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation] ,
1058
+ function (D1, D2, S, map1 )
1059
+ local map2;
1060
+
1061
+ if IsMultiDigraph(D1) then
1062
+ ErrorNoReturn(
1063
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
1064
+ elif IsMultiDigraph(D2) then
1065
+ ErrorNoReturn(
1066
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
1067
+ elif IsMultiDigraph(S) then
1068
+ ErrorNoReturn(
1069
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
1070
+ fi ;
1071
+
1072
+ if not IsDigraphEmbedding(S, D1, map1) then
1073
+ ErrorNoReturn(
1074
+ " the 4th argument (a transformation) is not " ,
1075
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
1076
+ " the 1st argument (a digraph)" );
1077
+ fi ;
1078
+
1079
+ map2 := DigraphEmbedding(S, D2);
1080
+ if map2 = fail then
1081
+ ErrorNoReturn(
1082
+ " no embeddings could be found from the 3rd argument " ,
1083
+ " (a digraph) to the 2nd argument (a digraph)" );
1084
+ fi ;
1085
+
1086
+ return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
1087
+ end );
1088
+
1089
+ InstallMethod(AmalgamDigraphs,
1090
+ " for a digraph, a digraph, and a digraph" ,
1091
+ [ IsDigraph, IsDigraph, IsDigraph] ,
1092
+ function (D1, D2, S )
1093
+ local map1, map2;
1094
+
1095
+ if IsMultiDigraph(D1) then
1096
+ ErrorNoReturn(
1097
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
1098
+ elif IsMultiDigraph(D2) then
1099
+ ErrorNoReturn(
1100
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
1101
+ elif IsMultiDigraph(S) then
1102
+ ErrorNoReturn(
1103
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
1104
+ fi ;
1105
+
1106
+ map1 := DigraphEmbedding(S, D1);
1107
+ if map1 = fail then
1108
+ ErrorNoReturn(
1109
+ " no embeddings could be found from the 3rd argument " ,
1110
+ " (a digraph) to the 1st argument (a digraph)" );
1111
+ fi ;
1112
+
1113
+ map2 := DigraphEmbedding(S, D2);
1114
+ if map2 = fail then
1115
+ ErrorNoReturn(
1116
+ " no embeddings could be found from the 3rd argument " ,
1117
+ " (a digraph) to the 2nd argument (a digraph)" );
1118
+ fi ;
1119
+
1120
+ return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
1121
+ end );
1122
+
1123
+ InstallMethod(NOCHECKS_AmalgamDigraphs,
1124
+ " for a digraph, a digraph, a digraph, a transformation, and a transformation" ,
1125
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation, IsTransformation] ,
1126
+ function (D1, D2, S, map1, map2 )
1127
+ local D, n, imageList1, imageList2, map, edge, T;
1128
+
1129
+ D := DigraphMutableCopyIfImmutable(D1);
1130
+
1131
+ n := DigraphNrVertices(D2) + DigraphNrVertices(D1) - DigraphNrVertices(S);
1132
+
1133
+ map := [ 1 .. n] ;
1134
+
1135
+ imageList1 := OnTuples([ 1 .. DigraphNrVertices(S)] , map1);
1136
+ imageList2 := OnTuples([ 1 .. DigraphNrVertices(S)] , map2);
1137
+
1138
+ map{ imageList2} := imageList1;
1139
+ map{ Difference(DigraphVertices(D2), imageList2)} :=
1140
+ [ DigraphNrVertices(D1) + 1 .. n] ;
1141
+
1142
+ T := Transformation(map);
1143
+
1144
+ DigraphAddVertices(D, DigraphNrVertices(D2) - DigraphNrVertices(S));
1145
+
1146
+ for edge in DigraphEdges(D2) do
1147
+ if not (edge[ 1 ] in imageList2
1148
+ and edge[ 2 ] in imageList2) then
1149
+ DigraphAddEdge(D, [ edge[ 1 ] ^ T, edge[ 2 ] ^ T] );
1150
+ fi ;
1151
+ od ;
1152
+
1153
+ return [ MakeImmutable(D), T] ;
1154
+ end );
1155
+
992
1156
# ##############################################################################
993
1157
# 4. Actions
994
1158
# ##############################################################################
0 commit comments