-
Notifications
You must be signed in to change notification settings - Fork 48
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,33 @@ gap> ChromaticNumber(PetersenGraph()); | |
</ManSection> | ||
<#/GAPDoc> | ||
|
||
<#GAPDoc Label="GeneralisedPetersenGraph"> | ||
<ManSection> | ||
<Attr Name="GeneralisedPetersenGraph" Arg="n, k"/> | ||
<Returns>A digaph.</Returns> | ||
<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"/>. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we see also |
||
|
||
<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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"/> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some brackets around |
||
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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could make this all much shorter by just doing:
|
||
> [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> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digaph
->digraph