From 5ca4c0ad1acdd1a4da95484e7066e6cc56a5603a Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Thu, 15 Nov 2018 16:51:30 +0000 Subject: [PATCH] grahom: improve DigraphColouring This commit implements the Welsh-Powell algorithm for digraph colouring. This implementation is almost always as good as the previous one (in terms of the number of colours required), and is faster (approx. 4 times faster on DigraphRemoveLoops(RandomDigraph(10000, 0.1))). --- doc/digraphs.bib | 14 ++++ doc/grahom.xml | 83 +++++++++++++++++--- doc/prop.xml | 2 +- doc/z-appA.xml | 8 +- doc/z-chap6.xml | 2 + gap/attr.gi | 14 ++-- gap/grahom.gd | 11 ++- gap/grahom.gi | 100 +++++++++++++++++-------- tst/standard/attr.tst | 14 ++-- tst/standard/grahom.tst | 162 ++++++++++++++++++++++++++++++++++------ 10 files changed, 322 insertions(+), 88 deletions(-) diff --git a/doc/digraphs.bib b/doc/digraphs.bib index f588fd300..459a70e54 100644 --- a/doc/digraphs.bib +++ b/doc/digraphs.bib @@ -94,3 +94,17 @@ @article {vanLintSchrijver1981 DOI = {10.1007/BF02579178}, URL = {http://dx.doi.org/10.1007/BF02579178}, } + +@article{Welsh1967aa, +author = {Welsh, D. J. A. and Powell, M. B.}, +title = {An upper bound for the chromatic number of a graph and its application to timetabling problems}, +journal = {The Computer Journal}, +volume = {10}, +number = {1}, +pages = {85-86}, +year = {1967}, +doi = {10.1093/comjnl/10.1.85}, +URL = {http://dx.doi.org/10.1093/comjnl/10.1.85}, +eprint = {/oup/backfile/content_public/journal/comjnl/10/1/10.1093/comjnl/10.1.85/2/100085.pdf} +} + diff --git a/doc/grahom.xml b/doc/grahom.xml index 79c1345c5..42b23c558 100644 --- a/doc/grahom.xml +++ b/doc/grahom.xml @@ -359,10 +359,6 @@ gap> GeneratorsOfEndomorphismMonoid(gr, [[1], [2, 3]]); Label="for a digraph and a number of colours"/> - - A transformation, or fail. A proper colouring of a digraph is a labelling of its vertices in @@ -381,10 +377,8 @@ gap> GeneratorsOfEndomorphismMonoid(gr, [[1], [2, 3]]); from digraph onto the complete digraph with n vertices if one exists, else it returns fail.

- If the optional second argument n is not provided, then - DigraphColouring uses a greedy algorithm to obtain some proper - colouring of digraph, which may not use the minimal number of - colours.

+ See also and +

Note that a digraph with at least two vertices has a 2-colouring if and only if it is bipartite, see . @@ -399,13 +393,84 @@ gap> t := DigraphColouring(gr, 2); Transformation( [ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ] ) gap> ForAll(DigraphEdges(gr), e -> e[1] ^ t <> e[2] ^ t); true -gap> DigraphColouring(gr); +gap> DigraphGreedyColouring(gr); +Transformation( [ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 ] ) +]]> + + +<#/GAPDoc> + +<#GAPDoc Label="DigraphGreedyColouring"> + + + + + A transformation, or fail. + + A proper colouring of a digraph is a labelling of its vertices in + such a way that adjacent vertices have different labels. Note that a digraph + with loops () does not have any proper + colouring. +

+ + If digraph is a digraphs and order is a dense list consisting + of all of the vertices of digraph (in any order), then + DigraphGreedyColouring + uses a greedy algorithm with the specified order to obtain some proper + colouring of digraph, which may not use the minimal number of + colours.

+ + If digraph is a digraph and func is a function whose argument + is a digraph, and that returns a dense list order, then + DigraphGreedyColouring(digraph, func) returns + DigraphGreedyColouring(digraph, func(digraph)). +

+ + If the optional second argument (either a list or a function), is not + specified, then is used by default. +

+ + See also + . +

+ + DigraphGreedyColouring(ChainDigraph(10)); +Transformation( [ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 ] ) +gap> DigraphGreedyColouring(ChainDigraph(10), [1 .. 10]); Transformation( [ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ] ) ]]> <#/GAPDoc> +<#GAPDoc Label="DigraphWelshPowellOrder"> + + + A list of the vertices. + + DigraphWelshPowellOrder returns a list of all of the vertices of + the digraph digraph ordered according to the sum of the number of + out- and in-neighbours, from highest to lowest. +

+ + DigraphWelshPowellOrder(Digraph([[4], [9], [9], [], +> [4, 6, 9], [1], [], [], +> [4, 5], [4, 5]])); +[ 5, 9, 4, 1, 6, 10, 2, 3, 7, 8 ] +]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphEmbedding"> diff --git a/doc/prop.xml b/doc/prop.xml index a0ee1c978..0301b4a02 100644 --- a/doc/prop.xml +++ b/doc/prop.xml @@ -671,7 +671,7 @@ true vertices of digraph can be partitioned into two non-empty sets such that the source and range of any edge of digraph lie in distinct sets. Equivalently, a digraph is bipartite if and only if it is 2-colorable; see - .

+ .

See also . VertexColouring - + VertexColouring in &Grape; is equivalent to in &Digraphs;, - except it return a transformation rather than a list of vertex + Attr="DigraphGreedyColouring" Label="for a digraph"/> in &Digraphs;, + except it returns a transformation rather than a list of vertex colors. @@ -1357,6 +1357,4 @@ - - diff --git a/doc/z-chap6.xml b/doc/z-chap6.xml index a0cbcf193..26f61cb03 100644 --- a/doc/z-chap6.xml +++ b/doc/z-chap6.xml @@ -59,6 +59,8 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are <#Include Label="EpimorphismsDigraphs"> <#Include Label="GeneratorsOfEndomorphismMonoid"> <#Include Label="DigraphColouring"> + <#Include Label="DigraphGreedyColouring"> + <#Include Label="DigraphWelshPowellOrder"> <#Include Label="DigraphEmbedding"> <#Include Label="ChromaticNumber"> <#Include Label="IsDigraphHomomorphism"> diff --git a/gap/attr.gi b/gap/attr.gi index 2244742bb..94058cd17 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -91,7 +91,7 @@ end); InstallMethod(ChromaticNumber, "for a digraph", [IsDigraph], function(digraph) local nr, comps, upper, chrom, tmp_comps, tmp_upper, n, comp, bound, clique, - cmp, c, i; + c, i; nr := DigraphNrVertices(digraph); @@ -128,7 +128,7 @@ function(digraph) # do not yet know. if IsConnectedDigraph(digraph) then comps := [digraph]; - upper := [RankOfTransformation(DigraphColoring(digraph), nr)]; + upper := [RankOfTransformation(DigraphGreedyColouring(digraph), nr)]; chrom := Maximum(CliqueNumber(digraph), chrom); else tmp_comps := []; @@ -151,7 +151,7 @@ function(digraph) # If comp is bipartite, then its chromatic number is 2, and, since # the chromatic number of digraph is >= 3, this component can be # ignored. - bound := RankOfTransformation(DigraphColoring(comp), + bound := RankOfTransformation(DigraphGreedyColouring(comp), DigraphNrVertices(comp)); if bound > chrom then # If bound <= chrom, then comp can be coloured by at most chrom @@ -187,16 +187,12 @@ function(digraph) od; # Sort by size, since smaller components are easier to colour - # TODO replace by 2-arg lambda - cmp := function(x, y) - return Size(x) < Size(y); - end; - SortParallel(comps, upper, cmp); + SortParallel(comps, upper, {x, y} -> Size(x) < Size(y)); fi; for i in [1 .. Length(comps)] do # is the current best upper bound for the chromatic number of comps[i] c := upper[i]; - while c > chrom and DigraphColoring(comps[i], c - 1) <> fail do + while c > chrom and DigraphColouring(comps[i], c - 1) <> fail do c := c - 1; od; if c > chrom then diff --git a/gap/grahom.gd b/gap/grahom.gd index b5d60c4c3..aeac3c567 100644 --- a/gap/grahom.gd +++ b/gap/grahom.gd @@ -28,8 +28,15 @@ DeclareOperation("EpimorphismsDigraphsRepresentatives", [IsDigraph, IsDigraph]); DeclareOperation("DigraphEmbedding", [IsDigraph, IsDigraph]); DeclareOperation("DigraphColouring", [IsDigraph, IsInt]); -DeclareAttribute("DigraphColouring", IsDigraph); -DeclareSynonymAttr("DigraphColoring", DigraphColouring); + +DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsHomogeneousList]); +DeclareOperation("DigraphGreedyColouringNC", [IsDigraph, IsHomogeneousList]); +DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsFunction]); + +DeclareAttribute("DigraphGreedyColouring", IsDigraph); +DeclareSynonym("DigraphGreedyColoring", DigraphGreedyColouring); + +DeclareAttribute("DigraphWelshPowellOrder", IsDigraph); DeclareGlobalFunction("HomomorphismDigraphsFinder"); diff --git a/gap/grahom.gi b/gap/grahom.gi index 84a2970b8..199366e20 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -202,6 +202,15 @@ function(digraph, n) "the second argument must be a non-negative integer,"); fi; + if HasDigraphGreedyColouring(digraph) then + if DigraphGreedyColouring(digraph) = fail then + return fail; + elif RankOfTransformation(DigraphGreedyColouring(digraph), + DigraphNrVertices(digraph)) = n then + return DigraphGreedyColouring(digraph); + fi; + fi; + # Only the null digraph with 0 vertices can be coloured with 0 colours if n = 0 then if DigraphNrVertices(digraph) = 0 then @@ -222,49 +231,76 @@ function(digraph, n) return DigraphEpimorphism(digraph, CompleteDigraph(n)); end); -# +InstallMethod(DigraphGreedyColouring, "for a digraph", [IsDigraph], +function(D) + return DigraphGreedyColouringNC(D, DigraphWelshPowellOrder(D)); +end); -InstallMethod(DigraphColouring, "for a digraph", [IsDigraph], -function(digraph) - local vertices, maxcolour, out_nbs, in_nbs, colouring, usedcolours, - nextcolour, v, u; +InstallMethod(DigraphGreedyColouring, "for a digraph", +[IsDigraph, IsHomogeneousList], +function(D, order) + local n; + n := DigraphNrVertices(D); + if Length(order) <> n or ForAny(order, x -> (not IsPosInt(x)) or x > n) then + ErrorNoReturn("the second argument must be a permutation of ", + [1 .. n]); + fi; + return DigraphGreedyColouringNC(D, order); +end); + +InstallMethod(DigraphGreedyColouringNC, "for a digraph and a homogeneous list", +[IsDigraph, IsHomogeneousList], +function(digraph, order) + local n, colour, colouring, out, inn, empty, all, available, nr_coloured, v; + + n := DigraphNrVertices(digraph); - if DigraphNrVertices(digraph) = 0 then + if n = 0 then return IdentityTransformation; elif DigraphHasLoops(digraph) then return fail; fi; - vertices := DigraphVertices(digraph); - maxcolour := 0; - out_nbs := OutNeighbours(digraph); - in_nbs := InNeighbours(digraph); - - colouring := []; - - for v in vertices do - usedcolours := BlistList([1 .. maxcolour + 1], []); - for u in out_nbs[v] do - if IsBound(colouring[u]) then - usedcolours[colouring[u]] := true; - fi; - od; - for u in in_nbs[v] do - if IsBound(colouring[u]) then - usedcolours[colouring[u]] := true; + colour := 1; + colouring := ListWithIdenticalEntries(n, 0); + out := OutNeighbours(digraph); + inn := InNeighbours(digraph); + empty := BlistList([1 .. n], []); + all := BlistList([1 .. n], [1 .. n]); + available := BlistList([1 .. n], [1 .. n]); + + nr_coloured := 0; + while nr_coloured < n do + for v in order do + if colouring[v] = 0 and available[v] then + nr_coloured := nr_coloured + 1; + colouring[v] := colour; + SubtractBlist(available, BlistList([1 .. n], out[v])); + SubtractBlist(available, BlistList([1 .. n], inn[v])); + if available = empty then + break; + fi; fi; od; - nextcolour := 1; - while usedcolours[nextcolour] do - nextcolour := nextcolour + 1; - od; - colouring[v] := nextcolour; - if colouring[v] > maxcolour then - maxcolour := colouring[v]; - fi; + UniteBlist(available, all); + colour := colour + 1; od; + return TransformationNC(colouring); +end); - return Transformation(colouring); +InstallMethod(DigraphGreedyColouring, "for a digraph and a function", +[IsDigraph, IsFunction], +function(D, func) + return DigraphGreedyColouringNC(D, func(D)); +end); + +InstallMethod(DigraphWelshPowellOrder, "for a digraph", [IsDigraph], +function(digraph) + local order, deg; + order := [1 .. DigraphNrVertices(digraph)]; + deg := ShallowCopy(OutDegrees(digraph)) + InDegrees(digraph); + SortParallel(deg, order, {x, y} -> x > y); + return order; end); ################################################################################ diff --git a/tst/standard/attr.tst b/tst/standard/attr.tst index e84cc6f80..e7f6f0dc6 100644 --- a/tst/standard/attr.tst +++ b/tst/standard/attr.tst @@ -1301,16 +1301,16 @@ gap> gr := DigraphFromDigraph6String(Concatenation( gap> ChromaticNumber(gr); 3 -gap> DigraphColoring(gr, 3); +gap> DigraphColouring(gr, 3); Transformation( [ 1, 2, 2, 1, 2, 1, 3, 1, 1, 2, 2, 2, 1, 2, 1, 2, 1, 1, 3, 3, 3, 2, 3, 3, 2, 2, 1, 3, 1, 3, 3, 3, 2, 1, 3, 1, 3, 1, 1, 2, 2, 3, 3, 3, 2 ] ) -gap> DigraphColoring(gr, 2); +gap> DigraphColouring(gr, 2); fail -gap> DigraphColoring(gr); -Transformation( [ 1, 1, 1, 1, 1, 1, 2, 1, 2, 2, 2, 2, 1, 2, 1, 2, 1, 2, 2, 3, - 3, 2, 3, 3, 3, 2, 1, 4, 4, 3, 3, 3, 3, 1, 3, 1, 3, 4, 4, 2, 2, 5, 3, 3, - 4 ] ) +gap> DigraphGreedyColoring(gr); +Transformation( [ 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 3, + 3, 2, 3, 3, 3, 2, 1, 4, 4, 2, 3, 3, 3, 3, 3, 1, 3, 4, 4, 3, 2, 1, 4, 3, + 1 ] ) gap> gr := Digraph([[2, 3, 4], [3], [], []]); gap> ChromaticNumber(gr); @@ -1368,7 +1368,7 @@ gap> ChromaticNumber(gr); 3 gap> gr := DigraphSymmetricClosure(ChainDigraph(5)); -gap> DigraphColoring(gr);; +gap> DigraphGreedyColoring(gr);; gap> ChromaticNumber(gr); 2 gap> gr := DigraphFromGraph6String("KmKk~K??G@_@"); diff --git a/tst/standard/grahom.tst b/tst/standard/grahom.tst index a219e2a18..ebc056fe9 100644 --- a/tst/standard/grahom.tst +++ b/tst/standard/grahom.tst @@ -252,7 +252,7 @@ gap> GeneratorsOfEndomorphismMonoid(gr); [ Transformation( [ 2, 1 ] ), IdentityTransformation, Transformation( [ 3, 3, 3 ] ) ] -#T# DigraphColouring and DigraphColouring: checking errors and robustness +#T# DigraphGreedyColouring and DigraphColouring: checking errors and robustness gap> gr := Digraph([[2, 2], []]); gap> DigraphColouring(gr, 1); @@ -299,49 +299,165 @@ gap> DigraphColouring(NullDigraph(0), 0); IdentityTransformation gap> DigraphColouring(CompleteDigraph(1), 0); fail +gap> DigraphColouring(Digraph([[1]]), 1); +fail +gap> gr := DigraphFromDigraph6String(Concatenation( +> "+l??O?C?A_@???CE????GAAG?C??M?????@_?OO??G??@?IC???_C?G?o??C?AO???c_??A?", +> "A?S???OAA???OG???G_A??C?@?cC????_@G???S??C_?C???[??A?A?OA?O?@?A?@A???GGO", +> "??`?_O??G?@?A??G?@AH????AA?O@??_??b???Cg??C???_??W?G????d?G?C@A?C???GC?W", +> "?????K???__O[??????O?W???O@??_G?@?CG??G?@G?C??@G???_Q?O?O?c???OAO?C??C?G", +> "?O??A@??D??G?C_?A??O?_GA??@@?_?G???E?IW??????_@G?C??")); + +gap> DigraphGreedyColouring(gr); +Transformation( [ 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 3, + 3, 2, 3, 3, 3, 2, 1, 4, 4, 2, 3, 3, 3, 3, 3, 1, 3, 4, 4, 3, 2, 1, 4, 3, + 1 ] ) +gap> DigraphColouring(gr, 4); +Transformation( [ 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 1, 2, 1, 2, 1, 2, 2, 3, + 3, 2, 3, 3, 3, 2, 1, 4, 4, 2, 3, 3, 3, 3, 3, 1, 3, 4, 4, 3, 2, 1, 4, 3, + 1 ] ) -#T# DigraphColouring -gap> DigraphColouring(EmptyDigraph(0)); +# DigraphGreedyColouring +gap> DigraphGreedyColouring(EmptyDigraph(0)); IdentityTransformation -gap> DigraphColouring(Digraph([[]])); +gap> DigraphGreedyColouring(Digraph([[]])); IdentityTransformation -gap> DigraphColouring(Digraph([[1]])); +gap> DigraphGreedyColouring(Digraph([[1]])); fail -gap> DigraphColouring(Digraph([[1]]), 1); -fail -gap> DigraphColouring(CycleDigraph(2)); +gap> DigraphGreedyColouring(CycleDigraph(2)); IdentityTransformation -gap> DigraphColouring(CycleDigraph(3)); +gap> DigraphGreedyColouring(CycleDigraph(3)); IdentityTransformation -gap> DigraphColouring(CycleDigraph(4)); +gap> DigraphGreedyColouring(CycleDigraph(4)); Transformation( [ 1, 2, 1, 2 ] ) -gap> DigraphColouring(CycleDigraph(5)); +gap> DigraphGreedyColouring(CycleDigraph(5)); Transformation( [ 1, 2, 1, 2, 3 ] ) -gap> DigraphColouring(CycleDigraph(6)); +gap> DigraphGreedyColouring(CycleDigraph(6)); Transformation( [ 1, 2, 1, 2, 1, 2 ] ) -gap> DigraphColouring(CompleteDigraph(10)); +gap> DigraphGreedyColouring(CompleteDigraph(10)); IdentityTransformation gap> gr := CompleteDigraph(4);; -gap> HasDigraphColoring(gr) or HasDigraphColouring(gr); +gap> HasDigraphGreedyColouring(gr); false -gap> DigraphColoring(gr); +gap> DigraphGreedyColouring(gr); IdentityTransformation -gap> HasDigraphColoring(gr) and HasDigraphColouring(gr); +gap> HasDigraphGreedyColouring(gr); true gap> gr := CycleDigraph(4);; -gap> HasDigraphColoring(gr) or HasDigraphColouring(gr); +gap> HasDigraphGreedyColouring(gr); false -gap> DigraphColouring(gr); +gap> DigraphGreedyColouring(gr); Transformation( [ 1, 2, 1, 2 ] ) -gap> HasDigraphColoring(gr) and HasDigraphColouring(gr); +gap> HasDigraphGreedyColouring(gr); true -gap> DigraphColoring(ChainDigraph(10));; -gap> DigraphColoring(CompleteDigraph(10));; +gap> DigraphGreedyColouring(ChainDigraph(10));; +gap> DigraphGreedyColouring(CompleteDigraph(10));; +gap> gr := DigraphFromSparse6String( +> ":]nA?LcB@_EDfEB`GIaHGdJIgEKcLK`?MdCHiFLaBJhFMkJM"); + +gap> DigraphGreedyColouring(gr);; +gap> DigraphGreedyColouring(EmptyDigraph(0)); +IdentityTransformation +gap> DigraphGreedyColouring(gr, [1 .. 10]); +Error, the second argument must be a permutation of [ 1 .. 30 ] +gap> DigraphGreedyColouring(gr, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, +> 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, -1]); +Error, the second argument must be a permutation of [ 1 .. 30 ] +gap> DigraphGreedyColouring(gr, [1 .. 30]); +Transformation( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] ) + +# DigraphWelshPowellOrder +gap> DigraphGreedyColouring(EmptyDigraph(0), DigraphWelshPowellOrder); +IdentityTransformation +gap> DigraphGreedyColouring(Digraph([[]]), DigraphWelshPowellOrder); +IdentityTransformation +gap> DigraphGreedyColouring(Digraph([[1]]), DigraphWelshPowellOrder); +fail +gap> DigraphGreedyColouring(CycleDigraph(2), DigraphWelshPowellOrder); +IdentityTransformation +gap> DigraphGreedyColouring(CycleDigraph(3), DigraphWelshPowellOrder); +IdentityTransformation +gap> DigraphGreedyColouring(CycleDigraph(4), DigraphWelshPowellOrder); +Transformation( [ 1, 2, 1, 2 ] ) +gap> DigraphGreedyColouring(CycleDigraph(5), DigraphWelshPowellOrder); +Transformation( [ 1, 2, 1, 2, 3 ] ) +gap> DigraphGreedyColouring(CycleDigraph(6), DigraphWelshPowellOrder); +Transformation( [ 1, 2, 1, 2, 1, 2 ] ) +gap> DigraphGreedyColouring(CompleteDigraph(10), DigraphWelshPowellOrder); +IdentityTransformation +gap> gr := CompleteDigraph(4);; +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(gr, DigraphWelshPowellOrder); +IdentityTransformation +gap> HasDigraphGreedyColouring(gr); +false +gap> gr := CycleDigraph(4);; +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(gr, DigraphWelshPowellOrder); +Transformation( [ 1, 2, 1, 2 ] ) +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(ChainDigraph(10), DigraphWelshPowellOrder); +Transformation( [ 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 ] ) +gap> DigraphGreedyColouring(CompleteDigraph(10), DigraphWelshPowellOrder); +IdentityTransformation +gap> gr := DigraphFromSparse6String( +> ":]nA?LcB@_EDfEB`GIaHGdJIgEKcLK`?MdCHiFLaBJhFMkJM"); + +gap> DigraphGreedyColouring(gr, DigraphWelshPowellOrder); +Transformation( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] ) +gap> DigraphGreedyColouring(EmptyDigraph(0)); +IdentityTransformation + +# DigraphWelshPowellOrder +gap> order_func := D -> [1 .. DigraphNrVertices(D)];; +gap> DigraphGreedyColouring(EmptyDigraph(0), order_func); +IdentityTransformation +gap> DigraphGreedyColouring(Digraph([[]]), order_func); +IdentityTransformation +gap> DigraphGreedyColouring(Digraph([[1]]), order_func); +fail +gap> DigraphGreedyColouring(CycleDigraph(2), order_func); +IdentityTransformation +gap> DigraphGreedyColouring(CycleDigraph(3), order_func); +IdentityTransformation +gap> DigraphGreedyColouring(CycleDigraph(4), order_func); +Transformation( [ 1, 2, 1, 2 ] ) +gap> DigraphGreedyColouring(CycleDigraph(5), order_func); +Transformation( [ 1, 2, 1, 2, 3 ] ) +gap> DigraphGreedyColouring(CycleDigraph(6), order_func); +Transformation( [ 1, 2, 1, 2, 1, 2 ] ) +gap> DigraphGreedyColouring(CompleteDigraph(10), order_func); +IdentityTransformation +gap> gr := CompleteDigraph(4);; +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(gr, order_func); +IdentityTransformation +gap> HasDigraphGreedyColouring(gr); +false +gap> gr := CycleDigraph(4);; +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(gr, order_func); +Transformation( [ 1, 2, 1, 2 ] ) +gap> HasDigraphGreedyColouring(gr); +false +gap> DigraphGreedyColouring(ChainDigraph(10), order_func); +Transformation( [ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ] ) +gap> DigraphGreedyColouring(CompleteDigraph(10), order_func); +IdentityTransformation gap> gr := DigraphFromSparse6String( > ":]nA?LcB@_EDfEB`GIaHGdJIgEKcLK`?MdCHiFLaBJhFMkJM"); -gap> DigraphColoring(gr);; -gap> DigraphColoring(EmptyDigraph(0)); +gap> DigraphGreedyColouring(gr, order_func); +Transformation( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 ] ) +gap> DigraphGreedyColouring(EmptyDigraph(0)); IdentityTransformation #T# HomomorphismDigraphsFinder 1