Skip to content

Commit

Permalink
Merge branch 'master' into RemoveEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfwilson committed Mar 11, 2021
2 parents e1521c6 + b257faa commit 7cd4002
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ branches:
except:
- /rc-v\d+\.\d+\.\d+/

skip_branch_with_pr: true

environment:
TEST_SUITE: test
PACKAGES: "latest"
Expand Down
35 changes: 27 additions & 8 deletions .github/workflows/gap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,35 @@ jobs:
pkgs-to-clone: datastructures

steps:
- uses: actions/checkout@v2
- uses: gap-actions/setup-gap-for-packages@v1
name: "Install GAP and clone/compile necessary packages"
- name: "Check out the repository"
uses: actions/checkout@v2
- name: "Install TeX Live"
if: ${{ matrix.gap-branch == 'master' }}
run: |
sudo apt-get update
sudo apt-get install texlive-latex-base texlive-latex-recommended texlive-latex-extra
sudo apt-get install texlive-extra-utils texlive-fonts-recommended texlive-fonts-extra
- name: "Install GAP and clone/compile necessary packages"
uses: gap-actions/setup-gap-for-packages@v1
with:
GAP_PKGS_TO_CLONE: "${{ matrix.pkgs-to-clone }}"
GAP_PKGS_TO_BUILD: "io orb profiling grape NautyTracesInterface datastructures"
GAPBRANCH: ${{ matrix.gap-branch }}
- name: "Install digraphs-lib"
run: DIGRAPHS_LIB="digraphs-lib-0.6"
&& curl --retry 5 -L -O "https://digraphs.github.io/Digraphs/${DIGRAPHS_LIB}.tar.gz"
&& tar xf "${DIGRAPHS_LIB}.tar.gz"
- uses: gap-actions/run-test-for-packages@v1
name: "Run tst/testall.g"
run: |
DIGRAPHS_LIB="digraphs-lib-0.6"
curl --retry 5 -L -O "https://digraphs.github.io/Digraphs/${DIGRAPHS_LIB}.tar.gz"
tar xf "${DIGRAPHS_LIB}.tar.gz"
- name: "Run tst/testall.g"
uses: gap-actions/run-test-for-packages@v1
- name: "Upload compiled manuals"
if: ${{ matrix.gap-branch == 'master' }}
uses: actions/upload-artifact@v2
with:
name: manual
path: |
doc/manual.pdf
doc/*.html
doc/*.css
doc/*.js
80 changes: 80 additions & 0 deletions doc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,3 +309,83 @@ gap> GeneralisedPetersenGraph(IsMutableDigraph, 9, 4);
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="StarDigraph">
<ManSection>
<Oper Name="StarDigraph" Arg="[filt, ]k"/>
<Returns>A digraph.</Returns>
<Description>
If <A>k</A> is a positive integer, then this operation returns the
<E>star digraph</E> with <A>k</A> vertices, which is the
undirected tree in which vertex <C>1</C> is adjacent to all other
vertices. If <A>k</A> is at least <C>2</C>, then this is the complete
bipartite digraph with bicomponents
<C>[1]</C> and <C>[2 .. <A>k</A>]</C>. <P/>

See <Ref Prop="IsUndirectedTree"/>, <Ref Prop="IsCompleteBipartiteDigraph"/>,
and <Ref Attr="DigraphBicomponents"/>. <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/>
<Example><![CDATA[
gap> StarDigraph(IsMutable, 10);
<mutable digraph with 10 vertices, 18 edges>
gap> StarDigraph(5);
<immutable complete bipartite digraph with bicomponent sizes 1 and 4>
gap> IsSymmetricDigraph(StarDigraph(3));
true
gap> IsUndirectedTree(StarDigraph(3));
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="KnightsGraph">
<ManSection>
<Oper Name="KnightsGraph" Arg="[filt, ]m, n"/>
<Returns>A digraph.</Returns>
<Description>
If <A>m</A> and <A>n</A> are both positive integers, then this operation
returns the <E>Knight's Graph</E> for a <A>m</A> by <A>n</A> board. <P/>

From
<URL>https://en.wikipedia.org/wiki/Knight%27s_graph</URL>:
<P/>

<Q>In graph theory, a knight's graph, or a knight's tour graph, is a
graph that represents all legal moves of the knight chess piece on a
chessboard. Each vertex of this graph represents a square of the
chessboard, and each edge connects two squares that are a knight's move
apart from each other. More specifically, an <A>m</A> by <A>n</A> knight's
graph is a knight's graph of an <A>m</A> by <A>n</A> chessboard.</Q>
<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/>

<Example><![CDATA[
gap> D := KnightsGraph(8, 8);
<immutable connected symmetric digraph with 64 vertices, 336 edges>
gap> IsConnectedDigraph(D);
true
gap> D := KnightsGraph(3, 3);
<immutable symmetric digraph with 9 vertices, 16 edges>
gap> IsConnectedDigraph(D);
false
gap> KnightsGraph(IsMutable, 3, 9);
<mutable digraph with 27 vertices, 88 edges>
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
2 changes: 2 additions & 0 deletions doc/z-chap2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
<#Include Label="JohnsonDigraph">
<#Include Label="PetersenGraph">
<#Include Label="GeneralisedPetersenGraph">
<#Include Label="KnightsGraph">
<#Include Label="StarDigraph">
</Section>

</Chapter>
8 changes: 8 additions & 0 deletions gap/examples.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ DeclareOperation("PetersenGraph", [IsFunction]);
DeclareConstructor("GeneralisedPetersenGraphCons", [IsDigraph, IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsInt, IsInt]);
DeclareOperation("GeneralisedPetersenGraph", [IsFunction, IsInt, IsInt]);

DeclareConstructor("StarDigraphCons", [IsDigraph, IsPosInt]);
DeclareOperation("StarDigraph", [IsPosInt]);
DeclareOperation("StarDigraph", [IsFunction, IsPosInt]);

DeclareConstructor("KnightsGraphCons", [IsDigraph, IsPosInt, IsPosInt]);
DeclareOperation("KnightsGraph", [IsPosInt, IsPosInt]);
DeclareOperation("KnightsGraph", [IsFunction, IsPosInt, IsPosInt]);
76 changes: 76 additions & 0 deletions gap/examples.gi
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,79 @@ GeneralisedPetersenGraphCons);

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

InstallMethod(StarDigraphCons, "for IsMutableDigraph and a positive integer",
[IsMutableDigraph, IsPosInt],
function(filt, k)
local j, graph;
graph := EmptyDigraph(IsMutable, k);
for j in [2 .. k] do
DigraphAddEdges(graph, [[1, j], [j, 1]]);
od;
return graph;
end);

InstallMethod(StarDigraph, "for a function and a positive integer",
[IsFunction, IsPosInt],
StarDigraphCons);

InstallMethod(StarDigraph, "for integer", [IsPosInt],
{k} -> StarDigraphCons(IsImmutableDigraph, k));

InstallMethod(StarDigraphCons,
"for IsImmutableDigraph and a positive integer",
[IsImmutableDigraph, IsPosInt],
function(filt, k)
local D;
D := MakeImmutable(StarDigraph(IsMutableDigraph, k));
SetIsMultiDigraph(D, false);
SetIsEmptyDigraph(D, k = 1);
SetIsCompleteBipartiteDigraph(D, k > 1);
return D;
end);

InstallMethod(KnightsGraphCons,
"for IsMutableDigraph and two positive integers",
[IsMutableDigraph, IsPosInt, IsPosInt],
function(filt, m, n)
local D, moveOffSets, coordinates, target, i, j, iPos;
D := EmptyDigraph(IsMutableDigraph, m * n);
moveOffSets := [[2, 1], [-2, 1], [2, -1], [-2, -1],
[1, 2], [-1, 2], [1, -2], [-1, -2]];
coordinates := [];
for i in [1 .. n] do
for j in [1 .. m] do
Add(coordinates, [i, j]);
od;
od;
iPos := 0;
for i in coordinates do
iPos := iPos + 1;
for j in moveOffSets do
target := [i[1] + j[1], i[2] + j[2]];
if target[1] in [1 .. n] and target[2] in [1 .. m] then
DigraphAddEdge(D, [iPos, (target[1] - 1) * m + target[2]]);
fi;
od;
od;
return D;
end);

InstallMethod(KnightsGraphCons,
"for IsImmutableDigraph and two positive integers",
[IsImmutableDigraph, IsPosInt, IsPosInt],
function(filt, m, n)
local D;
D := MakeImmutable(KnightsGraphCons(IsMutableDigraph, m, n));
SetIsMultiDigraph(D, false);
SetIsSymmetricDigraph(D, true);
SetIsConnectedDigraph(D, m > 2 and n > 2 and not (m = 3 and n = 3));
return D;
end);

InstallMethod(KnightsGraph, "for a function and two positive integers",
[IsFunction, IsPosInt, IsPosInt],
KnightsGraphCons);

InstallMethod(KnightsGraph, "for two positive integers", [IsPosInt, IsPosInt],
{m, n} -> KnightsGraphCons(IsImmutableDigraph, m, n));
26 changes: 26 additions & 0 deletions tst/standard/examples.tst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,32 @@ Error, the arguments <n> and <k> must be non-negative integers,
gap> JohnsonDigraph(IsMutableDigraph, 4, 2);
<mutable digraph with 6 vertices, 24 edges>

# StarDigraph
gap> StarDigraph(IsMutable, 10);
<mutable digraph with 10 vertices, 18 edges>
gap> StarDigraph(IsImmutableDigraph, 10);
<immutable complete bipartite digraph with bicomponent sizes 1 and 9>
gap> StarDigraph(3);
<immutable complete bipartite digraph with bicomponent sizes 1 and 2>
gap> StarDigraph(1);
<immutable empty digraph with 1 vertex>
gap> IsSymmetricDigraph(StarDigraph(3));
true
gap> IsMultiDigraph(StarDigraph(3));
false

# Knight's Graph
gap> D := KnightsGraph(8, 8);
<immutable connected symmetric digraph with 64 vertices, 336 edges>
gap> IsConnectedDigraph(D);
true
gap> D := KnightsGraph(3, 3);
<immutable symmetric digraph with 9 vertices, 16 edges>
gap> IsConnectedDigraph(D);
false
gap> KnightsGraph(IsMutable, 3, 9);
<mutable digraph with 27 vertices, 88 edges>

#
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: standard/examples.tst", 0);

0 comments on commit 7cd4002

Please sign in to comment.