Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GeneralisedPetersenGraph function #204

Merged
merged 4 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions doc/exmpl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ gap> ChromaticNumber(PetersenGraph());
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="GeneralisedPetersenGraph">
<ManSection>
<Attr Name="GeneralisedPetersenGraph" Arg="n, k"/>
<Returns>A digaph.</Returns>
Copy link
Member

Choose a reason for hiding this comment

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

digaph -> digraph

<Description>
If <A>n</A> is a positive integer and <A>k</A> is a non-negative integer less than <A>n / 2</A>, then this operation returns the <E>Generalised Petersen Graph</E> <M>GPG(n, k)</M>. <P/>

From Wikipedia: The generalized Petersen graphs are a family of cubic graphs formed by connecting the vertices of a regular polygon to the corresponding vertices of a star polygon. They include the Petersen graph and generalize one of the ways of constructing the Petersen graph. The generalized Petersen graph family was introduced in 1950 by H. S. M. Coxeter and was given its name in 1969 by Mark Watkins.<P/>

For more information, see <URL>https://en.wikipedia.org/wiki/Generalized_Petersen_graph</URL><P/>

See also <Ref Func="DigraphsTestInstall"/>.
Copy link
Member

Choose a reason for hiding this comment

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

Why do we see also DigraphsTestInstall??


<Example><![CDATA[
gap> GeneralisedPetersenGraph(7, 2);
<immutable digraph with 14 vertices, 42 edges>
gap> GeneralisedPetersenGraph(40, 1);
<immutable digraph with 80 vertices, 240 edges>
gap> D := GeneralisedPetersenGraph(5, 2);
<immutable digraph with 10 vertices, 30 edges>
gap> IsIsomorphicDigraph(D, PetersenGraph());
true
]]></Example>
Copy link
Member

Choose a reason for hiding this comment

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

Why not add an example which returns a mutable digraph? Other manual examples don't do this only because they haven't yet been updated.

</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="JohnsonDigraph">
<ManSection>
<Oper Name="JohnsonDigraph" Arg="n, k"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<#Include Label="EmptyDigraph">
<#Include Label="JohnsonDigraph">
<#Include Label="PetersenGraph">
<#Include Label="GeneralisedPetersenGraph">
</Section>

</Chapter>
4 changes: 4 additions & 0 deletions gap/exmpl.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ DeclareOperation("JohnsonDigraph", [IsFunction, IsInt, IsInt]);
DeclareConstructor("PetersenGraphCons", [IsDigraph]);
DeclareOperation("PetersenGraph", []);
DeclareOperation("PetersenGraph", [IsFunction]);

DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);
57 changes: 57 additions & 0 deletions gap/exmpl.gi
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,60 @@ InstallMethod(PetersenGraph, [],
function()
return PetersenGraphCons(IsImmutableDigraph);
end);

InstallMethod(GeneralisedPetersenGraphCons,
"for IsMutableDigraph, integer, integer",
[IsMutableDigraph, IsInt, IsInt],
function(filt, n, k)
local D, i;
if n < 1 then
ErrorNoReturn("the argument <n> must be a positive integer,");
elif k < 0 then
ErrorNoReturn("the argument <k> must be a non-negative integer,");
elif k > n / 2 then
ErrorNoReturn("the argument <k> must be less than <n> / 2,");
fi;
D := Digraph(filt, []);
for i in [1 .. n] do
DigraphAddVertex(D, i);
DigraphAddVertex(D, n + 1 + i);
od;
for i in [1 .. n] do
if i <> n then
DigraphAddEdge(D, [i, i + 1]);
else
DigraphAddEdge(D, [n, 1]);
fi;
DigraphAddEdge(D, [i, n + i]);
if n + i + k <= 2 * n then
DigraphAddEdge(D, [n + i, n + i + k]);
else
DigraphAddEdge(D, [n + i, (n + i + k) mod n + n]);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe some brackets around ((n + i + k) mod n) + n?

fi;
od;
DigraphSymmetricClosure(D);
return D;
end);

InstallMethod(GeneralisedPetersenGraphCons,
"for IsImmutableDigraph, integer, int",
[IsImmutableDigraph, IsInt, IsInt],
function(filt, n, k)
local D;
D := MakeImmutableDigraph(GeneralisedPetersenGraphCons(
IsMutableDigraph, n, k));
SetIsMultiDigraph(D, false);
SetIsSymmetricDigraph(D, true);
return D;
end);

InstallMethod(GeneralisedPetersenGraph, "for a function, integer, integer",
[IsFunction, IsInt, IsInt],
function(func, n, k)
return GeneralisedPetersenGraphCons(func, n, k);
end);

InstallMethod(GeneralisedPetersenGraph, "for integer, integer", [IsInt, IsInt],
function(n, k)
return GeneralisedPetersenGraphCons(IsImmutableDigraph, n, k);
end);
44 changes: 44 additions & 0 deletions tst/standard/exmpl.tst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,50 @@ gap> DigraphGirth(PetersenGraph());
gap> PetersenGraph(IsMutableDigraph);
<mutable digraph with 10 vertices, 30 edges>

# GeneralisedPetersenGraph
gap> D := GeneralisedPetersenGraph(8, 3);
<immutable digraph with 16 vertices, 48 edges>
gap> IsBipartiteDigraph(D);
true
gap> D := GeneralisedPetersenGraph(15, 7);
<immutable digraph with 30 vertices, 90 edges>
gap> IsBipartiteDigraph(D);
false
gap> D := GeneralisedPetersenGraph(10, 2);
<immutable digraph with 20 vertices, 60 edges>
gap> IsVertexTransitive(D);
true
gap> D := GeneralisedPetersenGraph(11, 2);
<immutable digraph with 22 vertices, 66 edges>
gap> IsVertexTransitive(D);
false
gap> D := GeneralisedPetersenGraph(5, 2);
<immutable digraph with 10 vertices, 30 edges>
gap> IsIsomorphicDigraph(D, PetersenGraph());
true
gap> mat8_3 := [[0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could make this all much shorter by just doing:

gap> G8_3 := DigraphFromGraph6String("OCQa`Q?OH?a@A@@?_OGB@");

> [0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0],
> [0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0],
> [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
> [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
> [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
> [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
> [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
> [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
> [0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0],
> [0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0],
> [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
> [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0],
> [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
> [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1],
> [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0]];;
gap> G8_3 := DigraphByAdjacencyMatrix(mat8_3);
<immutable digraph with 16 vertices, 48 edges>
gap> D := GeneralisedPetersenGraph(8, 3);
<immutable digraph with 16 vertices, 48 edges>
gap> IsIsomorphicDigraph(D, G8_3);
true

# CompleteDigraph
gap> gr := CompleteDigraph(5);
<immutable digraph with 5 vertices, 20 edges>
Expand Down