diff --git a/gap/examples.gd b/gap/examples.gd index 4a08fdf79..20bc3ec07 100644 --- a/gap/examples.gd +++ b/gap/examples.gd @@ -48,3 +48,5 @@ DeclareOperation("PetersenGraph", [IsFunction]); DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]); DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]); DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]); + +DeclareGlobalFunction("DIGRAPHS_PancakeGraph"); diff --git a/gap/examples.gi b/gap/examples.gi index 402ef6456..c10e6283d 100644 --- a/gap/examples.gi +++ b/gap/examples.gi @@ -370,3 +370,49 @@ GeneralisedPetersenGraphCons); InstallMethod(GeneralisedPetersenGraph, "for integer, integer", [IsInt, IsInt], {n, k} -> GeneralisedPetersenGraphCons(IsImmutableDigraph, n, k)); + +InstallGlobalFunction(DIGRAPHS_PancakeGraph, +function(n) + local PancakeGraphInner; + + PancakeGraphInner := function(list) + local D, C, labels, DD, new_labels, extra, w, l, i, v; + if Length(list) = 2 then + D := Digraph(IsMutableDigraph, [[2], [1]]); + SetDigraphVertexLabels(D, [list, Reversed(list)]); + return D; + fi; + + C := Combinations(list, Length(list) - 1); + D := PancakeGraphInner(C[1]); + extra := Difference(list, C[1]); + labels := DigraphVertexLabels(D); + for l in labels do + Append(l, extra); + od; + SetDigraphVertexLabels(D, labels); + for i in [2 .. Length(C)] do + DD := PancakeGraphInner(C[i]); + new_labels := DigraphVertexLabels(DD); + extra := Difference(list, C[i]); + for l in new_labels do + Append(l, extra); + od; + labels := DigraphVertexLabels(D); + Append(labels, new_labels); + DigraphDisjointUnion(D, DD); + SetDigraphVertexLabels(D, labels); + od; + + labels := DigraphVertexLabels(D); + for v in DigraphVertices(D) do + w := Position(labels, Reversed(labels[v])); + if v <> w then + DigraphAddEdge(D, v, w); + fi; + od; + + return D; + end; + return PancakeGraphInner([1 .. n]); +end); diff --git a/tst/standard/examples.tst b/tst/standard/examples.tst index d06db41e4..e719ef890 100644 --- a/tst/standard/examples.tst +++ b/tst/standard/examples.tst @@ -226,6 +226,18 @@ Error, the arguments and must be non-negative integers, gap> JohnsonDigraph(IsMutableDigraph, 4, 2); +# PancakeGraph +gap> D := DIGRAPHS_PancakeGraph(3); + +gap> ChromaticNumber(D); +2 +gap> IsVertexTransitive(D); +true +gap> DigraphUndirectedGirth(D); +6 +gap> IsHamiltonianDigraph(D); +true + # gap> DIGRAPHS_StopTest(); gap> STOP_TEST("Digraphs package: standard/examples.tst", 0);