diff --git a/doc/exmpl.xml b/doc/exmpl.xml index 3ccb32cd4..8ab4dbeb0 100644 --- a/doc/exmpl.xml +++ b/doc/exmpl.xml @@ -16,7 +16,9 @@ From Wikipedia: The Petersen graph is an undirected graph with 10 vertices and 15 edges. It is a small graph that serves as a useful example and counterexample for many problems in graph theory. The Petersen graph is named after Julius Petersen, who in 1898 constructed it to be the smallest bridgeless cubic graph with no three-edge-coloring.

- For more information, see https://en.wikipedia.org/wiki/Petersen_graph + For more information, see https://en.wikipedia.org/wiki/Petersen_graph

+ + See also . ChromaticNumber(PetersenGraph()); @@ -26,6 +28,35 @@ gap> ChromaticNumber(PetersenGraph()); <#/GAPDoc> +<#GAPDoc Label="GeneralisedPetersenGraph"> + + + A digraph. + + If n is a positive integer and k is a non-negative integer less than n / 2, then this operation returns the Generalised Petersen Graph GPG(n, k).

+ + 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.

+ + For more information, see https://en.wikipedia.org/wiki/Generalized_Petersen_graph

+ + See also . + + GeneralisedPetersenGraph(7, 2); + +gap> GeneralisedPetersenGraph(40, 1); + +gap> D := GeneralisedPetersenGraph(5, 2); + +gap> IsIsomorphicDigraph(D, PetersenGraph()); +true +gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4); + +]]> + + +<#/GAPDoc> + <#GAPDoc Label="JohnsonDigraph"> diff --git a/doc/z-chap2.xml b/doc/z-chap2.xml index aada4b3ee..bddba5250 100644 --- a/doc/z-chap2.xml +++ b/doc/z-chap2.xml @@ -77,6 +77,7 @@ <#Include Label="EmptyDigraph"> <#Include Label="JohnsonDigraph"> <#Include Label="PetersenGraph"> + <#Include Label="GeneralisedPetersenGraph"> diff --git a/gap/exmpl.gd b/gap/exmpl.gd index 0db489a19..3aa7277a8 100644 --- a/gap/exmpl.gd +++ b/gap/exmpl.gd @@ -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]); diff --git a/gap/exmpl.gi b/gap/exmpl.gi index ff98ab55d..98f10a7f2 100644 --- a/gap/exmpl.gi +++ b/gap/exmpl.gi @@ -356,3 +356,59 @@ 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 must be a positive integer,"); + elif k < 0 then + ErrorNoReturn("the argument must be a non-negative integer,"); + elif k > n / 2 then + ErrorNoReturn("the argument must be less than / 2,"); + fi; + D := Digraph(filt, []); + for i in [1 .. 2 * n] do + DigraphAddVertex(D, 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]); + 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); diff --git a/tst/standard/exmpl.tst b/tst/standard/exmpl.tst index 57794f9d8..d86ad7845 100644 --- a/tst/standard/exmpl.tst +++ b/tst/standard/exmpl.tst @@ -21,6 +21,34 @@ gap> DigraphGirth(PetersenGraph()); gap> PetersenGraph(IsMutableDigraph); +# GeneralisedPetersenGraph +gap> D := GeneralisedPetersenGraph(8, 3); + +gap> IsBipartiteDigraph(D); +true +gap> D := GeneralisedPetersenGraph(15, 7); + +gap> IsBipartiteDigraph(D); +false +gap> D := GeneralisedPetersenGraph(10, 2); + +gap> IsVertexTransitive(D); +true +gap> D := GeneralisedPetersenGraph(11, 2); + +gap> IsVertexTransitive(D); +false +gap> D := GeneralisedPetersenGraph(5, 2); + +gap> IsIsomorphicDigraph(D, PetersenGraph()); +true +gap> G8_3 := DigraphFromGraph6String("OCQa`Q?OH?a@A@@?_OGB@"); + +gap> D := GeneralisedPetersenGraph(8, 3); + +gap> IsIsomorphicDigraph(D, G8_3); +true + # CompleteDigraph gap> gr := CompleteDigraph(5);