From a9431e7387ac4d1406b62e802c39004810a6dc32 Mon Sep 17 00:00:00 2001 From: Rheya Monerasinghe Date: Wed, 25 Feb 2026 14:13:21 +0000 Subject: [PATCH 1/4] ColourRefinement non-optimised method --- gap/grahom.gd | 2 + gap/grahom.gi | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/gap/grahom.gd b/gap/grahom.gd index b18ecce70..cd14fa25f 100644 --- a/gap/grahom.gd +++ b/gap/grahom.gd @@ -41,6 +41,8 @@ DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsFunction]); DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsHomogeneousList]); DeclareOperation("DigraphGreedyColouringNC", [IsDigraph, IsHomogeneousList]); +DeclareOperation("DigraphColourRefinement", [IsDigraph]); + DeclareAttribute("DigraphWelshPowellOrder", IsDigraph); DeclareAttribute("DigraphSmallestLastOrder", IsDigraph); # TODO: document diff --git a/gap/grahom.gi b/gap/grahom.gi index 5628a3650..42a93ce3b 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -183,6 +183,126 @@ InstallMethod(DigraphGreedyColouring, "for a digraph and a function", [IsDigraph, IsFunction], {D, func} -> DigraphGreedyColouringNC(D, func(D))); +InstallMethod(DigraphColourRefinement, "for a digraph", [IsDigraph], +function(D) + + local listResult, i, round, c_min, c_max, set, Q, q, C, CD, j, P, v, B, SCD, Sets, pair, pointer, current, currentPair, newSet, colour; + + c_min := 1; + c_max := 1; + + # Queue of colours + Q := [1]; + + # Initial colouring + # vertices -> colour + # TODO: see if can change to single non-for loop line + C := rec(); + for v in DigraphVertices(D) do + C.(v) := 1; + od; + + # Colour classes + # All vertices initialised to 1 + # colour -> vertices labelled as such + P := rec(1 := DigraphVertices(D)); + + while not IsEmpty(Q) do + + # Pop colour off Q + q := Q[1]; + Remove(Q, 1); + + # For each v in V (all vertices in D) + # Get the neighbours of v that are in the colour class q + B := rec(); + for v in DigraphVertices(D) do + B.(v) := Intersection(Union(OutNeighbours(D)[v], + InNeighbours(D)[v]), P.(q)); + od; + + # CD: colour of v vs number of q coloured neighbours for all v in D + CD := []; + for v in DigraphVertices(D) do + Add(CD, [C.(v), Length(B.(v)), v]); + od; + + Sort(CD); + + # Put into sets + Sets := []; + currentPair := []; + newSet := []; + + j := 0; + + for pair in CD do + current := [pair[1], pair[2]]; + + # If first pair OR has the same values as the prev pair: + if currentPair = [] or current = currentPair then + Add(newSet, pair[3]); + else + # Doesn't have the same values as the prev pair + Add(Sets, newSet); + newSet := [pair[3]]; + + # If they had the same colour but diff no. neighbours + if pair[1] = currentPair[1] then + + # Push a new number to Q + j := j + 1; + fi; + fi; + currentPair := current; + od; + Add(Sets, newSet); + + # If there is reason for recolouring + if j > 0 then + + # Clearing P + # TODO: Can P be a list from the start? + # Would simplify this a lot vv + colour := c_min; + while colour <= c_max do + P.(colour) := []; + colour := colour + 1; + od; + + # Pushing the last value to Q + # TODO: look into largest set number for optimisation + for i in [1 .. Length(Sets)] do + Add(Q, c_max + i); + od; + + # Updating colours for the next round + c_min := c_max + 1; + c_max := c_max + Length(Sets); + + # Updating C and P + colour := c_min; + + for set in Sets do + P.(colour) := set; + + for v in set do + C.(v) := colour; + od; + colour := colour + 1; + od; + fi; + od; + + # Normalising results to a list starting at index 1 + listResult := []; + for i in [c_min .. c_max] do + Add(listResult, P.(i)); + od; + return listResult; + +end); + InstallMethod(DigraphWelshPowellOrder, "for a digraph", [IsDigraph], function(D) local order, deg; From d965a01f0b5b73c4c4e624f7df60903bfb075d20 Mon Sep 17 00:00:00 2001 From: Rheya Monerasinghe Date: Wed, 25 Feb 2026 15:48:50 +0000 Subject: [PATCH 2/4] Tests added for DigraphColourRefinement() --- tst/standard/grahom.tst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tst/standard/grahom.tst b/tst/standard/grahom.tst index 470c89e17..f9127d313 100644 --- a/tst/standard/grahom.tst +++ b/tst/standard/grahom.tst @@ -2898,6 +2898,32 @@ gap> HomomorphismDigraphsFinder(H, > Group(())); [ Transformation( [ 8, 1, 5, 7, 3, 4, 6, 8 ] ) ] +# DigraphColourRefinement +gap> D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; +gap> DigraphColourRefinement(D); +[ [ 2, 4 ], [ 1, 5 ], [ 7, 8 ], [ 3, 10 ], [ 9 ], [ 6 ] ] +gap> D := Digraph([[], [1], [1], [1]]);; +gap> DigraphColourRefinement(D); +[ [ 1 ], [ 2, 3, 4 ] ] +gap> D := Digraph([[1], [1], [1], [1]]);; +gap> DigraphColourRefinement(D); +Error, the digraph cannot contain loops +gap> D := Digraph([[], [], [], []]);; +gap> DigraphColourRefinement(D); +[ [ 1 .. 4 ] ] +gap> D := Digraph([[2], [3], [2, 4], [2, 5], [4, 6], [5]]);; +gap> DigraphColourRefinement(D); +[ [ 2, 6 ], [ 1 ], [ 3, 4, 5 ] ] +gap> D := Digraph([[2], [3], [1]]);; +gap> DigraphColourRefinement(D); +[ [ 1 .. 3 ] ] +gap> D := Digraph([[2, 4], [5], [2, 4], [5], [1, 3]]);; +gap> DigraphColourRefinement(D); +[ [ 2, 4 ], [ 5 ], [ 1, 3 ] ] +gap> D := Digraph([[4], [1, 3], [4], [5], [1, 3]]);; +gap> DigraphColourRefinement(D); +[ [ 1, 3 ], [ 4 ], [ 2, 5 ] ] + # gap> DIGRAPHS_StopTest(); gap> STOP_TEST("Digraphs package: standard/grahom.tst", 0); From 57ce2391b3ea5e6824c309f27be540c99dc152f9 Mon Sep 17 00:00:00 2001 From: Rheya Monerasinghe Date: Wed, 11 Mar 2026 14:33:32 +0000 Subject: [PATCH 3/4] DigraphColourRefinement considering out and in neighbours separately, and without optimisation --- doc/grahom.xml | 32 ++++++++++++++++++++++++++++++++ gap/grahom.gi | 32 ++++++++++++++++++++++---------- tst/standard/grahom.tst | 6 +++--- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/doc/grahom.xml b/doc/grahom.xml index 2e3d1b213..d0a06bbbc 100644 --- a/doc/grahom.xml +++ b/doc/grahom.xml @@ -543,6 +543,38 @@ Transformation( [ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ] ) <#/GAPDoc> +<#GAPDoc Label="DigraphColourRefinement"> + + + A list of lists of integers. + + Colour Refinement is a method of colouring a digraph such that for a colour, every + node with that colouring has an identical configuration of coloured neighbours. That is, + all nodes of colour q have the same number of neighbours of colour x, and colour y, etc. + DigraphColourRefinement considers the out neighbours and in neighbours of a node separately. +

+ This involves recolouring the digraph each iteration until it is 'refined'. It returns the colouring as a + 2D list. For two digraphs with different colourings, we can be sure that they are not isomorphic. However, + identical colourings for two digraphs does not necessarily mean they are isomorphic. +

+ See also + . +

+ + D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; +gap> DigraphColourRefinement(D); +[ [ 2, 4 ], [ 1, 5 ], [ 7, 8 ], [ 3, 10 ], [ 9 ], [ 6 ] ] +gap> DigraphColourRefinement(Digraph([[], [1], [1], [1]])); +[ [ 1 ], [ 2, 3, 4 ] ] +]]> + + +<#/GAPDoc> + <#GAPDoc Label="DigraphWelshPowellOrder"> diff --git a/gap/grahom.gi b/gap/grahom.gi index 42a93ce3b..7fd4799cb 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -186,7 +186,13 @@ InstallMethod(DigraphGreedyColouring, "for a digraph and a function", InstallMethod(DigraphColourRefinement, "for a digraph", [IsDigraph], function(D) - local listResult, i, round, c_min, c_max, set, Q, q, C, CD, j, P, v, B, SCD, Sets, pair, pointer, current, currentPair, newSet, colour; + local listResult, i, round, c_min, c_max, set, Q, q, C, CD, + j, P, v, Out, In, Sets, pair, current, currentPair, newSet, colour; + + # Or just remove loops? + if not DigraphNrLoops(D) = 0 then + ErrorNoReturn("the digraph cannot contain loops"); + fi; c_min := 1; c_max := 1; @@ -196,7 +202,6 @@ function(D) # Initial colouring # vertices -> colour - # TODO: see if can change to single non-for loop line C := rec(); for v in DigraphVertices(D) do C.(v) := 1; @@ -215,16 +220,18 @@ function(D) # For each v in V (all vertices in D) # Get the neighbours of v that are in the colour class q - B := rec(); + Out := rec(); + In := rec(); for v in DigraphVertices(D) do - B.(v) := Intersection(Union(OutNeighbours(D)[v], - InNeighbours(D)[v]), P.(q)); + Out.(v) := Intersection(OutNeighbours(D)[v], P.(q)); + In.(v) := Intersection(InNeighbours(D)[v], P.(q)); od; - # CD: colour of v vs number of q coloured neighbours for all v in D + # CD: [colour of v, number of q coloured out-neighbours of v, + # number of q coloured in-neighbours of v, v] CD := []; for v in DigraphVertices(D) do - Add(CD, [C.(v), Length(B.(v)), v]); + Add(CD, [C.(v), Length(Out.(v)), Length(In.(v)), v]); od; Sort(CD); @@ -237,15 +244,15 @@ function(D) j := 0; for pair in CD do - current := [pair[1], pair[2]]; + current := [pair[1], pair[2], pair[3]]; # If first pair OR has the same values as the prev pair: if currentPair = [] or current = currentPair then - Add(newSet, pair[3]); + Add(newSet, pair[4]); else # Doesn't have the same values as the prev pair Add(Sets, newSet); - newSet := [pair[3]]; + newSet := [pair[4]]; # If they had the same colour but diff no. neighbours if pair[1] = currentPair[1] then @@ -270,9 +277,13 @@ function(D) colour := colour + 1; od; + Q := []; + # Pushing the last value to Q # TODO: look into largest set number for optimisation for i in [1 .. Length(Sets)] do + + # TODO: make this conditional on not being the largest set? Add(Q, c_max + i); od; @@ -292,6 +303,7 @@ function(D) colour := colour + 1; od; fi; + od; # Normalising results to a list starting at index 1 diff --git a/tst/standard/grahom.tst b/tst/standard/grahom.tst index f9127d313..89fd0153b 100644 --- a/tst/standard/grahom.tst +++ b/tst/standard/grahom.tst @@ -2913,16 +2913,16 @@ gap> DigraphColourRefinement(D); [ [ 1 .. 4 ] ] gap> D := Digraph([[2], [3], [2, 4], [2, 5], [4, 6], [5]]);; gap> DigraphColourRefinement(D); -[ [ 2, 6 ], [ 1 ], [ 3, 4, 5 ] ] +[ [ 1 ], [ 6 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ] ] gap> D := Digraph([[2], [3], [1]]);; gap> DigraphColourRefinement(D); [ [ 1 .. 3 ] ] gap> D := Digraph([[2, 4], [5], [2, 4], [5], [1, 3]]);; gap> DigraphColourRefinement(D); -[ [ 2, 4 ], [ 5 ], [ 1, 3 ] ] +[ [ 2, 4 ], [ 1, 3 ], [ 5 ] ] gap> D := Digraph([[4], [1, 3], [4], [5], [1, 3]]);; gap> DigraphColourRefinement(D); -[ [ 1, 3 ], [ 4 ], [ 2, 5 ] ] +[ [ 4 ], [ 1, 3 ], [ 2 ], [ 5 ] ] # gap> DIGRAPHS_StopTest(); From 4935b0a55458129571fda63b40b1cebc3bf79ee2 Mon Sep 17 00:00:00 2001 From: Rheya Monerasinghe Date: Wed, 11 Mar 2026 15:09:38 +0000 Subject: [PATCH 4/4] Adjusting output of DigraphColourRefinement and moving code to oper.tst --- doc/grahom.xml | 32 ---------- doc/oper.xml | 33 ++++++++++ gap/grahom.gd | 2 - gap/grahom.gi | 132 ---------------------------------------- gap/oper.gd | 2 + gap/oper.gi | 132 ++++++++++++++++++++++++++++++++++++++++ tst/standard/grahom.tst | 26 -------- tst/standard/oper.tst | 26 ++++++++ 8 files changed, 193 insertions(+), 192 deletions(-) diff --git a/doc/grahom.xml b/doc/grahom.xml index d0a06bbbc..2e3d1b213 100644 --- a/doc/grahom.xml +++ b/doc/grahom.xml @@ -543,38 +543,6 @@ Transformation( [ 1, 2, 1, 2, 1, 2, 1, 2, 1, 2 ] ) <#/GAPDoc> -<#GAPDoc Label="DigraphColourRefinement"> - - - A list of lists of integers. - - Colour Refinement is a method of colouring a digraph such that for a colour, every - node with that colouring has an identical configuration of coloured neighbours. That is, - all nodes of colour q have the same number of neighbours of colour x, and colour y, etc. - DigraphColourRefinement considers the out neighbours and in neighbours of a node separately. -

- This involves recolouring the digraph each iteration until it is 'refined'. It returns the colouring as a - 2D list. For two digraphs with different colourings, we can be sure that they are not isomorphic. However, - identical colourings for two digraphs does not necessarily mean they are isomorphic. -

- See also - . -

- - D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; -gap> DigraphColourRefinement(D); -[ [ 2, 4 ], [ 1, 5 ], [ 7, 8 ], [ 3, 10 ], [ 9 ], [ 6 ] ] -gap> DigraphColourRefinement(Digraph([[], [1], [1], [1]])); -[ [ 1 ], [ 2, 3, 4 ] ] -]]> - - -<#/GAPDoc> - <#GAPDoc Label="DigraphWelshPowellOrder"> diff --git a/doc/oper.xml b/doc/oper.xml index 0930e8f3c..e12d82493 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -2619,3 +2619,36 @@ true]]> gap> DIGRAPHS_FREE_CLIQUES_DATA(); ]]> <#/GAPDoc> + +<#GAPDoc Label="DigraphColourRefinement"> + + + A list of lists of integers. + + Colour Refinement is a method of colouring a digraph such that for a colour, every + node with that colouring has an identical configuration of coloured neighbours. That is, + all nodes of colour q have the same number of neighbours of colour x, and colour y, etc. + DigraphColourRefinement considers the out neighbours and in neighbours of a node separately. +

+ This involves recolouring the digraph each iteration until it is 'refined'. It returns the colouring as a + list where the value at the ith position is the colour of node i. For two digraphs with different colourings, + we can be sure that they are not isomorphic. However, identical colourings for two digraphs does not necessarily + mean they are isomorphic. +

+ See also + . +

+ + D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; +gap> DigraphColourRefinement(D); +[ 2, 1, 4, 1, 2, 6, 3, 3, 5, 4 ] +gap> DigraphColourRefinement(Digraph([[], [1], [1], [1]])); +[ 1, 2, 2, 2 ] +]]> + + +<#/GAPDoc> diff --git a/gap/grahom.gd b/gap/grahom.gd index cd14fa25f..b18ecce70 100644 --- a/gap/grahom.gd +++ b/gap/grahom.gd @@ -41,8 +41,6 @@ DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsFunction]); DeclareOperation("DigraphGreedyColouring", [IsDigraph, IsHomogeneousList]); DeclareOperation("DigraphGreedyColouringNC", [IsDigraph, IsHomogeneousList]); -DeclareOperation("DigraphColourRefinement", [IsDigraph]); - DeclareAttribute("DigraphWelshPowellOrder", IsDigraph); DeclareAttribute("DigraphSmallestLastOrder", IsDigraph); # TODO: document diff --git a/gap/grahom.gi b/gap/grahom.gi index 7fd4799cb..5628a3650 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -183,138 +183,6 @@ InstallMethod(DigraphGreedyColouring, "for a digraph and a function", [IsDigraph, IsFunction], {D, func} -> DigraphGreedyColouringNC(D, func(D))); -InstallMethod(DigraphColourRefinement, "for a digraph", [IsDigraph], -function(D) - - local listResult, i, round, c_min, c_max, set, Q, q, C, CD, - j, P, v, Out, In, Sets, pair, current, currentPair, newSet, colour; - - # Or just remove loops? - if not DigraphNrLoops(D) = 0 then - ErrorNoReturn("the digraph cannot contain loops"); - fi; - - c_min := 1; - c_max := 1; - - # Queue of colours - Q := [1]; - - # Initial colouring - # vertices -> colour - C := rec(); - for v in DigraphVertices(D) do - C.(v) := 1; - od; - - # Colour classes - # All vertices initialised to 1 - # colour -> vertices labelled as such - P := rec(1 := DigraphVertices(D)); - - while not IsEmpty(Q) do - - # Pop colour off Q - q := Q[1]; - Remove(Q, 1); - - # For each v in V (all vertices in D) - # Get the neighbours of v that are in the colour class q - Out := rec(); - In := rec(); - for v in DigraphVertices(D) do - Out.(v) := Intersection(OutNeighbours(D)[v], P.(q)); - In.(v) := Intersection(InNeighbours(D)[v], P.(q)); - od; - - # CD: [colour of v, number of q coloured out-neighbours of v, - # number of q coloured in-neighbours of v, v] - CD := []; - for v in DigraphVertices(D) do - Add(CD, [C.(v), Length(Out.(v)), Length(In.(v)), v]); - od; - - Sort(CD); - - # Put into sets - Sets := []; - currentPair := []; - newSet := []; - - j := 0; - - for pair in CD do - current := [pair[1], pair[2], pair[3]]; - - # If first pair OR has the same values as the prev pair: - if currentPair = [] or current = currentPair then - Add(newSet, pair[4]); - else - # Doesn't have the same values as the prev pair - Add(Sets, newSet); - newSet := [pair[4]]; - - # If they had the same colour but diff no. neighbours - if pair[1] = currentPair[1] then - - # Push a new number to Q - j := j + 1; - fi; - fi; - currentPair := current; - od; - Add(Sets, newSet); - - # If there is reason for recolouring - if j > 0 then - - # Clearing P - # TODO: Can P be a list from the start? - # Would simplify this a lot vv - colour := c_min; - while colour <= c_max do - P.(colour) := []; - colour := colour + 1; - od; - - Q := []; - - # Pushing the last value to Q - # TODO: look into largest set number for optimisation - for i in [1 .. Length(Sets)] do - - # TODO: make this conditional on not being the largest set? - Add(Q, c_max + i); - od; - - # Updating colours for the next round - c_min := c_max + 1; - c_max := c_max + Length(Sets); - - # Updating C and P - colour := c_min; - - for set in Sets do - P.(colour) := set; - - for v in set do - C.(v) := colour; - od; - colour := colour + 1; - od; - fi; - - od; - - # Normalising results to a list starting at index 1 - listResult := []; - for i in [c_min .. c_max] do - Add(listResult, P.(i)); - od; - return listResult; - -end); - InstallMethod(DigraphWelshPowellOrder, "for a digraph", [IsDigraph], function(D) local order, deg; diff --git a/gap/oper.gd b/gap/oper.gd index f6a37e0f8..4766b3496 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -156,6 +156,8 @@ DeclareOperation("Dominators", [IsDigraph, IsPosInt]); DeclareOperation("DominatorTree", [IsDigraph, IsPosInt]); DeclareOperation("DigraphCycleBasis", [IsDigraph]); +DeclareOperation("DigraphColourRefinement", [IsDigraph]); + # 10. Operations for vertices . . . DeclareOperation("PartialOrderDigraphJoinOfVertices", [IsDigraph, IsPosInt, IsPosInt]); diff --git a/gap/oper.gi b/gap/oper.gi index 3876db50e..9be9917ef 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -2732,3 +2732,135 @@ function(D, n) od; return kings; end); + +InstallMethod(DigraphColourRefinement, "for a digraph", [IsDigraph], +function(D) + + local listResult, i, round, c_min, c_max, set, Q, q, C, CD, + j, P, v, Out, In, Sets, pair, current, currentPair, newSet, colour; + + # Or just remove loops? + if not DigraphNrLoops(D) = 0 then + ErrorNoReturn("the digraph cannot contain loops"); + fi; + + c_min := 1; + c_max := 1; + + # Queue of colours + Q := [1]; + + # Initial colouring + # vertices -> colour + C := []; + for v in DigraphVertices(D) do + C[v] := 1; + od; + + # Colour classes + # All vertices initialised to 1 + # colour -> vertices labelled as such + P := rec(1 := DigraphVertices(D)); + + while not IsEmpty(Q) do + + # Pop colour off Q + q := Q[1]; + Remove(Q, 1); + + # For each v in V (all vertices in D) + # Get the neighbours of v that are in the colour class q + Out := rec(); + In := rec(); + for v in DigraphVertices(D) do + Out.(v) := Intersection(OutNeighbours(D)[v], P.(q)); + In.(v) := Intersection(InNeighbours(D)[v], P.(q)); + od; + + # CD: [colour of v, number of q coloured out-neighbours of v, + # number of q coloured in-neighbours of v, v] + CD := []; + for v in DigraphVertices(D) do + Add(CD, [C[v], Length(Out.(v)), Length(In.(v)), v]); + od; + + Sort(CD); + + # Put into sets + Sets := []; + currentPair := []; + newSet := []; + + j := 0; + + for pair in CD do + current := [pair[1], pair[2], pair[3]]; + + # If first pair OR has the same values as the prev pair: + if currentPair = [] or current = currentPair then + Add(newSet, pair[4]); + else + # Doesn't have the same values as the prev pair + Add(Sets, newSet); + newSet := [pair[4]]; + + # If they had the same colour but diff no. neighbours + if pair[1] = currentPair[1] then + + # Push a new number to Q + j := j + 1; + fi; + fi; + currentPair := current; + od; + Add(Sets, newSet); + + # If there is reason for recolouring + if j > 0 then + + # Clearing P + # TODO: Can P be a list from the start? + # Would simplify this a lot vv + colour := c_min; + while colour <= c_max do + P.(colour) := []; + colour := colour + 1; + od; + + Q := []; + + # Pushing the last value to Q + # TODO: look into largest set number for optimisation + for i in [1 .. Length(Sets)] do + + # TODO: make this conditional on not being the largest set? + Add(Q, c_max + i); + od; + + # Updating colours for the next round + c_min := c_max + 1; + c_max := c_max + Length(Sets); + + # Updating C and P + colour := c_min; + + for set in Sets do + P.(colour) := set; + + for v in set do + C[v] := colour; + od; + colour := colour + 1; + od; + fi; + + od; + + # Normalising C to 1 + for i in [1 .. Length(C)] do + C[i] := C[i] - (c_min - 1); + od; + + return C; + +end); diff --git a/tst/standard/grahom.tst b/tst/standard/grahom.tst index 89fd0153b..470c89e17 100644 --- a/tst/standard/grahom.tst +++ b/tst/standard/grahom.tst @@ -2898,32 +2898,6 @@ gap> HomomorphismDigraphsFinder(H, > Group(())); [ Transformation( [ 8, 1, 5, 7, 3, 4, 6, 8 ] ) ] -# DigraphColourRefinement -gap> D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; -gap> DigraphColourRefinement(D); -[ [ 2, 4 ], [ 1, 5 ], [ 7, 8 ], [ 3, 10 ], [ 9 ], [ 6 ] ] -gap> D := Digraph([[], [1], [1], [1]]);; -gap> DigraphColourRefinement(D); -[ [ 1 ], [ 2, 3, 4 ] ] -gap> D := Digraph([[1], [1], [1], [1]]);; -gap> DigraphColourRefinement(D); -Error, the digraph cannot contain loops -gap> D := Digraph([[], [], [], []]);; -gap> DigraphColourRefinement(D); -[ [ 1 .. 4 ] ] -gap> D := Digraph([[2], [3], [2, 4], [2, 5], [4, 6], [5]]);; -gap> DigraphColourRefinement(D); -[ [ 1 ], [ 6 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ] ] -gap> D := Digraph([[2], [3], [1]]);; -gap> DigraphColourRefinement(D); -[ [ 1 .. 3 ] ] -gap> D := Digraph([[2, 4], [5], [2, 4], [5], [1, 3]]);; -gap> DigraphColourRefinement(D); -[ [ 2, 4 ], [ 1, 3 ], [ 5 ] ] -gap> D := Digraph([[4], [1, 3], [4], [5], [1, 3]]);; -gap> DigraphColourRefinement(D); -[ [ 4 ], [ 1, 3 ], [ 2 ], [ 5 ] ] - # gap> DIGRAPHS_StopTest(); gap> STOP_TEST("Digraphs package: standard/grahom.tst", 0); diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index 1c813fe21..45163c26d 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -3324,6 +3324,32 @@ gap> DigraphEdges(D); gap> DigraphVertexLabels(D); [ 1, 2, 3, 6, [ 4, 5 ] ] +# DigraphColourRefinement +gap> D := Digraph([[3], [], [1, 9], [], [10], [7, 8, 9], [6, 8], [6, 7], [3, 6, 10], [5, 9]]);; +gap> DigraphColourRefinement(D); +[ 2, 1, 4, 1, 2, 6, 3, 3, 5, 4 ] +gap> D := Digraph([[], [1], [1], [1]]);; +gap> DigraphColourRefinement(D); +[ 1, 2, 2, 2 ] +gap> D := Digraph([[1], [1], [1], [1]]);; +gap> DigraphColourRefinement(D); +Error, the digraph cannot contain loops +gap> D := Digraph([[], [], [], []]);; +gap> DigraphColourRefinement(D); +[ 1, 1, 1, 1 ] +gap> D := Digraph([[2], [3], [2, 4], [2, 5], [4, 6], [5]]);; +gap> DigraphColourRefinement(D); +[ 1, 3, 4, 5, 6, 2 ] +gap> D := Digraph([[2], [3], [1]]);; +gap> DigraphColourRefinement(D); +[ 1, 1, 1 ] +gap> D := Digraph([[2, 4], [5], [2, 4], [5], [1, 3]]);; +gap> DigraphColourRefinement(D); +[ 2, 1, 2, 1, 3 ] +gap> D := Digraph([[4], [1, 3], [4], [5], [1, 3]]);; +gap> DigraphColourRefinement(D); +[ 2, 3, 2, 1, 4 ] + # gap> DIGRAPHS_StopTest(); gap> STOP_TEST("Digraphs package: standard/oper.tst", 0);