@@ -765,80 +765,163 @@ function(D1, D2, edge_function)
765
765
return Digraph(edges);
766
766
end );
767
767
768
- InstallMethod(AmalgamDigraphsIsomorphic ,
768
+ InstallMethod(AmalgamDigraphs ,
769
769
" for a digraph, a digraph, a list, and a list" ,
770
- [ IsDigraph, IsDigraph, IsList, IsList ] ,
771
- function (D1, D2, subdigraphVertices1, subdigraphVertices2 )
772
- local subdigraph1, subdigraph2, newSubdigraphVertices2, transformation, vertex ;
770
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation, IsTransformation ] ,
771
+ function (D1, D2, S, map1, map2 )
772
+ local D, n, imageList1, imageList2, map, edge, T ;
773
773
774
- subdigraph1 := InducedSubdigraph(DigraphImmutableCopyIfMutable(D1),
775
- subdigraphVertices1);
776
- subdigraph2 := InducedSubdigraph(DigraphImmutableCopyIfMutable(D2),
777
- subdigraphVertices2);
774
+ if IsMultiDigraph(D1) then
775
+ ErrorNoReturn(
776
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
777
+ elif IsMultiDigraph(D2) then
778
+ ErrorNoReturn(
779
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
780
+ elif IsMultiDigraph(S) then
781
+ ErrorNoReturn(
782
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
783
+ fi ;
778
784
779
- if not IsIsomorphicDigraph(subdigraph1, subdigraph2 ) then
785
+ if not IsDigraphEmbedding(S, D1, map1 ) then
780
786
ErrorNoReturn(
781
- " the subdigraph induced by the 3rd argument (a list) in the 1st " ,
782
- " argument ( a digraph) is not ismorphic to the subdigraph induced " ,
783
- " by the 4th argument (a list) in the 2nd argument (a digraph)" );
787
+ " the 4th argument (a transformation) is not " ,
788
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
789
+ " the 1st argument (a digraph)" );
784
790
fi ;
791
+ if not IsDigraphEmbedding(S, D2, map2) then
792
+ ErrorNoReturn(
793
+ " the 5th argument (a transformation) is not " ,
794
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
795
+ " the 2nd argument (a digraph)" );
796
+ fi ;
797
+
798
+ # Create a mutable copy so that the function also works if
799
+ # D1 is immutable. If D1 is a mutable digraph then
800
+ # D1 will be changed in place.
801
+ D := DigraphMutableCopyIfImmutable(D1);
802
+
803
+ n := DigraphNrVertices(D2) + DigraphNrVertices(D1) - DigraphNrVertices(S);
804
+
805
+ # 'map' is an embedding of D2 into the final output graph.
806
+ # The embedding of D1 into the final output graph is the identity mapping.
785
807
786
- newSubdigraphVertices2 := [] ;
787
- transformation := DigraphEmbedding(subdigraph2, subdigraph1);
788
- for vertex in subdigraphVertices2 do
789
- newSubdigraphVertices2[
790
- Position(subdigraphVertices2, vertex) ^ transformation] := vertex;
808
+ map := [ 1 .. n] ;
809
+
810
+ imageList1 := OnTuples([ 1 .. DigraphNrVertices(S)] , map1);
811
+ imageList2 := OnTuples([ 1 .. DigraphNrVertices(S)] , map2);
812
+
813
+ map{ imageList2} := imageList1;
814
+ map{ Difference(DigraphVertices(D2), imageList2)} :=
815
+ [ DigraphNrVertices(D1) + 1 .. n] ;
816
+
817
+ T := Transformation(map);
818
+
819
+ DigraphAddVertices(D, DigraphNrVertices(D2) - DigraphNrVertices(S));
820
+
821
+ for edge in DigraphEdges(D2) do
822
+ if not (edge[ 1 ] in imageList2
823
+ and edge[ 2 ] in imageList2) then
824
+ DigraphAddEdge(D, [ edge[ 1 ] ^ T, edge[ 2 ] ^ T] );
825
+ fi ;
791
826
od ;
792
827
793
- return AmalgamDigraphs(D1, D2, subdigraphVertices1, newSubdigraphVertices2);
828
+ return [ MakeImmutable(D), T] ;
829
+ end );
830
+
831
+ InstallMethod(AmalgamDigraphs,
832
+ " for a digraph, a digraph, a list, and a list" ,
833
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation] ,
834
+ function (D1, D2, S, map1 )
835
+ local map2;
836
+
837
+ if IsMultiDigraph(D1) then
838
+ ErrorNoReturn(
839
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
840
+ elif IsMultiDigraph(D2) then
841
+ ErrorNoReturn(
842
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
843
+ elif IsMultiDigraph(S) then
844
+ ErrorNoReturn(
845
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
846
+ fi ;
847
+
848
+ if not IsDigraphEmbedding(S, D1, map1) then
849
+ ErrorNoReturn(
850
+ " the 4th argument (a transformation) is not " ,
851
+ " a digraph embedding from the 3rd argument (a digraph) into " ,
852
+ " the 1st argument (a digraph)" );
853
+ fi ;
854
+
855
+ map2 := DigraphEmbedding(S, D2);
856
+ if map2 = fail then
857
+ ErrorNoReturn(
858
+ " no embeddings could be found from the 3rd argument " ,
859
+ " (a digraph) to the 2nd argument (a digraph)" );
860
+ fi ;
861
+
862
+ return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
794
863
end );
795
864
796
865
InstallMethod(AmalgamDigraphs,
797
866
" for a digraph, a digraph, a list, and a list" ,
798
- [ IsDigraph, IsDigraph, IsList, IsList] ,
799
- function (D1, D2, subdigraphVertices1, subdigraphVertices2 )
800
- local D, n, map, T, vertex, edge;
801
-
802
- if not InducedSubdigraph(DigraphImmutableCopyIfMutable(D1),
803
- subdigraphVertices1) =
804
- InducedSubdigraph(DigraphImmutableCopyIfMutable(D2),
805
- subdigraphVertices2) then
867
+ [ IsDigraph, IsDigraph, IsDigraph] ,
868
+ function (D1, D2, S )
869
+ local map1, map2;
870
+
871
+ if IsMultiDigraph(D1) then
872
+ ErrorNoReturn(
873
+ " the 1st argument (a digraph) must not satisfy IsMultiDigraph" );
874
+ elif IsMultiDigraph(D2) then
875
+ ErrorNoReturn(
876
+ " the 2nd argument (a digraph) must not satisfy IsMultiDigraph" );
877
+ elif IsMultiDigraph(S) then
806
878
ErrorNoReturn(
807
- " the subdigraph induced by the 3rd argument (a list) in the 1st " ,
808
- " argument (a digraph) does not equal the subdigraph induced by the " ,
809
- " 4th argument (a list) in the 2nd argument (a digraph)" );
879
+ " the 3rd argument (a digraph) must not satisfy IsMultiDigraph" );
810
880
fi ;
811
881
812
- # Create a mutable copy so that the function also works if
813
- # D1 is immutable. If D1 is a mutable digraph then
814
- # D1 will be changed in place.
815
- D := DigraphMutableCopyIfImmutable(D1);
882
+ map1 := DigraphEmbedding(S, D1);
883
+ if map1 = fail then
884
+ ErrorNoReturn(
885
+ " no embeddings could be found from the 3rd argument " ,
886
+ " (a digraph) to the 1st argument (a digraph)" );
887
+ fi ;
816
888
817
- n := DigraphNrVertices(D2) + DigraphNrVertices(D1);
818
- n := n - Length(subdigraphVertices1);
889
+ map2 := DigraphEmbedding(S, D2);
890
+ if map2 = fail then
891
+ ErrorNoReturn(
892
+ " no embeddings could be found from the 3rd argument " ,
893
+ " (a digraph) to the 2nd argument (a digraph)" );
894
+ fi ;
819
895
820
- # 'map' is a mapping from the vertices of D2 to the vertices of the
821
- # final output graph. The idea is to map the subdigraph vertices of D2
822
- # onto the subdigraph vertices of D1 and then map the rest of the vertices
823
- # of D2 to other (higher) values. The mapping from D1 to the output graph
824
- # can be understood as the identity mapping.
896
+ return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
897
+ end );
898
+
899
+ InstallMethod(NOCHECKS_AmalgamDigraphs,
900
+ " for a digraph, a digraph, a list, and a list" ,
901
+ [ IsDigraph, IsDigraph, IsDigraph, IsTransformation, IsTransformation] ,
902
+ function (D1, D2, S, map1, map2 )
903
+ local D, n, imageList1, imageList2, map, edge, T;
904
+
905
+ D := DigraphMutableCopyIfImmutable(D1);
906
+
907
+ n := DigraphNrVertices(D2) + DigraphNrVertices(D1) - DigraphNrVertices(S);
825
908
826
909
map := [ 1 .. n] ;
827
910
828
- for vertex in [ 1 .. Length(subdigraphVertices1)] do
829
- map[ subdigraphVertices2[ vertex]] := subdigraphVertices1[ vertex] ;
830
- od ;
911
+ imageList1 := OnTuples([ 1 .. DigraphNrVertices(S)] , map1);
912
+ imageList2 := OnTuples([ 1 .. DigraphNrVertices(S)] , map2);
831
913
832
- map{ Difference(DigraphVertices(D2), subdigraphVertices2)} :=
914
+ map{ imageList2} := imageList1;
915
+ map{ Difference(DigraphVertices(D2), imageList2)} :=
833
916
[ DigraphNrVertices(D1) + 1 .. n] ;
834
917
835
918
T := Transformation(map);
836
919
837
- DigraphAddVertices(D, DigraphNrVertices(D2) - Length(subdigraphVertices1 ));
920
+ DigraphAddVertices(D, DigraphNrVertices(D2) - DigraphNrVertices(S ));
838
921
839
922
for edge in DigraphEdges(D2) do
840
- if not (edge[ 1 ] in subdigraphVertices2
841
- and edge[ 2 ] in subdigraphVertices2 ) then
923
+ if not (edge[ 1 ] in imageList2
924
+ and edge[ 2 ] in imageList2 ) then
842
925
DigraphAddEdge(D, [ edge[ 1 ] ^ T, edge[ 2 ] ^ T] );
843
926
fi ;
844
927
od ;
0 commit comments