From 195f319bf6e1f43d384c1fe74a51bcce44880d2d Mon Sep 17 00:00:00 2001 From: Murray Whyte Date: Fri, 14 Jun 2019 12:06:05 +0100 Subject: [PATCH 1/4] Add GeneralisedPetersenGraph function --- doc/exmpl.xml | 27 ++++++++++++++++++++ doc/z-chap2.xml | 1 + gap/exmpl.gd | 4 +++ gap/exmpl.gi | 57 ++++++++++++++++++++++++++++++++++++++++++ tst/standard/exmpl.tst | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) diff --git a/doc/exmpl.xml b/doc/exmpl.xml index 3ccb32cd4..8cdd1eba2 100644 --- a/doc/exmpl.xml +++ b/doc/exmpl.xml @@ -26,6 +26,33 @@ gap> ChromaticNumber(PetersenGraph()); <#/GAPDoc> +<#GAPDoc Label="GeneralisedPetersenGraph"> + + + A digaph. + + 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 +]]> + + +<#/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..1e1db626f 100644 --- a/gap/exmpl.gi +++ b/gap/exmpl.gi @@ -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 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 .. 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]); + 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..e67e24399 100644 --- a/tst/standard/exmpl.tst +++ b/tst/standard/exmpl.tst @@ -21,6 +21,50 @@ 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> mat8_3 := [[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, 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); + +gap> D := GeneralisedPetersenGraph(8, 3); + +gap> IsIsomorphicDigraph(D, G8_3); +true + # CompleteDigraph gap> gr := CompleteDigraph(5); From 01ee47a2091651e537339e2520a43a29634748da Mon Sep 17 00:00:00 2001 From: Murray Whyte Date: Fri, 14 Jun 2019 12:29:45 +0100 Subject: [PATCH 2/4] Modify construction to make output work more nicely with DigraphVertexLabels --- gap/exmpl.gi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gap/exmpl.gi b/gap/exmpl.gi index 1e1db626f..1aa8de5da 100644 --- a/gap/exmpl.gi +++ b/gap/exmpl.gi @@ -370,9 +370,8 @@ function(filt, n, k) ErrorNoReturn("the argument must be less than / 2,"); fi; D := Digraph(filt, []); - for i in [1 .. n] do + for i in [1 .. 2 * n] do DigraphAddVertex(D, i); - DigraphAddVertex(D, n + 1 + i); od; for i in [1 .. n] do if i <> n then From 64040fc25628acc01c008e036b3b09e794d03995 Mon Sep 17 00:00:00 2001 From: Murray Whyte Date: Fri, 14 Jun 2019 12:42:49 +0100 Subject: [PATCH 3/4] Implement changes --- doc/exmpl.xml | 10 +++++++--- gap/exmpl.gi | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/doc/exmpl.xml b/doc/exmpl.xml index 8cdd1eba2..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()); @@ -29,7 +31,7 @@ gap> ChromaticNumber(PetersenGraph()); <#GAPDoc Label="GeneralisedPetersenGraph"> - A digaph. + 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).

@@ -37,7 +39,7 @@ gap> ChromaticNumber(PetersenGraph()); For more information, see https://en.wikipedia.org/wiki/Generalized_Petersen_graph

- See also . + See also . GeneralisedPetersenGraph(7, 2); @@ -48,6 +50,8 @@ gap> D := GeneralisedPetersenGraph(5, 2); gap> IsIsomorphicDigraph(D, PetersenGraph()); true +gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4); + ]]> diff --git a/gap/exmpl.gi b/gap/exmpl.gi index 1aa8de5da..98f10a7f2 100644 --- a/gap/exmpl.gi +++ b/gap/exmpl.gi @@ -383,7 +383,7 @@ function(filt, n, k) 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]); + DigraphAddEdge(D, [n + i, ((n + i + k) mod n) + n]); fi; od; DigraphSymmetricClosure(D); From c6ca07a7016aeaef9985bd84b3bb671d564fec2c Mon Sep 17 00:00:00 2001 From: Murray Whyte Date: Fri, 14 Jun 2019 13:30:56 +0100 Subject: [PATCH 4/4] Shorten tests --- tst/standard/exmpl.tst | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/tst/standard/exmpl.tst b/tst/standard/exmpl.tst index e67e24399..d86ad7845 100644 --- a/tst/standard/exmpl.tst +++ b/tst/standard/exmpl.tst @@ -42,23 +42,7 @@ gap> D := GeneralisedPetersenGraph(5, 2); gap> IsIsomorphicDigraph(D, PetersenGraph()); true -gap> mat8_3 := [[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, 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); +gap> G8_3 := DigraphFromGraph6String("OCQa`Q?OH?a@A@@?_OGB@"); gap> D := GeneralisedPetersenGraph(8, 3);