Skip to content

Commit

Permalink
examples: add pancakes
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Feb 10, 2021
1 parent 6045e53 commit 4d98f96
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gap/examples.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ DeclareOperation("PetersenGraph", [IsFunction]);
DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);

DeclareGlobalFunction("DIGRAPHS_PancakeGraph");
46 changes: 46 additions & 0 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 12 additions & 0 deletions tst/standard/examples.tst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ Error, the arguments <n> and <k> must be non-negative integers,
gap> JohnsonDigraph(IsMutableDigraph, 4, 2);
<mutable digraph with 6 vertices, 24 edges>

# PancakeGraph
gap> D := DIGRAPHS_PancakeGraph(3);
<mutable digraph with 6 vertices, 12 edges>
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);

0 comments on commit 4d98f96

Please sign in to comment.