From 8347f44b3012480abef0869f6c34a1682713c473 Mon Sep 17 00:00:00 2001 From: mpan322 Date: Mon, 29 Jan 2024 14:52:10 +0000 Subject: [PATCH 1/4] first commit --- gap/cographs-TODO.md | 10 ++++++++++ gap/cographs.gd | 0 gap/cographs.gi | 0 3 files changed, 10 insertions(+) create mode 100644 gap/cographs-TODO.md create mode 100644 gap/cographs.gd create mode 100644 gap/cographs.gi diff --git a/gap/cographs-TODO.md b/gap/cographs-TODO.md new file mode 100644 index 000000000..e7018cb0b --- /dev/null +++ b/gap/cographs-TODO.md @@ -0,0 +1,10 @@ +- Dahlhaus parallel cographs algorithm +- Algo in this paper https://www.sciencedirect.com/science/article/pii/S0166218X04002446?via%3Dihub + - this paper only works for finite undirected graphs w/o multiple edges +- Look into cograph decomposition tree computation + + +- https://inria.hal.science/hal-00958972/document + +- https://www.cs.colostate.edu/~rmm/DGM97.pdf +- file:///home/mp322/Downloads/Schulz_Christian.pdf \ No newline at end of file diff --git a/gap/cographs.gd b/gap/cographs.gd new file mode 100644 index 000000000..e69de29bb diff --git a/gap/cographs.gi b/gap/cographs.gi new file mode 100644 index 000000000..e69de29bb From 00678556ffd6e04fd1d5108c66dd5e2cd5beaaa8 Mon Sep 17 00:00:00 2001 From: mpan322 Date: Fri, 22 Mar 2024 17:32:26 +0000 Subject: [PATCH 2/4] displaying --- PackageInfo.g | 1 + gap/display.gd | 19 +- gap/display.gi | 414 +++++++++++++------------------ tst/standard/display.tst | 514 +++++++++++++++------------------------ 4 files changed, 379 insertions(+), 569 deletions(-) diff --git a/PackageInfo.g b/PackageInfo.g index 977a2f72d..1351419c0 100644 --- a/PackageInfo.g +++ b/PackageInfo.g @@ -390,6 +390,7 @@ Dependencies := rec( GAP := ">=4.10.0", NeededOtherPackages := [["io", ">=4.5.1"], ["orb", ">=4.8.2"], + ["graphviz", "*"], ["datastructures", ">=0.2.5"]], SuggestedOtherPackages := [["GAPDoc", ">=1.6.3"], ["grape", ">=4.8.1"], diff --git a/gap/display.gd b/gap/display.gd index 5916ef9b9..dc201a73a 100644 --- a/gap/display.gd +++ b/gap/display.gd @@ -1,4 +1,4 @@ -############################################################################# +############################################################################ ## ## display.gd ## Copyright (C) 2017-19 James D. Mitchell @@ -8,6 +8,22 @@ ############################################################################# ## +DeclareAttribute("GraphvizDotDigraph", IsDigraph); +DeclareOperation("GraphvizDotColoredDigraph", [IsDigraph, IsList, IsList]); +DeclareOperation("GraphvizDotVertexColoredDigraph", [IsDigraph, IsList]); +DeclareOperation("GraphvizDotEdgeColoredDigraph", [IsDigraph, IsList]); +DeclareOperation("GraphvizDotVertexLabelledDigraph", [IsDigraph]); +DeclareAttribute("GraphvizDotSymmetricDigraph", IsDigraph); +DeclareOperation("GraphvizDotSymmetricColoredDigraph", [IsDigraph, IsList, IsList]); +DeclareOperation("GraphvizDotSymmetricVertexColoredDigraph", [IsDigraph, IsList]); +DeclareOperation("GraphvizDotSymmetricEdgeColoredDigraph", [IsDigraph, IsList]); +DeclareAttribute("GraphvizDotPartialOrderDigraph", IsDigraph); +DeclareAttribute("GraphvizDotPreorderDigraph", IsDigraph); +DeclareSynonym("GraphvizDotQuasiorderDigraph", GraphvizDotPreorderDigraph); +DeclareOperation("GraphvizDotHighlightedDigraph", [IsDigraph, IsList]); +DeclareOperation("GraphvizDotHighlightedDigraph", + [IsDigraph, IsList, IsString, IsString]); + DeclareAttribute("DotDigraph", IsDigraph); DeclareOperation("DotColoredDigraph", [IsDigraph, IsList, IsList]); DeclareOperation("DotVertexColoredDigraph", [IsDigraph, IsList]); @@ -23,3 +39,4 @@ DeclareSynonym("DotQuasiorderDigraph", DotPreorderDigraph); DeclareOperation("DotHighlightedDigraph", [IsDigraph, IsList]); DeclareOperation("DotHighlightedDigraph", [IsDigraph, IsList, IsString, IsString]); + diff --git a/gap/display.gi b/gap/display.gi index f55429169..9407a991c 100644 --- a/gap/display.gi +++ b/gap/display.gi @@ -9,35 +9,37 @@ ## # AN's code, adapted by WW -BindGlobal("DIGRAPHS_DotDigraph", +BindGlobal("GV_DIGRAPHS_DotDigraph", function(D, node_funcs, edge_funcs) - local str, out, i, func, j, l; - str := "//dot\n"; - Append(str, "digraph hgn{\n"); - Append(str, "node [shape=circle]\n"); + local out, nodes, tail, head, node, edge, graph, i, func, j, l; + + graph := GraphvizDigraph("hgn"); + GraphvizSetAttr(graph, "node [shape=\"circle\"]"); + for i in DigraphVertices(D) do - Append(str, StringFormatted("{}", i)); + node := GraphvizAddNode(graph, StringFormatted("{}", i)); for func in node_funcs do - Append(str, func(i)); + func(graph, node, i); od; - Append(str, "\n"); od; + + nodes := GraphvizNodes(graph); out := OutNeighbours(D); for i in DigraphVertices(D) do l := Length(out[i]); for j in [1 .. l] do - Append(str, StringFormatted("{} -> {}", i, out[i][j])); + tail := nodes[String(i)]; + head := nodes[String(out[i][j])]; + edge := GraphvizAddEdge(graph, tail, head); for func in edge_funcs do - Append(str, func(i, j)); + func(graph, edge, i, j); od; - Append(str, "\n"); od; od; - Append(str, "}\n"); - return str; + return graph; end); -BindGlobal("DIGRAPHS_ValidRGBValue", +BindGlobal("GV_DIGRAPHS_ValidRGBValue", function(str) local l, chars, x, i; l := Length(str); @@ -59,22 +61,22 @@ function(str) fi; end); -BindGlobal("DIGRAPHS_GraphvizColorsList", fail); +BindGlobal("GV_DIGRAPHS_GraphvizColorsList", fail); -BindGlobal("DIGRAPHS_GraphvizColors", +BindGlobal("GV_DIGRAPHS_GraphvizColors", function() local f; - if DIGRAPHS_GraphvizColorsList = fail then + if GV_DIGRAPHS_GraphvizColorsList = fail then f := IO_File(Concatenation(DIGRAPHS_Dir(), "/data/colors.p")); - MakeReadWriteGlobal("DIGRAPHS_GraphvizColorsList"); - DIGRAPHS_GraphvizColorsList := IO_Unpickle(f); - MakeReadOnlyGlobal("DIGRAPHS_GraphvizColorsList"); + MakeReadWriteGlobal("GV_DIGRAPHS_GraphvizColorsList"); + GV_DIGRAPHS_GraphvizColorsList := IO_Unpickle(f); + MakeReadOnlyGlobal("GV_DIGRAPHS_GraphvizColorsList"); IO_Close(f); fi; - return DIGRAPHS_GraphvizColorsList; + return GV_DIGRAPHS_GraphvizColorsList; end); -BindGlobal("DIGRAPHS_ValidVertColors", +BindGlobal("GV_DIGRAPHS_ValidVertColors", function(D, verts) local v, sum, colors, col; v := DigraphVertices(D); @@ -83,12 +85,12 @@ function(D, verts) ErrorNoReturn("the number of vertex colors must be the same as the number", " of vertices, expected ", Length(v), " but found ", Length(verts), ""); fi; - colors := DIGRAPHS_GraphvizColors(); + colors := GV_DIGRAPHS_GraphvizColors(); if Length(verts) = Length(v) then for col in verts do if not IsString(col) then ErrorNoReturn("expected a string"); - elif DIGRAPHS_ValidRGBValue(col) = false and + elif GV_DIGRAPHS_ValidRGBValue(col) = false and (col in colors) = false then ErrorNoReturn("expected RGB Value or valid color name as defined", " by GraphViz 2.44.1 X11 Color Scheme", @@ -103,14 +105,14 @@ function(D, verts) fi; end); -BindGlobal("DIGRAPHS_ValidEdgeColors", +BindGlobal("GV_DIGRAPHS_ValidEdgeColors", function(D, edge) local out, l, counter, sum, colors, v, col; out := OutNeighbours(D); l := Length(edge); counter := 0; sum := 0; - colors := DIGRAPHS_GraphvizColors(); + colors := GV_DIGRAPHS_GraphvizColors(); if Length(edge) <> Length(out) then ErrorNoReturn("the list of edge colors needs to have the", " same shape as the out-neighbours of the digraph"); @@ -124,7 +126,7 @@ function(D, edge) for col in edge[v] do if not IsString(col) then ErrorNoReturn("expected a string"); - elif DIGRAPHS_ValidRGBValue(col) = false and + elif GV_DIGRAPHS_ValidRGBValue(col) = false and (col in colors) = false then ErrorNoReturn("expected RGB Value or valid color name as defined", " by GraphViz 2.44.1 X11 Color Scheme", @@ -144,261 +146,175 @@ function(D, edge) fi; end); +InstallMethod(GraphvizDotDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], +D -> GV_DIGRAPHS_DotDigraph(D, [], [])); + InstallMethod(DotDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], -D -> DIGRAPHS_DotDigraph(D, [], [])); +D -> AsString(GraphvizDotDigraph(D))); -InstallMethod(DotColoredDigraph, "for a digraph by out-neighbours and two lists", +InstallMethod(GraphvizDotColoredDigraph, "for a digraph by out-neighbours and two lists", [IsDigraphByOutNeighboursRep, IsList, IsList], function(D, vert, edge) local vert_func, edge_func; - if DIGRAPHS_ValidVertColors(D, vert) and DIGRAPHS_ValidEdgeColors(D, edge) then - vert_func := i -> StringFormatted("[color={}, style=filled]", vert[i]); - edge_func := {i, j} -> StringFormatted("[color={}]", edge[i][j]); - return DIGRAPHS_DotDigraph(D, [vert_func], [edge_func]); + if GV_DIGRAPHS_ValidVertColors(D, vert) and GV_DIGRAPHS_ValidEdgeColors(D, edge) then + vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + edge_func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); + return GV_DIGRAPHS_DotDigraph(D, [vert_func], [edge_func]); fi; end); -InstallMethod(DotVertexColoredDigraph, +InstallMethod(DotColoredDigraph, "for a digraph by out-neighbours and two lists", +[IsDigraphByOutNeighboursRep, IsList, IsList], +{D, vert, edge} -> AsString(GraphvizDotColoredDigraph(D, vert, edge))); + +InstallMethod(GraphvizDotVertexColoredDigraph, "for a digraph by out-neighbours and a list", [IsDigraphByOutNeighboursRep, IsList], function(D, vert) local func; - if DIGRAPHS_ValidVertColors(D, vert) then - func := i -> StringFormatted("[color={}, style=filled]", vert[i]); - return DIGRAPHS_DotDigraph(D, [func], []); + if GV_DIGRAPHS_ValidVertColors(D, vert) then + func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + return GV_DIGRAPHS_DotDigraph(D, [func], []); fi; end); -InstallMethod(DotEdgeColoredDigraph, +InstallMethod(DotVertexColoredDigraph, +"for a digraph by out-neighbours and a list", +[IsDigraphByOutNeighboursRep, IsList], +{D, vert} -> AsString(GraphvizDotVertexColoredDigraph(D, vert))); + +InstallMethod(GraphvizDotEdgeColoredDigraph, "for a digraph by out-neighbours and a list", [IsDigraphByOutNeighboursRep, IsList], function(D, edge) local func; - if DIGRAPHS_ValidEdgeColors(D, edge) then - func := {i, j} -> StringFormatted("[color={}]", edge[i][j]); - return DIGRAPHS_DotDigraph(D, [], [func]); + if GV_DIGRAPHS_ValidEdgeColors(D, edge) then + func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); + return GV_DIGRAPHS_DotDigraph(D, [], [func]); fi; end); -InstallMethod(DotVertexLabelledDigraph, "for a digraph by out-neighbours", +InstallMethod(DotEdgeColoredDigraph, +"for a digraph by out-neighbours and a list", +[IsDigraphByOutNeighboursRep, IsList], +{D, edge} -> AsString(GraphvizDotEdgeColoredDigraph(D, edge))); + +InstallMethod(GraphvizDotVertexLabelledDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], function(D) local func; - func := i -> StringFormatted(" [label=\"{}\"]", DigraphVertexLabel(D, i)); - return DIGRAPHS_DotDigraph(D, [func], []); + func := {g, n, i} -> GraphvizSetAttrs(n, rec(label := DigraphVertexLabel(D, i))); + return GV_DIGRAPHS_DotDigraph(D, [func], []); end); -BindGlobal("DIGRAPHS_DotSymmetricDigraph", +InstallMethod(DotVertexLabelledDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], +{D} -> AsString(GraphvizDotVertexLabelledDigraph(D))); + + +BindGlobal("GV_DIGRAPHS_DotSymmetricDigraph", function(D, node_funcs, edge_funcs) - local out, str, i, j, func; + local graph, node, nodes, edge, out, n1, n2, str, i, j, func; if not IsSymmetricDigraph(D) then ErrorNoReturn("the argument must be a symmetric digraph,"); fi; - out := OutNeighbours(D); - str := "//dot\n"; - Append(str, "graph hgn{\n"); - Append(str, "node [shape=circle]\n\n"); + + out := OutNeighbours(D); + + graph := GraphvizGraph("hgn"); + GraphvizSetAttr(graph, "node [shape=\"circle\"]"); for i in DigraphVertices(D) do - Append(str, StringFormatted("{}", i)); + node := GraphvizAddNode(graph, StringFormatted("{}", i)); for func in node_funcs do - Append(str, func(i)); + func(graph, node, i); od; - Append(str, "\n"); od; + + nodes := GraphvizNodes(graph); for i in DigraphVertices(D) do for j in [1 .. Length(out[i])] do if out[i][j] >= i then - Append(str, StringFormatted("{} -- {}", i, out[i][j])); + n1 := nodes[String(i)]; + n2 := nodes[String(out[i][j])]; + edge := GraphvizAddEdge(graph, n1, n2); for func in edge_funcs do - Append(str, func(i, j)); + func(graph, edge, i, j); od; - Append(str, "\n"); fi; od; od; - Append(str, "}\n"); - return str; + return graph; end); +InstallMethod(GraphvizDotSymmetricDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], +D -> GV_DIGRAPHS_DotSymmetricDigraph(D, [], [])); + InstallMethod(DotSymmetricDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], -D -> DIGRAPHS_DotSymmetricDigraph(D, [], [])); +D -> AsString(GraphvizDotSymmetricDigraph(D))); -InstallMethod(DotSymmetricColoredDigraph, +InstallMethod(GraphvizDotSymmetricColoredDigraph, "for a digraph by out-neighbours and two lists", [IsDigraphByOutNeighboursRep, IsList, IsList], function(D, vert, edge) local vert_func, edge_func; - if DIGRAPHS_ValidVertColors(D, vert) and DIGRAPHS_ValidEdgeColors(D, edge) then - vert_func := i -> StringFormatted("[color={}, style=filled]", vert[i]); - edge_func := {i, j} -> StringFormatted("[color={}]", edge[i][j]); - return DIGRAPHS_DotSymmetricDigraph(D, [vert_func], [edge_func]); + if GV_DIGRAPHS_ValidVertColors(D, vert) and GV_DIGRAPHS_ValidEdgeColors(D, edge) then + vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + edge_func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); + return GV_DIGRAPHS_DotSymmetricDigraph(D, [vert_func], [edge_func]); fi; end); -InstallMethod(DotSymmetricVertexColoredDigraph, +InstallMethod(GraphvizDotSymmetricVertexColoredDigraph, "for a digraph by out-neighbours and a list", [IsDigraphByOutNeighboursRep, IsList], function(D, vert) local func; - if DIGRAPHS_ValidVertColors(D, vert) then - func := i -> StringFormatted ("[color={}, style=filled]", vert[i]); - return DIGRAPHS_DotSymmetricDigraph(D, [func], []); + if GV_DIGRAPHS_ValidVertColors(D, vert) then + func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + return GV_DIGRAPHS_DotSymmetricDigraph(D, [func], []); fi; end); -InstallMethod(DotSymmetricEdgeColoredDigraph, +InstallMethod(GraphvizDotSymmetricEdgeColoredDigraph, "for a digraph by out-neighbours and a list", [IsDigraphByOutNeighboursRep, IsList], function(D, edge) local func; - if DIGRAPHS_ValidEdgeColors(D, edge) then - func := {i, j} -> StringFormatted("[color={}]", edge[i][j]); - return DIGRAPHS_DotSymmetricDigraph(D, [], [func]); + if GV_DIGRAPHS_ValidEdgeColors(D, edge) then + func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); + return GV_DIGRAPHS_DotSymmetricDigraph(D, [], [func]); fi; end); -# AN's code - -if not IsBound(Splash) then # This function is written by A. Egri-Nagy - BindGlobal("VizViewers", - ["xpdf", "xdg-open", "open", "evince", "okular", "gv"]); - - BindGlobal("Splash", - function(arg) - local str, opt, path, dir, tdir, file, viewer, type, inn, filetype, out, - engine; - - if not IsString(arg[1]) then - ErrorNoReturn("the 1st argument must be a string,"); - fi; - str := arg[1]; - - opt := rec(); - if IsBound(arg[2]) and IsRecord(arg[2]) then - opt := arg[2]; - elif IsBound(arg[2]) then - ErrorNoReturn("the 2nd argument must be a record,"); - fi; - - # path - path := UserHomeExpand("~/"); # default - if IsBound(opt.path) then - path := opt.path; - fi; - - # directory - if IsBound(opt.directory) then - if not opt.directory in DirectoryContents(path) then - Exec(Concatenation("mkdir ", path, opt.directory)); - fi; - dir := Concatenation(path, opt.directory, "/"); - elif IsBound(opt.path) then - if not "tmp.viz" in DirectoryContents(path) then - tdir := Directory(Concatenation(path, "/", "tmp.viz")); - dir := Filename(tdir, ""); - fi; - else - tdir := DirectoryTemporary(); - dir := Filename(tdir, ""); - fi; - - # file - file := "vizpicture"; # default - if IsBound(opt.filename) then - file := opt.filename; - fi; - - # viewer - if IsBound(opt.viewer) then - viewer := opt.viewer; - if not IsString(viewer) then - ErrorNoReturn("the option `viewer` must be a string, not an ", - TNAM_OBJ(viewer), ","); - elif Filename(DirectoriesSystemPrograms(), viewer) = fail then - ErrorNoReturn("the viewer \"", viewer, "\" specified in the option ", - "`viewer` is not available,"); - fi; - else - viewer := First(VizViewers, x -> - Filename(DirectoriesSystemPrograms(), x) <> fail); - if viewer = fail then - ErrorNoReturn("none of the default viewers ", VizViewers, - " is available, please specify an available viewer", - " in the options record component `viewer`,"); - fi; - fi; - - # type - if IsBound(opt.type) and (opt.type = "latex" or opt.type = "dot") then - type := opt.type; - elif Length(str) >= 6 and str{[1 .. 6]} = "%latex" then - type := "latex"; - elif Length(str) >= 5 and str{[1 .. 5]} = "//dot" then - type := "dot"; - else - ErrorNoReturn("the component \"type\" of the 2nd argument ", - " must be \"dot\" or \"latex\","); - fi; - if type = "latex" then - inn := Concatenation(dir, file, ".tex"); - else # type = "dot" - inn := Concatenation(dir, file, ".dot"); - fi; - - # output type and name - filetype := "pdf"; # default - if IsBound(opt.filetype) and IsString(opt.filetype) and type <> "latex" then - filetype := opt.filetype; - fi; - out := Concatenation(dir, file, ".", filetype); - - # engine - engine := "dot"; # default - if IsBound(opt.engine) then - engine := opt.engine; - if not engine in ["dot", "neato", "twopi", "circo", - "fdp", "sfdp", "patchwork"] then - ErrorNoReturn("the component \"engine\" of the 2nd argument ", - " must be one of: \"dot\", \"neato\", ", - "\"twopi\", \"circo\", \"fdp\", \"sfdp\", ", - "or \"patchwork\""); - fi; - fi; - - # Write and compile the file - FileString(inn, str); - if type = "latex" then - # Requires GAP >= 4.11: - # Exec(StringFormatted("cd {}; pdflatex {} 2>/dev/null 1>/dev/null", dir); - Exec(Concatenation("cd ", dir, ";", - "pdflatex ", file, " 2>/dev/null 1>/dev/null")); - else # type = "dot" - # Requires GAP >= 4.11: - # Exec(StringFormatted("{} -T {} {} -o {}", engine, filetype, inn, out)); - Exec(Concatenation(engine, " -T", filetype, " ", inn, " -o ", out)); - fi; - Exec(Concatenation(viewer, " ", out, " 2>/dev/null 1>/dev/null &")); - end); -fi; +InstallMethod(DotSymmetricEdgeColoredDigraph, +"for a digraph by out-neighbours and a list", +[IsDigraphByOutNeighboursRep, IsList], +{D, edge} -> AsString(GraphvizDotSymmetricEdgeColoredDigraph(D, edge))); # CR's code -InstallMethod(DotPartialOrderDigraph, "for a partial order digraph", +InstallMethod(GraphvizDotPartialOrderDigraph, "for a partial order digraph", [IsDigraph], function(D) if not IsPartialOrderDigraph(D) then ErrorNoReturn("the argument must be a partial order digraph,"); fi; D := DigraphMutableCopyIfMutable(D); - return DotDigraph(DigraphReflexiveTransitiveReduction(D)); + return GraphvizDotDigraph(DigraphReflexiveTransitiveReduction(D)); end); -InstallMethod(DotPreorderDigraph, "for a preorder digraph", +InstallMethod(DotPartialOrderDigraph, "for a partial order digraph", +[IsDigraph], +{D} -> AsString(GraphvizDotPartialOrderDigraph(D))); + +InstallMethod(GraphvizDotPreorderDigraph, "for a preorder digraph", [IsDigraph], function(D) - local comps, quo, red, str, c, x, e; + local comps, quo, red, str, c, x, e, node, graph, label, head, tail, nodes; if not IsPreorderDigraph(D) then ErrorNoReturn("the argument must be a preorder digraph,"); fi; @@ -410,43 +326,58 @@ function(D) quo := DigraphRemoveAllMultipleEdges(QuotientDigraph(D, comps)); red := DigraphReflexiveTransitiveReduction(quo); - str := "//dot\n"; - Append(str, "digraph graphname {\n"); - Append(str, "node [shape=Mrecord, height=0.5, fixedsize=true]"); - Append(str, "ranksep=1;\n"); + graph := GraphvizDigraph("graphname"); + GraphvizSetAttr(graph, "node [shape=\"Mrecord\"]"); + GraphvizSetAttr(graph, "height=\"0.5\""); + GraphvizSetAttr(graph, "fixedsize=\"true\""); + GraphvizSetAttr(graph, "ranksep=\"1\""); # Each vertex of the quotient D is labelled by its preimage. for c in [1 .. Length(comps)] do - Append(str, String(c)); - Append(str, " [label=\""); - Append(str, String(comps[c][1])); + + # create node w/ label + label := "\""; + Append(label, String(comps[c][1])); for x in comps[c]{[2 .. Length(comps[c])]} do - Append(str, "|"); - Append(str, String(x)); + Append(label, "|"); + Append(label, String(x)); od; - Append(str, "\", width="); - Append(str, String(Float(Length(comps[c]) / 2))); - Append(str, "]\n"); + Append(label, "\""); + + node := GraphvizAddNode(graph, String(c)); + GraphvizSetAttr(node, "label", label); + GraphvizSetAttr(node, "width", String(Float(Length(comps[c]) / 2))); od; # Add the edges of the quotient D. + nodes := GraphvizNodes(graph); for e in DigraphEdges(red) do - Append(str, Concatenation(String(e[1]), " -> ", String(e[2]), "\n")); + tail := nodes[String(e[1])]; + head := nodes[String(e[2])]; + GraphvizAddEdge(graph, tail, head); od; - Append(str, "}"); - return str; + return graph; end); +InstallMethod(DotPreorderDigraph, "for a preorder digraph", +[IsDigraph], +{D} -> AsString(GraphvizDotPreorderDigraph(D))); + + +InstallMethod(GraphvizDotHighlightedDigraph, "for a digraph and list", +[IsDigraph, IsList], +{D, list} -> GraphvizDotHighlightedDigraph(D, list, "black", "grey")); + InstallMethod(DotHighlightedDigraph, "for a digraph and list", [IsDigraph, IsList], -{D, list} -> DotHighlightedDigraph(D, list, "black", "grey")); +{D, list} -> AsString(GraphvizDotHighlightedDigraph(D, list, "black", "grey"))); -InstallMethod(DotHighlightedDigraph, +InstallMethod(GraphvizDotHighlightedDigraph, "for a digraph by out-neighbours, list, and two strings", [IsDigraphByOutNeighboursRep, IsList, IsString, IsString], function(D, highverts, highcolour, lowcolour) - local lowverts, out, str, i, j; + local lowverts, graph, node, edge, nodes, out, i, j; if not IsSubset(DigraphVertices(D), highverts) then ErrorNoReturn("the 2nd argument must be a list of vertices ", @@ -461,55 +392,44 @@ function(D, highverts, highcolour, lowcolour) lowverts := Difference(DigraphVertices(D), highverts); out := OutNeighbours(D); - str := "//dot\n"; - - Append(str, "digraph hgn{\n"); - Append(str, "subgraph lowverts{\n"); - Append(str, Concatenation("node [shape=circle, color=", - lowcolour, - "]\n edge [color=", - lowcolour, - "]\n")); + graph := GraphvizDigraph("hgn"); for i in lowverts do - Append(str, Concatenation(String(i), "\n")); + node := GraphvizAddNode(graph, String(i)); + GraphvizSetAttrs(node, rec( shape := "circle", color := lowcolour)); od; - Append(str, "}\n"); - - Append(str, "subgraph highverts{\n"); - Append(str, Concatenation("node [shape=circle, color=", - highcolour, - "]\n edge [color=", - highcolour, - "]\n")); for i in highverts do - Append(str, Concatenation(String(i), "\n")); + node := GraphvizAddNode(graph, String(i)); + GraphvizSetAttrs(node, rec( shape := "circle", color := highcolour)); od; - Append(str, "}\n"); - - Append(str, "subgraph lowverts{\n"); + nodes := GraphvizNodes(graph); for i in lowverts do for j in out[i] do - Append(str, Concatenation(String(i), " -> ", String(j), "\n")); + edge := GraphvizAddEdge(graph, nodes[String(i)], nodes[String(j)]); + GraphvizSetAttr(edge, "color", lowcolour); od; od; - Append(str, "}\n"); - Append(str, "subgraph highverts{\n"); for i in highverts do for j in out[i] do - Append(str, Concatenation(String(i), " -> ", String(j))); + edge := GraphvizAddEdge(graph, nodes[String(i)], nodes[String(j)]); + GraphvizSetAttr(edge, "color", highcolour); if j in lowverts then - Append(str, Concatenation(" [color=", lowcolour, "]")); + GraphvizSetAttr(edge, "color", lowcolour); fi; - Append(str, "\n"); od; od; - Append(str, "}\n}\n"); - return str; + return graph; end); + + +InstallMethod(DotHighlightedDigraph, +"for a digraph by out-neighbours, list, and two strings", +[IsDigraphByOutNeighboursRep, IsList, IsString, IsString], +{D, highverts, highcolour, lowcolour} -> + AsString(GraphvizDotHighlightedDigraph(D, highverts, highcolour, lowcolour))); diff --git a/tst/standard/display.tst b/tst/standard/display.tst index 76b7ef493..dc4b60df7 100644 --- a/tst/standard/display.tst +++ b/tst/standard/display.tst @@ -4,6 +4,7 @@ #Y Copyright (C) 2014-15 James D. Mitchell ## ## Licensing information can be found in the README file of this package. +## Taken from the old digraphs display package ## ############################################################################# ## @@ -13,70 +14,40 @@ gap> LoadPackage("digraphs", false);; # gap> DIGRAPHS_StartTest(); -# Display and PrintString and String -gap> Digraph([]); - -gap> Digraph([[]]); - -gap> Digraph([[1]]); - -gap> Digraph([[2], []]); - -gap> gr := Digraph([[1, 2], [2], []]); - -gap> PrintString(gr); -"DigraphFromDigraph6String(\"&Bq?\")" -gap> String(gr); -"DigraphFromDigraph6String(\"&Bq?\")" -gap> gr := Digraph([[2], [1], [], [3]]); - -gap> PrintString(gr); -"DigraphFromDigraph6String(\"&CQ?G\")" -gap> String(gr); -"DigraphFromDigraph6String(\"&CQ?G\")" -gap> r := rec(DigraphVertices := [1, 2, 3], -> DigraphSource := [1, 2], -> DigraphRange := [2, 3]);; -gap> gr := Digraph(r); - -gap> PrintString(gr); -"ChainDigraph(3)" -gap> String(gr); -"ChainDigraph(3)" - # DotDigraph and DotSymmetricDigraph gap> r := rec(DigraphVertices := [1 .. 3], DigraphSource := [1, 1, 1, 1], > DigraphRange := [1, 2, 2, 3]);; -gap> gr := Digraph(r); - -gap> dot := DotDigraph(gr);; -gap> dot{[1 .. 50]}; -"//dot\ndigraph hgn{\nnode [shape=circle]\n1\n2\n3\n1 -> " -gap> dot{[51 .. 75]}; -"1\n1 -> 2\n1 -> 2\n1 -> 3\n}\n" +gap> gr := Digraph(r);; +gap> dot := GraphvizDotDigraph(gr);; +gap> AsString(dot); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t1 -> 1\n\t1 -> 2\ +\n\t1 -> 2\n\t1 -> 3\n}\n" gap> r := rec(DigraphVertices := [1 .. 8], > DigraphSource := [1, 1, 2, 2, 3, 4, 4, 4, 5, 5, 5, 5, 5, 6, 7, 7, 7, 7, 7, 8, > 8], > DigraphRange := [6, 7, 1, 6, 5, 1, 4, 8, 1, 3, 6, 6, 7, 7, 1, 4, 4, 5, 7, 5, > 6]);; -gap> gr1 := Digraph(r); - -gap> DotDigraph(gr1){[50 .. 109]}; -"6\n7\n8\n1 -> 6\n1 -> 7\n2 -> 1\n2 -> 6\n3 -> 5\n4 -> 1\n4 -> 4\n4 -> " +gap> gr1 := Digraph(r);; +gap> dot1 := GraphvizDotDigraph(gr1);; +gap> AsString(dot1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\ +\n\t8\n\t1 -> 6\n\t1 -> 7\n\t2 -> 1\n\t2 -> 6\n\t3 -> 5\n\t4 -> 1\n\t4 -> 4\n\ +\t4 -> 8\n\t5 -> 1\n\t5 -> 3\n\t5 -> 6\n\t5 -> 6\n\t5 -> 7\n\t6 -> 7\n\t7 -> 1\ +\n\t7 -> 4\n\t7 -> 4\n\t7 -> 5\n\t7 -> 7\n\t8 -> 5\n\t8 -> 6\n}\n" gap> adj := [[2], [1, 3], [2, 3, 4], [3]]; [ [ 2 ], [ 1, 3 ], [ 2, 3, 4 ], [ 3 ] ] -gap> gr2 := Digraph(adj); - -gap> DotDigraph(gr2){[11 .. 75]}; -"aph hgn{\nnode [shape=circle]\n1\n2\n3\n4\n1 -> 2\n2 -> 1\n2 -> 3\n3 -> 2\n" -gap> DotSymmetricDigraph(gr2){[12 .. 70]}; -" hgn{\nnode [shape=circle]\n\n1\n2\n3\n4\n1 -- 2\n2 -- 3\n3 -- 3\n3 -" -gap> DotSymmetricDigraph(gr1); -Error, the argument must be a symmetric digraph, +gap> gr2 := Digraph(adj);; +gap> dot2 := GraphvizDotDigraph(gr2);; +gap> AsString(dot2); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t1 -> 2\n\t2 \ +-> 1\n\t2 -> 3\n\t3 -> 2\n\t3 -> 3\n\t3 -> 4\n\t4 -> 3\n}\n" +gap> dot3 := GraphvizDotSymmetricDigraph(gr2);; +gap> AsString(dot3); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t1 -- 2\n\t2 --\ + 3\n\t3 -- 3\n\t3 -- 4\n}\n" #DotColoredDigraph and DotSymmetriColoredDigraph -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -95,10 +66,16 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors){[1 .. 30]}; -"//dot\ndigraph hgn{\nnode [shape" -gap> D := Digraph([[2], [1, 3], [2]]); - +gap> dot1 := GraphvizDotColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t\ +2 [color=red, style=filled]\n\t3 [color=green, style=filled]\n\t4 [color=yello\ +w, style=filled]\n\t1 -> 2 [color=lightblue]\n\t1 -> 3 [color=pink]\n\t1 -> 4 \ +[color=purple]\n\t2 -> 1 [color=lightblue]\n\t2 -> 3 [color=pink]\n\t2 -> 4 [c\ +olor=purple]\n\t3 -> 1 [color=lightblue]\n\t3 -> 2 [color=pink]\n\t3 -> 4 [col\ +or=purple]\n\t4 -> 1 [color=lightblue]\n\t4 -> 2 [color=pink]\n\t4 -> 3 [color\ +=purple]\n}\n" +gap> D := Digraph([[2], [1, 3], [2]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; gap> vertcolors[2] := "pink";; @@ -109,12 +86,12 @@ gap> edgecolors[3] := [];; gap> edgecolors[1][1] := "green";; gap> edgecolors[2][1] := "green";; gap> edgecolors[3][1] := "red";; edgecolors[2][2] := "red";; -gap> DotSymmetricColoredDigraph(D, vertcolors, edgecolors); -"//dot\ngraph hgn{\nnode [shape=circle]\n\n1[color=blue, style=filled]\n2[colo\ -r=pink, style=filled]\n3[color=purple, style=filled]\n1 -- 2[color=green]\n2 -\ -- 3[color=red]\n}\n" -gap> D := Digraph([[2, 3], [1, 3], [1]]); - +gap> dot2 := GraphvizDotSymmetricColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot2); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t2 \ +[color=pink, style=filled]\n\t3 [color=purple, style=filled]\n\t1 -- 2 [color=\ +green]\n\t2 -- 3 [color=red]\n}\n" +gap> D := Digraph([[2, 3], [1, 3], [1]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; @@ -124,13 +101,13 @@ gap> edgecolors[3] := [];; gap> edgecolors[1][1] := "orange";; edgecolors[1][2] := "yellow";; gap> edgecolors[2][1] := "orange";; edgecolors[2][2] := "pink";; gap> edgecolors[3][1] := "yellow";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); -"//dot\ndigraph hgn{\nnode [shape=circle]\n1[color=blue, style=filled]\n2[colo\ -r=red, style=filled]\n3[color=green, style=filled]\n1 -> 2[color=orange]\n1 ->\ - 3[color=yellow]\n2 -> 1[color=orange]\n2 -> 3[color=pink]\n3 -> 1[color=yello\ -w]\n}\n" -gap> D := Digraph(IsMutableDigraph, [[2, 3], [1, 3], [1]]); - +gap> dot3 := GraphvizDotColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot3); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t\ +2 [color=red, style=filled]\n\t3 [color=green, style=filled]\n\t1 -> 2 [color=\ +orange]\n\t1 -> 3 [color=yellow]\n\t2 -> 1 [color=orange]\n\t2 -> 3 [color=pin\ +k]\n\t3 -> 1 [color=yellow]\n}\n" +gap> D := Digraph(IsMutableDigraph, [[2, 3], [1, 3], [1]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; @@ -140,11 +117,13 @@ gap> edgecolors[3] := [];; gap> edgecolors[1][1] := "orange";; edgecolors[1][2] := "yellow";; gap> edgecolors[2][1] := "orange";; edgecolors[2][2] := "pink";; gap> edgecolors[3][1] := "yellow";; -gap> DotColoredDigraph(D, vertcolors, edgecolors);; -gap> D; - -gap> D := Digraph([[2, 4], [1, 3], [2], [1]]); - +gap> dot4 := GraphvizDotColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot4); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t\ +2 [color=red, style=filled]\n\t3 [color=green, style=filled]\n\t1 -> 2 [color=\ +orange]\n\t1 -> 3 [color=yellow]\n\t2 -> 1 [color=orange]\n\t2 -> 3 [color=pin\ +k]\n\t3 -> 1 [color=yellow]\n}\n" +gap> D := Digraph([[2, 4], [1, 3], [2], [1]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -154,12 +133,13 @@ gap> edgecolors[3] := [];; edgecolors[4] := [];; gap> edgecolors[1][1] := "orange";; edgecolors[1][2] := "orange";; gap> edgecolors[2][1] := "orange";; edgecolors[2][2] := "orange";; gap> edgecolors[3][1] := "orange";; edgecolors[4][1] := "orange";; -gap> DotSymmetricColoredDigraph(D, vertcolors, edgecolors); -"//dot\ngraph hgn{\nnode [shape=circle]\n\n1[color=blue, style=filled]\n2[colo\ -r=red, style=filled]\n3[color=green, style=filled]\n4[color=yellow, style=fill\ -ed]\n1 -- 2[color=orange]\n1 -- 4[color=orange]\n2 -- 3[color=orange]\n}\n" -gap> D := Digraph(IsMutableDigraph, [[2, 4], [1, 3], [2], [1]]); - +gap> dot5 := GraphvizDotSymmetricColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot5); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t2 \ +[color=red, style=filled]\n\t3 [color=green, style=filled]\n\t4 [color=yellow,\ + style=filled]\n\t1 -- 2 [color=orange]\n\t1 -- 4 [color=orange]\n\t2 -- 3 [co\ +lor=orange]\n}\n" +gap> D := Digraph(IsMutableDigraph, [[2, 4], [1, 3], [2], [1]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -169,14 +149,13 @@ gap> edgecolors[3] := [];; edgecolors[4] := [];; gap> edgecolors[1][1] := "orange";; edgecolors[1][2] := "orange";; gap> edgecolors[2][1] := "orange";; edgecolors[2][2] := "orange";; gap> edgecolors[3][1] := "orange";; edgecolors[4][1] := "orange";; -gap> DotSymmetricColoredDigraph(D, vertcolors, edgecolors); -"//dot\ngraph hgn{\nnode [shape=circle]\n\n1[color=blue, style=filled]\n2[colo\ -r=red, style=filled]\n3[color=green, style=filled]\n4[color=yellow, style=fill\ -ed]\n1 -- 2[color=orange]\n1 -- 4[color=orange]\n2 -- 3[color=orange]\n}\n" -gap> D; - -gap> D := CompleteDigraph(4); - +gap> dot6 := GraphvizDotSymmetricColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(dot6); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t2 \ +[color=red, style=filled]\n\t3 [color=green, style=filled]\n\t4 [color=yellow,\ + style=filled]\n\t1 -- 2 [color=orange]\n\t1 -- 4 [color=orange]\n\t2 -- 3 [co\ +lor=orange]\n}\n" +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "banana";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -195,11 +174,10 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors){[5 .. 35]}; +gap> GraphvizDotColoredDigraph(D, vertcolors, edgecolors){[5 .. 35]}; Error, expected RGB Value or valid color name as defined by GraphViz 2.44.1 X1\ 1 Color Scheme http://graphviz.org/doc/info/colors.html -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; @@ -218,11 +196,10 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); +gap> GraphvizDotColoredDigraph(D, vertcolors, edgecolors); Error, the number of vertex colors must be the same as the number of vertices,\ expected 4 but found 3 -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := 2;; vertcolors[2] := 1;; gap> vertcolors[3] := 1;; vertcolors[4] := 3;; @@ -241,10 +218,9 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); +gap> GraphvizDotColoredDigraph(D, vertcolors, edgecolors); Error, expected a string -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "#AB3487";; vertcolors[2] := "#DF4738";; gap> vertcolors[3] := "#4BF234";; vertcolors[4] := "#AF34C9";; @@ -263,15 +239,16 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); -"//dot\ndigraph hgn{\nnode [shape=circle]\n1[color=#AB3487, style=filled]\n2[c\ -olor=#DF4738, style=filled]\n3[color=#4BF234, style=filled]\n4[color=#AF34C9, \ -style=filled]\n1 -> 2[color=lightblue]\n1 -> 3[color=pink]\n1 -> 4[color=purpl\ -e]\n2 -> 1[color=lightblue]\n2 -> 3[color=pink]\n2 -> 4[color=purple]\n3 -> 1[\ -color=lightblue]\n3 -> 2[color=pink]\n3 -> 4[color=purple]\n4 -> 1[color=light\ -blue]\n4 -> 2[color=pink]\n4 -> 3[color=purple]\n}\n" -gap> D := CompleteDigraph(4); - +gap> x1 := GraphvizDotColoredDigraph(D, vertcolors, edgecolors);; +gap> AsString(x1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=#AB3487, style=filled]\ +\n\t2 [color=#DF4738, style=filled]\n\t3 [color=#4BF234, style=filled]\n\t4 [c\ +olor=#AF34C9, style=filled]\n\t1 -> 2 [color=lightblue]\n\t1 -> 3 [color=pink]\ +\n\t1 -> 4 [color=purple]\n\t2 -> 1 [color=lightblue]\n\t2 -> 3 [color=pink]\n\ +\t2 -> 4 [color=purple]\n\t3 -> 1 [color=lightblue]\n\t3 -> 2 [color=pink]\n\t\ +3 -> 4 [color=purple]\n\t4 -> 1 [color=lightblue]\n\t4 -> 2 [color=pink]\n\t4 \ +-> 3 [color=purple]\n}\n" +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -290,11 +267,10 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); +gap> GraphvizDotColoredDigraph(D, vertcolors, edgecolors); Error, expected RGB Value or valid color name as defined by GraphViz 2.44.1 X1\ 1 Color Scheme http://graphviz.org/doc/info/colors.html -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; @@ -312,52 +288,35 @@ gap> edgecolors[3][2] := "pink";; gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; -gap> DotColoredDigraph(D, vertcolors, edgecolors); +gap> GraphvizDotColoredDigraph(D, vertcolors, edgecolors); Error, the list of edge colors needs to have the same shape as the out-neighbo\ urs of the digraph # DotVertexColoredDigraph -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; vertcolors[4] := "yellow";; -gap> Print(DotVertexColoredDigraph(D, vertcolors)); -//dot -digraph hgn{ -node [shape=circle] -1[color=blue, style=filled] -2[color=red, style=filled] -3[color=green, style=filled] -4[color=yellow, style=filled] -1 -> 2 -1 -> 3 -1 -> 4 -2 -> 1 -2 -> 3 -2 -> 4 -3 -> 1 -3 -> 2 -3 -> 4 -4 -> 1 -4 -> 2 -4 -> 3 -} -gap> D := EmptyDigraph(3); - +gap> out1 := GraphvizDotVertexColoredDigraph(D, vertcolors);; +gap> AsString(out1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t\ +2 [color=red, style=filled]\n\t3 [color=green, style=filled]\n\t4 [color=yello\ +w, style=filled]\n\t1 -> 2\n\t1 -> 3\n\t1 -> 4\n\t2 -> 1\n\t2 -> 3\n\t2 -> 4\n\ +\t3 -> 1\n\t3 -> 2\n\t3 -> 4\n\t4 -> 1\n\t4 -> 2\n\t4 -> 3\n}\n" +gap> D := EmptyDigraph(3);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; vertcolors[2] := "red";; gap> vertcolors[3] := "green";; gap> edgecolors := [];; gap> edgecolors[1] := [];; edgecolors[2] := [];; gap> edgecolors[3] := [];; -gap> DotVertexColoredDigraph(D, vertcolors); -"//dot\ndigraph hgn{\nnode [shape=circle]\n1[color=blue, style=filled]\n2[colo\ -r=red, style=filled]\n3[color=green, style=filled]\n}\n" +gap> out2 := GraphvizDotVertexColoredDigraph(D, vertcolors);; +gap> AsString(out2); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t\ +2 [color=red, style=filled]\n\t3 [color=green, style=filled]\n}\n" # DotEdgeColoredDigraph -gap> D := CompleteDigraph(4); - +gap> D := CompleteDigraph(4);; gap> edgecolors := [];; gap> edgecolors[1] := [];; edgecolors[2] := [];; gap> edgecolors[3] := [];; edgecolors[4] := [];; @@ -373,62 +332,63 @@ gap> edgecolors[3][3] := "purple";; gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; -gap> DotEdgeColoredDigraph(D, edgecolors); -"//dot\ndigraph hgn{\nnode [shape=circle]\n1\n2\n3\n4\n1 -> 2[color=lightblue]\ -\n1 -> 3[color=pink]\n1 -> 4[color=purple]\n2 -> 1[color=lightblue]\n2 -> 3[co\ -lor=pink]\n2 -> 4[color=purple]\n3 -> 1[color=lightblue]\n3 -> 2[color=pink]\n\ -3 -> 4[color=purple]\n4 -> 1[color=lightblue]\n4 -> 2[color=pink]\n4 -> 3[colo\ -r=purple]\n}\n" -gap> DotEdgeColoredDigraph(CycleDigraph(3), []); +gap> out1 := GraphvizDotEdgeColoredDigraph(D, edgecolors);; +gap> AsString(out1){[1..300]}; +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t1 -> 2 [colo\ +r=lightblue]\n\t1 -> 3 [color=pink]\n\t1 -> 4 [color=purple]\n\t2 -> 1 [color=\ +lightblue]\n\t2 -> 3 [color=pink]\n\t2 -> 4 [color=purple]\n\t3 -> 1 [color=li\ +ghtblue]\n\t3 -> 2 [color=pink]\n\t3 -> 4 [color=purple]\n\t4 -> 1 [color=ligh\ +tblue]\n\t4 -> 2 [color" +gap> GraphvizDotEdgeColoredDigraph(CycleDigraph(3), []); Error, the list of edge colors needs to have the same shape as the out-neighbo\ urs of the digraph -gap> DotEdgeColoredDigraph(CycleDigraph(3), [[fail, fail], [fail], [fail]]); +gap> GraphvizDotEdgeColoredDigraph(CycleDigraph(3), [[fail, fail], [fail], [fail]]); Error, the list of edge colors needs to have the same shape as the out-neighbo\ urs of the digraph -gap> DotEdgeColoredDigraph(CycleDigraph(3), [[fail], [fail], [fail]]); +gap> GraphvizDotEdgeColoredDigraph(CycleDigraph(3), [[fail], [fail], [fail]]); Error, expected a string # DotSymmetricVertexColoredDigraph -gap> D := Digraph([[2], [1, 3], [2]]); - +gap> D := Digraph([[2], [1, 3], [2]]);; gap> vertcolors := [];; gap> vertcolors[1] := "blue";; gap> vertcolors[2] := "pink";; gap> vertcolors[3] := "purple";; -gap> DotSymmetricVertexColoredDigraph(D, vertcolors); -"//dot\ngraph hgn{\nnode [shape=circle]\n\n1[color=blue, style=filled]\n2[colo\ -r=pink, style=filled]\n3[color=purple, style=filled]\n1 -- 2\n2 -- 3\n}\n" +gap> out1 := GraphvizDotSymmetricVertexColoredDigraph(D, vertcolors);; +gap> AsString(out1); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1 [color=blue, style=filled]\n\t2 \ +[color=pink, style=filled]\n\t3 [color=purple, style=filled]\n\t1 -- 2\n\t2 --\ + 3\n}\n" # DotSymmetricEdgeColoredDigraph -gap> D := Digraph([[2], [1, 3], [2]]); - +gap> D := Digraph([[2], [1, 3], [2]]);; gap> edgecolors := [];; gap> edgecolors[1] := [];; edgecolors[2] := [];; gap> edgecolors[3] := [];; gap> edgecolors[1][1] := "green";; edgecolors[2][1] := "green";; gap> edgecolors[2][2] := "red";; edgecolors[3][1] := "red";; -gap> DotSymmetricEdgeColoredDigraph(D, edgecolors); -"//dot\ngraph hgn{\nnode [shape=circle]\n\n1\n2\n3\n1 -- 2[color=green]\n2 -- \ -3[color=red]\n}\n" +gap> out1 := GraphvizDotSymmetricEdgeColoredDigraph(D, edgecolors);; +gap> AsString(out1); +"graph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t1 -- 2 [color=green\ +]\n\t2 -- 3 [color=red]\n}\n" # DotVertexLabelledDigraph gap> r := rec(DigraphVertices := [1 .. 3], DigraphSource := [1, 1, 1, 1], > DigraphRange := [1, 2, 2, 3]);; -gap> gr := Digraph(r); - -gap> dot := DotVertexLabelledDigraph(gr);; -gap> dot; -"//dot\ndigraph hgn{\nnode [shape=circle]\n1 [label=\"1\"]\n2 [label=\"2\"]\n3\ - [label=\"3\"]\n1 -> 1\n1 -> 2\n1 -> 2\n1 -> 3\n}\n" +gap> gr := Digraph(r);; +gap> dot1 := GraphvizDotVertexLabelledDigraph(gr);; +gap> AsString(dot1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [label=1]\n\t2 [label=2]\n\t3 \ +[label=3]\n\t1 -> 1\n\t1 -> 2\n\t1 -> 2\n\t1 -> 3\n}\n" gap> SetDigraphVertexLabel(gr, 1, 2); -gap> dot := DotVertexLabelledDigraph(gr);; -gap> dot; -"//dot\ndigraph hgn{\nnode [shape=circle]\n1 [label=\"2\"]\n2 [label=\"2\"]\n3\ - [label=\"3\"]\n1 -> 1\n1 -> 2\n1 -> 2\n1 -> 3\n}\n" +gap> dot2 := GraphvizDotVertexLabelledDigraph(gr);; +gap> AsString(dot2); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1 [label=2]\n\t2 [label=2]\n\t3 \ +[label=3]\n\t1 -> 1\n\t1 -> 2\n\t1 -> 2\n\t1 -> 3\n}\n" # Splash gap> Splash(1); -Error, the 1st argument must be a string, +Error, the 1st argument must be a string or graphviz graph. gap> Splash("string", 0); Error, the 2nd argument must be a record, gap> Splash("string"); @@ -437,8 +397,8 @@ latex", gap> Splash("string", rec(path := "~/", filename := "filename")); Error, the component "type" of the 2nd argument must be "dot" or "\ latex", -gap> Splash("string", rec(viewer := "bad")); -Error, the viewer "bad" specified in the option `viewer` is not available, +gap> Splash("string", rec(viewer := "xpdf")); +Error, the viewer "xpdf" specified in the option `viewer` is not available, gap> Splash("string", rec(type := "dot", engine := "dott")); Error, the component "engine" of the 2nd argument must be one of: "\ dot", "neato", "twopi", "circo", "fdp", "sfdp", or "patchwork" @@ -463,132 +423,84 @@ Error, none of the default viewers [ "nonexistent-viewer" onent `viewer`, gap> VizViewers := VizViewers_backup;; gap> MakeReadOnlyGlobal("VizViewers"); +gap> Splash(DotDigraph(RandomDigraph(10)), rec(viewer := 1)); +Error, the option `viewer` must be a string, not an integer, +gap> Splash(DotDigraph(RandomDigraph(10)), rec(viewer := "asdfasfa")); +Error, the viewer "asdfasfa" specified in the option `viewer` is not available\ +, # DotPartialOrderDigraph gap> gr := Digraph([[1], [1, 2], [1, 3], [1, 4], [1 .. 5], [1 .. 6], > [1, 2, 3, 4, 5, 7], [1, 8]]);; -gap> Print(DotPartialOrderDigraph(gr)); -//dot -digraph hgn{ -node [shape=circle] -1 -2 -3 -4 -5 -6 -7 -8 -2 -> 1 -3 -> 1 -4 -> 1 -5 -> 2 -5 -> 3 -5 -> 4 -6 -> 5 -7 -> 5 -8 -> 1 -} +gap> out1 := GraphvizDotPartialOrderDigraph(gr);; +gap> AsString(out1); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t7\ +\n\t8\n\t2 -> 1\n\t3 -> 1\n\t4 -> 1\n\t5 -> 2\n\t5 -> 3\n\t5 -> 4\n\t6 -> 5\n\ +\t7 -> 5\n\t8 -> 1\n}\n" gap> gr := Digraph([[1], [2], [1, 3], [2, 4], [1, 2, 3, 4, 5], [1, 2, 3, 6]]);; -gap> Print(DotPartialOrderDigraph(gr)); -//dot -digraph hgn{ -node [shape=circle] -1 -2 -3 -4 -5 -6 -3 -> 1 -4 -> 2 -5 -> 3 -5 -> 4 -6 -> 3 -6 -> 2 -} +gap> out2 := GraphvizDotPartialOrderDigraph(gr);; +gap> AsString(out2); +"digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t5\n\t6\n\t3 \ +-> 1\n\t4 -> 2\n\t5 -> 3\n\t5 -> 4\n\t6 -> 3\n\t6 -> 2\n}\n" gap> gr := Digraph([[1], []]);; -gap> DotPartialOrderDigraph(gr); +gap> GraphvizDotPartialOrderDigraph(gr);; Error, the argument must be a partial order digraph, +# +gap> DIGRAPHS_StopTest(); +gap> STOP_TEST("Digraphs package: standard/display.tst", 0); + # DotPreorderDigraph and DotQuasiorderDigraph -gap> DotPreorderDigraph(CompleteDigraph(5)); +gap> GraphvizDotPreorderDigraph(CompleteDigraph(5));; Error, the argument must be a preorder digraph, gap> gr := Digraph([[1], [1, 2], [1, 3], [1, 4], [1 .. 5], [1 .. 6], > [1, 2, 3, 4, 5, 7], [1, 8]]);; -gap> Print(DotPreorderDigraph(gr), "\n"); -//dot -digraph graphname { -node [shape=Mrecord, height=0.5, fixedsize=true]ranksep=1; -1 [label="1", width=0.5] -2 [label="2", width=0.5] -3 [label="3", width=0.5] -4 [label="4", width=0.5] -5 [label="5", width=0.5] -6 [label="6", width=0.5] -7 [label="7", width=0.5] -8 [label="8", width=0.5] -2 -> 1 -3 -> 1 -4 -> 1 -5 -> 2 -5 -> 3 -5 -> 4 -6 -> 5 -7 -> 5 -8 -> 1 -} +gap> out1 := GraphvizDotPreorderDigraph(gr);; +gap> AsString(out1); +"digraph graphname {\n\tnode [shape=\"Mrecord\"] height=\"0.5\" fixedsize=\"tr\ +ue\" ranksep=\"1\" \n\t1 [label=\"1\", width=0.5]\n\t2 [label=\"2\", width=0.5\ +]\n\t3 [label=\"3\", width=0.5]\n\t4 [label=\"4\", width=0.5]\n\t5 [label=\"5\ +\", width=0.5]\n\t6 [label=\"6\", width=0.5]\n\t7 [label=\"7\", width=0.5]\n\t\ +8 [label=\"8\", width=0.5]\n\t2 -> 1\n\t3 -> 1\n\t4 -> 1\n\t5 -> 2\n\t5 -> 3\n\ +\t5 -> 4\n\t6 -> 5\n\t7 -> 5\n\t8 -> 1\n}\n" gap> gr := Concatenation("&X_?_A]|^Vr[nHpmVcy~zy[A????_???G??B]nhtmvcwvJq\\^~", > "|m??_AEx]Rb[nHo??__vJy[??A??O_aV~^Zb]njo???_???GZdxMLy}n_");; gap> gr := DigraphFromDigraph6String(gr);; -gap> Print(DotPreorderDigraph(gr){[1 .. 94]}, "\n"); -//dot -digraph graphname { -node [shape=Mrecord, height=0.5, fixedsize=true]ranksep=1; -1 [label= +gap> out2 := GraphvizDotPreorderDigraph(gr);; +gap> AsString(out2); +"digraph graphname {\n\tnode [shape=\"Mrecord\"] height=\"0.5\" fixedsize=\"tr\ +ue\" ranksep=\"1\" \n\t1 [label=\"23\", width=0.5]\n\t2 [label=\"13\", width=0\ +.5]\n\t3 [label=\"1\", width=0.5]\n\t4 [label=\"8\", width=0.5]\n\t5 [label=\"\ +7\", width=0.5]\n\t6 [label=\"6\", width=0.5]\n\t7 [label=\"22\", width=0.5]\n\ +\t8 [label=\"16\", width=0.5]\n\t9 [label=\"19\", width=0.5]\n\t10 [label=\"4|\ +3|15|14|11|24\", width=3.]\n\t11 [label=\"17\", width=0.5]\n\t12 [label=\"9\",\ + width=0.5]\n\t13 [label=\"21\", width=0.5]\n\t14 [label=\"25\", width=0.5]\n\ +\t15 [label=\"2\", width=0.5]\n\t16 [label=\"10\", width=0.5]\n\t17 [label=\"5\ +\", width=0.5]\n\t18 [label=\"20\", width=0.5]\n\t19 [label=\"12\", width=0.5]\ +\n\t20 [label=\"18\", width=0.5]\n\t2 -> 1\n\t3 -> 2\n\t8 -> 7\n\t9 -> 2\n\t9 \ +-> 4\n\t10 -> 9\n\t10 -> 5\n\t10 -> 6\n\t10 -> 8\n\t11 -> 10\n\t12 -> 11\n\t13\ + -> 12\n\t14 -> 13\n\t15 -> 3\n\t15 -> 14\n\t16 -> 3\n\t16 -> 10\n\t17 -> 16\n\ +\t17 -> 12\n\t18 -> 17\n\t19 -> 18\n}\n" gap> gr := DigraphDisjointUnion(CompleteDigraph(10), > CompleteDigraph(5), > CycleDigraph(2));; gap> gr := DigraphReflexiveTransitiveClosure(DigraphAddEdge(gr, [10, 11]));; gap> IsPreorderDigraph(gr); true -gap> Print(DotPreorderDigraph(gr), "\n"); -//dot -digraph graphname { -node [shape=Mrecord, height=0.5, fixedsize=true]ranksep=1; -1 [label="11|12|13|14|15", width=2.5] -2 [label="1|2|3|4|5|6|7|8|9|10", width=5.] -3 [label="16|17", width=1.] -2 -> 1 -} +gap> out3 := GraphvizDotPreorderDigraph(gr);; +gap> AsString(out3); +"digraph graphname {\n\tnode [shape=\"Mrecord\"] height=\"0.5\" fixedsize=\"tr\ +ue\" ranksep=\"1\" \n\t1 [label=\"11|12|13|14|15\", width=2.5]\n\t2 [label=\"1\ +|2|3|4|5|6|7|8|9|10\", width=5.]\n\t3 [label=\"16|17\", width=1.]\n\t2 -> 1\n}\ +\n" # DotHighlightedDigraph -gap> gr := Digraph([[2, 3], [2], [1, 3]]); - -gap> Print(DotHighlightedDigraph(gr, [1, 2], "red", "black")); -//dot -digraph hgn{ -subgraph lowverts{ -node [shape=circle, color=black] - edge [color=black] -3 -} -subgraph highverts{ -node [shape=circle, color=red] - edge [color=red] -1 -2 -} -subgraph lowverts{ -3 -> 1 -3 -> 3 -} -subgraph highverts{ -1 -> 2 -1 -> 3 [color=black] -2 -> 2 -} -} +gap> gr := Digraph([[2, 3], [2], [1, 3]]);; +gap> out1 := GraphvizDotHighlightedDigraph(gr, [1, 2], "red", "black");; +gap> ReplacedString(AsString(out1), ">", "<"); +"digraph hgn {\n\t3 [color=black, shape=circle]\n\t1 [color=red, shape=circle]\ +\n\t2 [color=red, shape=circle]\n\t3 -< 1 [color=black]\n\t3 -< 3 [color=black\ +]\n\t1 -< 2 [color=red]\n\t1 -< 3 [color=black]\n\t2 -< 2 [color=red]\n}\n" gap> D := CycleDigraph(5);; gap> DotHighlightedDigraph(D, [10], "black", "grey"); Error, the 2nd argument must be a list of vertices of the 1st argu\ @@ -599,52 +511,12 @@ Error, the 3rd argument must be a string containing the name of a\ gap> DotHighlightedDigraph(D, [1], "black", ""); Error, the 4th argument must be a string containing the name of a \ colour, -gap> Print(DotHighlightedDigraph(D, Filtered(DigraphVertices(D), IsEvenInt))); -//dot -digraph hgn{ -subgraph lowverts{ -node [shape=circle, color=grey] - edge [color=grey] -1 -3 -5 -} -subgraph highverts{ -node [shape=circle, color=black] - edge [color=black] -2 -4 -} -subgraph lowverts{ -1 -> 2 -3 -> 4 -5 -> 1 -} -subgraph highverts{ -2 -> 3 [color=grey] -4 -> 5 [color=grey] -} -} - -# Splash -gap> Splash(DotDigraph(RandomDigraph(10)), rec(viewer := 1)); -Error, the option `viewer` must be a string, not an integer, -gap> Splash(DotDigraph(RandomDigraph(10)), rec(viewer := "asdfasfa")); -Error, the viewer "asdfasfa" specified in the option `viewer` is not available\ -, - -# DIGRAPHS_UnbindVariables -gap> Unbind(D); -gap> Unbind(adj); -gap> Unbind(backup); -gap> Unbind(dot); -gap> Unbind(edgecolors); -gap> Unbind(gr); -gap> Unbind(gr1); -gap> Unbind(gr2); -gap> Unbind(r); -gap> Unbind(tmpdir); -gap> Unbind(vertcolors); +gap> out2 := GraphvizDotHighlightedDigraph(D, Filtered(DigraphVertices(D), IsEvenInt));; +gap> AsString(out2); +"digraph hgn {\n\t1 [color=grey, shape=circle]\n\t3 [color=grey, shape=circle]\ +\n\t5 [color=grey, shape=circle]\n\t2 [color=black, shape=circle]\n\t4 [color=\ +black, shape=circle]\n\t1 -> 2 [color=grey]\n\t3 -> 4 [color=grey]\n\t5 -> 1 [\ +color=grey]\n\t2 -> 3 [color=grey]\n\t4 -> 5 [color=grey]\n}\n" # gap> DIGRAPHS_StopTest(); From 6b54550cea1eb95bbbb94add5a192f2208f341ea Mon Sep 17 00:00:00 2001 From: mpan322 Date: Fri, 22 Mar 2024 17:55:10 +0000 Subject: [PATCH 3/4] fixed gaplint --- gap/display.gd | 6 ++++-- gap/display.gi | 51 ++++++++++++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/gap/display.gd b/gap/display.gd index dc201a73a..808775f91 100644 --- a/gap/display.gd +++ b/gap/display.gd @@ -14,8 +14,10 @@ DeclareOperation("GraphvizDotVertexColoredDigraph", [IsDigraph, IsList]); DeclareOperation("GraphvizDotEdgeColoredDigraph", [IsDigraph, IsList]); DeclareOperation("GraphvizDotVertexLabelledDigraph", [IsDigraph]); DeclareAttribute("GraphvizDotSymmetricDigraph", IsDigraph); -DeclareOperation("GraphvizDotSymmetricColoredDigraph", [IsDigraph, IsList, IsList]); -DeclareOperation("GraphvizDotSymmetricVertexColoredDigraph", [IsDigraph, IsList]); +DeclareOperation("GraphvizDotSymmetricColoredDigraph", + [IsDigraph, IsList, IsList]); +DeclareOperation("GraphvizDotSymmetricVertexColoredDigraph", + [IsDigraph, IsList]); DeclareOperation("GraphvizDotSymmetricEdgeColoredDigraph", [IsDigraph, IsList]); DeclareAttribute("GraphvizDotPartialOrderDigraph", IsDigraph); DeclareAttribute("GraphvizDotPreorderDigraph", IsDigraph); diff --git a/gap/display.gi b/gap/display.gi index 9407a991c..c4d919ad3 100644 --- a/gap/display.gi +++ b/gap/display.gi @@ -154,12 +154,16 @@ InstallMethod(DotDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], D -> AsString(GraphvizDotDigraph(D))); -InstallMethod(GraphvizDotColoredDigraph, "for a digraph by out-neighbours and two lists", +InstallMethod(GraphvizDotColoredDigraph, +"for a digraph by out-neighbours and two lists", [IsDigraphByOutNeighboursRep, IsList, IsList], function(D, vert, edge) - local vert_func, edge_func; - if GV_DIGRAPHS_ValidVertColors(D, vert) and GV_DIGRAPHS_ValidEdgeColors(D, edge) then - vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + local vert_func, cond, edge_func; + cond := GV_DIGRAPHS_ValidVertColors(D, vert); + cond := cond and GV_DIGRAPHS_ValidEdgeColors(D, edge); + if cond then + vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], + style := "filled")); edge_func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); return GV_DIGRAPHS_DotDigraph(D, [vert_func], [edge_func]); fi; @@ -175,12 +179,13 @@ InstallMethod(GraphvizDotVertexColoredDigraph, function(D, vert) local func; if GV_DIGRAPHS_ValidVertColors(D, vert) then - func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], + style := "filled")); return GV_DIGRAPHS_DotDigraph(D, [func], []); fi; end); -InstallMethod(DotVertexColoredDigraph, +InstallMethod(DotVertexColoredDigraph, "for a digraph by out-neighbours and a list", [IsDigraphByOutNeighboursRep, IsList], {D, vert} -> AsString(GraphvizDotVertexColoredDigraph(D, vert))); @@ -201,28 +206,29 @@ InstallMethod(DotEdgeColoredDigraph, [IsDigraphByOutNeighboursRep, IsList], {D, edge} -> AsString(GraphvizDotEdgeColoredDigraph(D, edge))); -InstallMethod(GraphvizDotVertexLabelledDigraph, "for a digraph by out-neighbours", +InstallMethod(GraphvizDotVertexLabelledDigraph, +"for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], function(D) local func; - func := {g, n, i} -> GraphvizSetAttrs(n, rec(label := DigraphVertexLabel(D, i))); - return GV_DIGRAPHS_DotDigraph(D, [func], []); + func := {g, n, i} -> GraphvizSetAttrs(n, rec(label := + DigraphVertexLabel(D, i))); + return GV_DIGRAPHS_DotDigraph(D, [func], []); end); InstallMethod(DotVertexLabelledDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], {D} -> AsString(GraphvizDotVertexLabelledDigraph(D))); - BindGlobal("GV_DIGRAPHS_DotSymmetricDigraph", function(D, node_funcs, edge_funcs) - local graph, node, nodes, edge, out, n1, n2, str, i, j, func; + local graph, node, nodes, edge, out, n1, n2, i, j, func; if not IsSymmetricDigraph(D) then ErrorNoReturn("the argument must be a symmetric digraph,"); fi; out := OutNeighbours(D); - + graph := GraphvizGraph("hgn"); GraphvizSetAttr(graph, "node [shape=\"circle\"]"); for i in DigraphVertices(D) do @@ -260,9 +266,12 @@ InstallMethod(GraphvizDotSymmetricColoredDigraph, "for a digraph by out-neighbours and two lists", [IsDigraphByOutNeighboursRep, IsList, IsList], function(D, vert, edge) - local vert_func, edge_func; - if GV_DIGRAPHS_ValidVertColors(D, vert) and GV_DIGRAPHS_ValidEdgeColors(D, edge) then - vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + local vert_func, cond, edge_func; + cond := GV_DIGRAPHS_ValidVertColors(D, vert); + cond := cond and GV_DIGRAPHS_ValidEdgeColors(D, edge); + if cond then + vert_func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], + style := "filled")); edge_func := {g, e, i, j} -> GraphvizSetAttrs(e, rec(color := edge[i][j])); return GV_DIGRAPHS_DotSymmetricDigraph(D, [vert_func], [edge_func]); fi; @@ -274,7 +283,8 @@ InstallMethod(GraphvizDotSymmetricVertexColoredDigraph, function(D, vert) local func; if GV_DIGRAPHS_ValidVertColors(D, vert) then - func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], style := "filled")); + func := {g, n, i} -> GraphvizSetAttrs(n, rec(color := vert[i], + style := "filled")); return GV_DIGRAPHS_DotSymmetricDigraph(D, [func], []); fi; end); @@ -314,7 +324,7 @@ InstallMethod(DotPartialOrderDigraph, "for a partial order digraph", InstallMethod(GraphvizDotPreorderDigraph, "for a preorder digraph", [IsDigraph], function(D) - local comps, quo, red, str, c, x, e, node, graph, label, head, tail, nodes; + local comps, quo, red, c, x, e, node, graph, label, head, tail, nodes; if not IsPreorderDigraph(D) then ErrorNoReturn("the argument must be a preorder digraph,"); fi; @@ -364,7 +374,6 @@ InstallMethod(DotPreorderDigraph, "for a preorder digraph", [IsDigraph], {D} -> AsString(GraphvizDotPreorderDigraph(D))); - InstallMethod(GraphvizDotHighlightedDigraph, "for a digraph and list", [IsDigraph, IsList], {D, list} -> GraphvizDotHighlightedDigraph(D, list, "black", "grey")); @@ -397,13 +406,12 @@ function(D, highverts, highcolour, lowcolour) for i in lowverts do node := GraphvizAddNode(graph, String(i)); - GraphvizSetAttrs(node, rec( shape := "circle", color := lowcolour)); + GraphvizSetAttrs(node, rec(shape := "circle", color := lowcolour)); od; - for i in highverts do node := GraphvizAddNode(graph, String(i)); - GraphvizSetAttrs(node, rec( shape := "circle", color := highcolour)); + GraphvizSetAttrs(node, rec(shape := "circle", color := highcolour)); od; nodes := GraphvizNodes(graph); @@ -427,7 +435,6 @@ function(D, highverts, highcolour, lowcolour) return graph; end); - InstallMethod(DotHighlightedDigraph, "for a digraph by out-neighbours, list, and two strings", [IsDigraphByOutNeighboursRep, IsList, IsString, IsString], From c5ca57a9879df48ab0d3a5c7764264120ba85386 Mon Sep 17 00:00:00 2001 From: mpan322 Date: Fri, 22 Mar 2024 17:58:21 +0000 Subject: [PATCH 4/4] more gaplint fixes --- gap/cographs-TODO.md | 10 ---------- tst/standard/display.tst | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 gap/cographs-TODO.md diff --git a/gap/cographs-TODO.md b/gap/cographs-TODO.md deleted file mode 100644 index e7018cb0b..000000000 --- a/gap/cographs-TODO.md +++ /dev/null @@ -1,10 +0,0 @@ -- Dahlhaus parallel cographs algorithm -- Algo in this paper https://www.sciencedirect.com/science/article/pii/S0166218X04002446?via%3Dihub - - this paper only works for finite undirected graphs w/o multiple edges -- Look into cograph decomposition tree computation - - -- https://inria.hal.science/hal-00958972/document - -- https://www.cs.colostate.edu/~rmm/DGM97.pdf -- file:///home/mp322/Downloads/Schulz_Christian.pdf \ No newline at end of file diff --git a/tst/standard/display.tst b/tst/standard/display.tst index dc4b60df7..a87483c7d 100644 --- a/tst/standard/display.tst +++ b/tst/standard/display.tst @@ -333,7 +333,7 @@ gap> edgecolors[4][1] := "lightblue";; gap> edgecolors[4][2] := "pink";; gap> edgecolors[4][3] := "purple";; gap> out1 := GraphvizDotEdgeColoredDigraph(D, edgecolors);; -gap> AsString(out1){[1..300]}; +gap> AsString(out1){[1 .. 300]}; "digraph hgn {\n\tnode [shape=\"circle\"] \n\t1\n\t2\n\t3\n\t4\n\t1 -> 2 [colo\ r=lightblue]\n\t1 -> 3 [color=pink]\n\t1 -> 4 [color=purple]\n\t2 -> 1 [color=\ lightblue]\n\t2 -> 3 [color=pink]\n\t2 -> 4 [color=purple]\n\t3 -> 1 [color=li\