Skip to content
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 TadpoleDigraph #423

Merged
merged 17 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions doc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,36 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="TadpoleDigraph">
<ManSection>
<Oper Name="TadpoleDigraph" Arg="[filt, ]m, n"/>
<Returns>A digraph.</Returns>
<Description>
If <A>m</A> and <A>n</A> are non-negative integers (where m > 2), then this operation
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
returns a Tadpole digraph.<P/>

If the optional first argument <A>filt</A> is present, then this should
specify the category or representation the digraph being created will
belong to. For example, if <A>filt</A> is <Ref Filt="IsMutableDigraph"/>,
then the digraph being created will be mutable, if <A>filt</A> is <Ref
Filt="IsImmutableDigraph"/>, then the digraph will be immutable.
If the optional first argument <A>filt</A> is not present, then <Ref
Filt="IsImmutableDigraph"/> is used by default.<P/>

The <E>Tadpole digraph</E> consists of a cycle graph on m vertices and a path graph on
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
n vertices. These two graphs are connected by a bridge.<P/>

<Example><![CDATA[
gap> TadpoleDigraph(10, 15);
<immutable symmetric multidigraph with 25 vertices, 50 edges>
gap> TadpoleDigraph(IsMutableDigraph, 5, 6);
<mutable digraph with 11 vertices, 22 edges>
gap> IsSymmetricDigraph(TadpoleDigraph(3, 5));
true
gap> IsMultiDigraph(TadpoleDigraph(3, 5));
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
4 changes: 4 additions & 0 deletions gap/examples.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ DeclareOperation("PetersenGraph", [IsFunction]);
DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);

DeclareConstructor("TadpoleDigraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("TadpoleDigraph", [IsInt, IsInt]);
DeclareOperation("TadpoleDigraph", [IsFunction, IsInt, IsInt]);
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
55 changes: 55 additions & 0 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,58 @@ GeneralisedPetersenGraphCons);

InstallMethod(GeneralisedPetersenGraph, "for integer, integer", [IsInt, IsInt],
{n, k} -> GeneralisedPetersenGraphCons(IsImmutableDigraph, n, k));

InstallMethod(GeneralisedPetersenGraphCons,
"for IsImmutableDigraph, integer, int",
[IsImmutableDigraph, IsInt, IsInt],
function(filt, n, k)
local D;
D := MakeImmutable(GeneralisedPetersenGraphCons(IsMutableDigraph, n, k));
SetIsMultiDigraph(D, false);
SetIsSymmetricDigraph(D, true);
return D;
end);

InstallMethod(TadpoleDigraphCons, "for IsMutableDigraph and two integers",
[IsMutableDigraph, IsInt, IsInt],
function(filt, m, n)
local i, j, tail, graph;
if (m < 3) then
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
ErrorNoReturn("m needs to greater than 2");
elif (n < 0) then
ErrorNoReturn("n needs to be positive (or 0)");
fi;
graph := CycleDigraph(IsMutable, m);
DigraphAddEdge(graph, [1, m]);
for j in [2 .. m] do
DigraphAddEdge(graph, [j, j - 1]);
od;
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
if (n = 0) then
return graph;
fi;
tail := ChainDigraph(IsMutable, n);
for i in [2 .. n] do
DigraphAddEdge(tail, [i, i - 1]);
od;
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
DigraphDisjointUnion(graph, tail);
DigraphAddEdges(graph, [[m, n + m], [n + m, m]]);
return graph;
end);

InstallMethod(TadpoleDigraph, "for a function, integer, integer",
[IsFunction, IsInt, IsInt],
TadpoleDigraphCons);

InstallMethod(TadpoleDigraph, "for integer, integer", [IsInt, IsInt],
{m, n} -> TadpoleDigraphCons(IsImmutableDigraph, m, n));

InstallMethod(TadpoleDigraphCons,
"for IsImmutableDigraph, integer, integer",
[IsImmutableDigraph, IsInt, IsInt],
function(filt, m, n)
local D;
D := MakeImmutable(TadpoleDigraph(IsMutableDigraph, m, n));
SetIsMultiDigraph(D, true);
SetIsSymmetricDigraph(D, true);
return D;
end);
14 changes: 13 additions & 1 deletion 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>

#
# TadPoleDigraph
gap> TadpoleDigraph(2, 2);
Error, m needs to greater than 2
gap> TadpoleDigraph(3, -1);
Error, n needs to be positive (or 0)
wilfwilson marked this conversation as resolved.
Show resolved Hide resolved
gap> TadpoleDigraph(10, 15);
<immutable symmetric multidigraph with 25 vertices, 50 edges>
gap> TadpoleDigraph(IsMutableDigraph, 5, 6);
<mutable digraph with 11 vertices, 22 edges>
gap> IsSymmetricDigraph(TadpoleDigraph(3, 5));
true
gap> IsMultiDigraph(TadpoleDigraph(3, 5));
true
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: standard/examples.tst", 0);