Skip to content

Commit

Permalink
oper: add IsDigraphColouring
Browse files Browse the repository at this point in the history
A method that verifies if a list or transformation is a colouring of a digraph.
  • Loading branch information
james-d-mitchell authored and wilfwilson committed Nov 23, 2018
1 parent 3cf0602 commit 3ed0124
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 0 deletions.
44 changes: 44 additions & 0 deletions doc/grahom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,47 @@ false]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IsDigraphColouring">
<ManSection>
<Oper Name="IsDigraphColouring" Arg="digraph, list"/>
<Oper Name="IsDigraphColouring" Arg="digraph, t"
Label="for a transformation"/>
<Returns> <K>true</K> or <K>false</K>. </Returns>
<Description>
The operation <C>IsDigraphColouring</C> verifies whether or not
the list <A>list</A> describes a proper colouring of the digraph
<A>digraph</A>.
<P/>

A list <A>list</A> describes a <E>proper colouring</E> of a digraph
<A>digraph</A> if <A>list</A> consists of positive integers, the length of
<A>list</A> equals the number of vertices in <A>digraph</A>, and for any
vertices <C>u, v</C> of <A>digraph</A> if <C>u</C> and <C>v</C> are adjacent,
then <C><A>list</A>[u] &gt;&lt; <A>list</A>[v]</C>.
<P/>

A transformation <A>t</A> describes a proper colouring of a digraph
<A>digraph</A>, if <C>ImageListOfTransformation(<A>t</A>,
DigraphNrVertices(<A>digraph</A>))</C> is a proper colouring of
<A>digraph</A>. <P/>

See also <Ref Oper="IsDigraphHomomorphism"/>.

<Example><![CDATA[
gap> D := JohnsonDigraph(5, 3);
<digraph with 10 vertices, 60 edges>
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 4, 5, 6, 7]);
true
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 2, 5, 6, 7]);
false
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 2, 5, 6, -1]);
false
gap> IsDigraphColouring(D, [1, 2, 3]);
false
gap> IsDigraphColouring(D, IdentityTransformation);
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
1 change: 1 addition & 0 deletions doc/z-chap6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are
<#Include Label="IsomorphismDigraphsColours">
<#Include Label="RepresentativeOutNeighbours">
<#Include Label="IsDigraphAutomorphism">
<#Include Label="IsDigraphColouring">
</Section>

<Section><Heading>Homomorphisms of digraphs</Heading>
Expand Down
3 changes: 3 additions & 0 deletions gap/grahom.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ DeclareOperation("IsDigraphMonomorphism",
[IsDigraph, IsDigraph, IsPerm]);
DeclareOperation("IsDigraphEmbedding",
[IsDigraph, IsDigraph, IsPerm]);

DeclareOperation("IsDigraphColouring", [IsDigraph, IsList]);
DeclareOperation("IsDigraphColouring", [IsDigraph, IsTransformation]);
28 changes: 28 additions & 0 deletions gap/grahom.gi
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,31 @@ function(src, ran, x)
od;
return true;
end);

InstallMethod(IsDigraphColouring, "for a digraph and a list",
[IsDigraph, IsHomogeneousList],
function(digraph, colours)
local n, out, v, w;
n := DigraphNrVertices(digraph);
if Length(colours) <> n or ForAny(colours, x -> not IsPosInt(x)) then
return false;
fi;
out := OutNeighbours(digraph);
for v in DigraphVertices(digraph) do
for w in out[v] do
if colours[w] = colours[v] then
return false;
fi;
od;
od;
return true;
end);

InstallMethod(IsDigraphColouring, "for a digraph and a transformation",
[IsDigraph, IsTransformation],
function(digraph, t)
local n;
n := DigraphNrVertices(digraph);
return IsDigraphColouring(digraph,
ImageListOfTransformation(t, n));
end);
14 changes: 14 additions & 0 deletions tst/standard/grahom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,20 @@ true
gap> IsDigraphEmbedding(src, ran, ());
false

# IsDigraphColouring
gap> D := JohnsonDigraph(5, 3);
<digraph with 10 vertices, 60 edges>
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 4, 5, 6, 7]);
true
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 2, 5, 6, 7]);
false
gap> IsDigraphColouring(D, [1, 2, 3, 3, 2, 1, 2, 5, 6, -1]);
false
gap> IsDigraphColouring(D, [1, 2, 3]);
false
gap> IsDigraphColouring(D, IdentityTransformation);
true

#T# DIGRAPHS_UnbindVariables
gap> Unbind(edges);
gap> Unbind(epis);
Expand Down

0 comments on commit 3ed0124

Please sign in to comment.