@@ -727,23 +727,166 @@ function(digraph)
727727end );
728728
729729InstallMethod(DotString, " for a Cayley digraph" , [ IsCayleyDigraph] ,
730- function (digraph )
731- local S, li, label, i;
732- S := SemigroupOfCayleyDigraph(digraph);
733- if not CanUseFroidurePin(S) or Size(S) > 26 then
730+ function (D )
731+ local S, edge_colors, N, msg, legend, node_labels, offset, en, label, next,
732+ edge_func, node_func, result, i;
733+
734+ S := SemigroupOfCayleyDigraph(D);
735+ edge_colors := [ " \" #00ff00\" " , " \" #ff00ff\" " , " \" #007fff\" " , " \" #ff7f00\" " ,
736+ " \" #7fbf7f\" " , " \" #4604ac\" " , " \" #de0328\" " , " \" #19801d\" " ,
737+ " \" #d881f5\" " , " \" #00ffff\" " , " \" #ffff00\" " , " \" #00ff7f\" " ,
738+ " \" #ad5867\" " , " \" #85f610\" " , " \" #84e9f5\" " , " \" #f5c778\" " ,
739+ " \" #207090\" " , " \" #764ef3\" " , " \" #7b4c00\" " , " \" #0000ff\" " ,
740+ " \" #b80c9a\" " , " \" #601045\" " , " \" #29b7c0\" " , " \" #839f12" ] ;
741+ N := Length(GeneratorsOfSemigroup(S));
742+ if not CanUseFroidurePin(S) then
734743 TryNextMethod ();
735744 fi ;
736- li := AsListCanonical(S);
745+
746+ if IsMonoidAsSemigroup(S) and One(GeneratorsOfSemigroup(S)) in S then
747+ offset := - 1 ;
748+ else
749+ offset := 1 ;
750+ fi ;
751+
752+ node_labels := [] ;
753+ en := EnumeratorCanonical(S);
737754 for i in [ 1 .. Size(S)] do
738- label := SEMIGROUPS.WordToExtRepObj(MinimalFactorization(S, li[ i] ));
739- label := SEMIGROUPS.ExtRepObjToString(label);
740- SetDigraphVertexLabel(digraph, i, label);
755+ if IsOne(en[ i] ) then
756+ label := " ε" ;
757+ else
758+ label := SEMIGROUPS.WordToExtRepObj(MinimalFactorization(S, i) + offset);
759+ label := SEMIGROUPS.ExtRepObjToString(label);
760+ fi ;
761+ node_labels[ i] := label;
741762 od ;
742- return DotVertexLabelledDigraph(digraph);
763+
764+ legend := " node [shape=plaintext]\n subgraph cluster_01 {\n label=\" Legend\"\n " ;
765+ Append(legend, " key2 [label=<<table border=\" 0\" cellpadding=\" 2\" " );
766+ Append(legend, " cellspacing=\" 0\" cellborder=\" 0\" >\n " );
767+
768+ for i in [ 1 .. N] do
769+ Append(legend,
770+ StringFormatted(" <tr><td port=\" i{}\" > </td></tr>\n " ,
771+ i));
772+ od ;
773+ Append(legend, " </table>>]\n " );
774+ Append(legend, " key [label=<<table border=\" 0\" cellpadding=\" 2\" " );
775+ Append(legend, " cellspacing=\" 0\" cellborder=\" 0\" >\n " );
776+
777+ for i in [ 1 .. N] do
778+ label := node_labels[ i] ;
779+ next := " <tr><td align=\" right\" " ;
780+ Append(next, StringFormatted(" port=\" i{}\" >{} </td></tr>\n " , i, label));
781+ Append(legend, next);
782+ od ;
783+
784+ Append(legend, " </table>>]\n\n " );
785+
786+ for i in [ 1 .. N] do
787+ next := StringFormatted(" key:i{1}:e -> key2:i{1}:w [color={2}," ,
788+ i,
789+ edge_colors[ i] );
790+ Append(next, " constraint=false]\n " );
791+ Append(legend, next);
792+ od ;
793+ Append(legend, " }\n " );
794+
795+ node_func := i -> StringFormatted(" [label=\" {}\" ]" , node_labels[ i] );
796+ edge_func := { i, j} -> StringFormatted(" [color={}]" , edge_colors[ j] );
797+
798+ result := DIGRAPHS_DotDigraph(D, [ node_func] , [ edge_func] );
799+ result := SplitString(result, " \n " );
800+ result[ 3 ] := " subgraph 00 {" ;
801+ Add(result, " node [shape=box]" , 3 );
802+ Add(result, legend);
803+ Add(result, " }" );
804+ return JoinStringsWithSeparator(result, " \n " );
743805end );
744806
745807InstallMethod(DotLeftCayleyDigraph, " for a semigroup" , [ IsSemigroup] ,
746808S -> DotString(LeftCayleyDigraph(S)));
747809
748810InstallMethod(DotRightCayleyDigraph, " for a semigroup" , [ IsSemigroup] ,
749811S -> DotString(RightCayleyDigraph(S)));
812+
813+ InstallMethod(DotWordGraph, " for a word graph and list of edge labels" ,
814+ [ IsDigraph, IsList, IsList] ,
815+ function (D, node_labels, edge_labels )
816+ local M, N, edge_colors, msg, legend, label, next, node_func, edge_func, result, v, i;
817+
818+ if IsNullDigraph(D) then
819+ # Word graphs must have at least one node . . .
820+ ErrorNoReturn(" TODO3" );
821+ fi ;
822+
823+ M := DigraphNrVertices(D);
824+ N := Length(OutNeighboursOfVertex(D, 1 ));
825+
826+ if not IsOutRegularDigraph(D) then
827+ ErrorNoReturn(" TODO1" );
828+ elif Length(edge_labels) <> N then
829+ ErrorNoReturn(" TODO2" );
830+ fi ;
831+
832+ edge_colors := [ " \" #00ff00\" " , " \" #ff00ff\" " , " \" #007fff\" " , " \" #ff7f00\" " ,
833+ " \" #7fbf7f\" " , " \" #4604ac\" " , " \" #de0328\" " , " \" #19801d\" " ,
834+ " \" #d881f5\" " , " \" #00ffff\" " , " \" #ffff00\" " , " \" #00ff7f\" " ,
835+ " \" #ad5867\" " , " \" #85f610\" " , " \" #84e9f5\" " , " \" #f5c778\" " ,
836+ " \" #207090\" " , " \" #764ef3\" " , " \" #7b4c00\" " , " \" #0000ff\" " ,
837+ " \" #b80c9a\" " , " \" #601045\" " , " \" #29b7c0\" " , " \" #839f12" ] ;
838+
839+ if N > Length(edge_colors) then
840+ msg := Concatenation(" the out-degree of every vertex in the 1st argument (a digraph) " ,
841+ " must have at most {}, found {}" );
842+ ErrorNoReturn(StringFormatted(msg, Length(edge_colors), N));
843+ fi ;
844+
845+ # node_labels := ["ε"];
846+
847+ # for v in [2 .. M] do
848+ # Add(node_labels, edge_labels{DigraphPath(D, 1, v)[2]});
849+ # od;
850+
851+ legend := " node [shape=plaintext]\n subgraph cluster_01 {\n label=\" Legend\"\n " ;
852+ Append(legend, " key2 [label=<<table border=\" 0\" cellpadding=\" 2\" " );
853+ Append(legend, " cellspacing=\" 0\" cellborder=\" 0\" >\n " );
854+
855+ for i in [ 1 .. N] do
856+ Append(legend,
857+ StringFormatted(" <tr><td port=\" i{}\" > </td></tr>\n " ,
858+ i));
859+ od ;
860+ Append(legend, " </table>>]\n " );
861+ Append(legend, " key [label=<<table border=\" 0\" cellpadding=\" 2\" " );
862+ Append(legend, " cellspacing=\" 0\" cellborder=\" 0\" >\n " );
863+
864+ for i in [ 1 .. N] do
865+ label := [ edge_labels[ i]] ;
866+ next := " <tr><td align=\" right\" " ;
867+ Append(next, StringFormatted(" port=\" i{}\" >{} </td></tr>\n " , i, label));
868+ Append(legend, next);
869+ od ;
870+
871+ Append(legend, " </table>>]\n\n " );
872+
873+ for i in [ 1 .. N] do
874+ next := StringFormatted(" key:i{1}:e -> key2:i{1}:w [color={2}," ,
875+ i,
876+ edge_colors[ i] );
877+ Append(next, " constraint=false]\n " );
878+ Append(legend, next);
879+ od ;
880+ Append(legend, " }\n " );
881+
882+ node_func := i -> StringFormatted(" [label=\" {}\" ]" , node_labels[ i] );
883+ edge_func := { i, j} -> StringFormatted(" [color={}]" , edge_colors[ j] );
884+
885+ result := DIGRAPHS_DotDigraph(D, [ node_func] , [ edge_func] );
886+ result := SplitString(result, " \n " );
887+ result[ 3 ] := " subgraph 00 {" ;
888+ Add(result, " node [shape=box]" , 3 );
889+ Add(result, legend);
890+ Add(result, " }" );
891+ return JoinStringsWithSeparator(result, " \n " );
892+ end );
0 commit comments