Skip to content

Implementing Colour Refinement#905

Open
RheyaM wants to merge 12 commits intodigraphs:mainfrom
RheyaM:ColourRefinement
Open

Implementing Colour Refinement#905
RheyaM wants to merge 12 commits intodigraphs:mainfrom
RheyaM:ColourRefinement

Conversation

@RheyaM
Copy link
Contributor

@RheyaM RheyaM commented Mar 11, 2026

Implementation of DigraphColourRefinement. Takes a digraph and returns a colouring (A list where value at ith position is the colour of the ith node), such that all nodes with the same colour have the same configuration of coloured neighbours. That is, if two nodes have the same colour, they will have the same number of neighbours of colour x, and colour y, etc. DigraphColourRefinement considers out and in neighbours separately.

If two digraphs produce two different colouring under Colour Refinement, we can know that they are not isomorphic.

Now includes optimisation step

doc/oper.xml Outdated
Label="for a digraph"/>
<Returns>A list of lists of integers.</Returns>
<Description>
Colour Refinement is a method of colouring a digraph such that for a colour, every
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inappropriate capitalisation.

doc/oper.xml Outdated
<Description>
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 <A>q</A> have the same number of neighbours of colour <A>x</A>, and colour y</A>, etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
all nodes of colour <A>q</A> have the same number of neighbours of colour <A>x</A>, and colour y</A>, etc.
all nodes of colour <A>q</A> have the same number of neighbours of colour <A>x</A>, and colour <A>y</A>, etc.

but also this should probably say: "all nodes with the same colour have equal numbers of nodes of every colour"

doc/oper.xml Outdated
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 <A>q</A> have the same number of neighbours of colour <A>x</A>, and colour y</A>, etc.
<C>DigraphColourRefinement</C> considers the out neighbours and in neighbours of a node separately.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be expanded to say exactly how they are considered separately.

doc/oper.xml Outdated
all nodes of colour <A>q</A> have the same number of neighbours of colour <A>x</A>, and colour y</A>, etc.
<C>DigraphColourRefinement</C> considers the out neighbours and in neighbours of a node separately.
<P/>
This involves recolouring the digraph each iteration until it is 'refined'. It returns the colouring as a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is This? What iterations are you referring to? What does 'refined' mean in this context? This is too imprecise.

doc/oper.xml Outdated
<P/>
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I believe this, the colouring as returned by this function depends on the order the vertices appear in the digraph, but isomorphism does not.

gap/oper.gi Outdated
j, P, v, Out, In, Sets, pair, current, currentPair, newSet, colour;

# Or just remove loops?
if not DigraphNrLoops(D) = 0 then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not DigraphNrLoops(D) = 0 then
if DigraphHasLoops(D) then

See also
<Ref Oper="DigraphColouring"
Label="for a digraph and a number of colours"/>.
<P/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation should say something about the complexity of the algorithm and its implementation too.

gap/oper.gi Outdated
Comment on lines +2755 to +2758
C := [];
for v in DigraphVertices(D) do
C[v] := 1;
od;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
C := [];
for v in DigraphVertices(D) do
C[v] := 1;
od;
C := List(DigraphNrVertices(D), x -> 1);

@RheyaM RheyaM marked this pull request as ready for review March 25, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants