Skip to content

Commit 73426ba

Browse files
wilfwilsonjames-d-mitchell
authored andcommitted
Fix bug in CirculantGraph (Issue #764)
1 parent aadec2a commit 73426ba

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

doc/examples.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,19 +1044,29 @@ true]]></Example>
10441044
<A>par</A> is <C>[1,<A>n</A>]</C> then the graph is the <A>n</A>th Mobius
10451045
ladder graph.<P/>
10461046

1047-
A circulant graph is biconnected, cyclic, Hamiltonian, regular, and vertex
1048-
transitive.<P/>
1047+
A circulant graph is vertex transitive, but is not necessarily connected
1048+
(consider <C>CirculantGraph(4, [2])</C>, for example). However, a
1049+
<E>connected</E> circulant graph is also Hamiltonian and biconnected.<P/>
10491050

10501051
See <URL>https://mathworld.wolfram.com/CirculantGraph.html</URL> for further
10511052
details.<P/>
10521053

10531054
&STANDARD_FILT_TEXT;
10541055

10551056
<Example><![CDATA[
1056-
gap> D := CirculantGraph(6, [1, 2, 3]);
1057+
gap> D := CirculantGraph(6, [2]);
1058+
<immutable vertex-transitive symmetric digraph with 6 vertices, 12 edg\
1059+
es>
1060+
gap> DigraphNrConnectedComponents(D);
1061+
2
1062+
gap> D := CirculantGraph(6, [2, 3]);
10571063
<immutable Hamiltonian biconnected vertex-transitive symmetric digraph\
1058-
with 6 vertices, 30 edges>
1059-
gap> IsIsomorphicDigraph(D, CompleteDigraph(6));
1064+
with 6 vertices, 18 edges>
1065+
gap> AutomorphismGroup(D) = DihedralGroup(IsPermGroup, 12);
1066+
true
1067+
gap> HamiltonianPath(D);
1068+
[ 1, 3, 5, 2, 6, 4 ]
1069+
gap> IsCompleteDigraph(CirculantGraph(6, [1, 2, 3]));
10601070
true]]></Example>
10611071
</Description>
10621072
</ManSection>

gap/examples.gi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,7 @@ function(_, n, par)
11031103
ErrorNoReturn("arguments must be an integer <n> greater ",
11041104
"than 1 and a list of integers between 1 and n,");
11051105
fi;
1106-
D := Digraph(IsMutableDigraph, []);
1107-
DigraphAddVertices(D, n);
1106+
D := EmptyDigraph(IsMutableDigraph, n);
11081107
for i in [1 .. n] do
11091108
for j in par do
11101109
if (i - j) mod n = 0 then
@@ -1130,11 +1129,14 @@ function(_, n, par)
11301129
D := MakeImmutable(CirculantGraphCons(IsMutableDigraph, n, par));
11311130
SetIsMultiDigraph(D, false);
11321131
SetIsSymmetricDigraph(D, true);
1133-
SetIsUndirectedTree(D, false);
1134-
SetIsRegularDigraph(D, true);
11351132
SetIsVertexTransitive(D, true);
1136-
SetIsHamiltonianDigraph(D, true);
1137-
SetIsBiconnectedDigraph(D, true);
1133+
SetIsUndirectedTree(D, false);
1134+
SetIsUndirectedForest(D, IsEmpty(par) or
1135+
(IsEvenInt(n) and Unique(par) = [n / 2]));
1136+
if Gcd(Concatenation([n], par)) = 1 then
1137+
SetIsHamiltonianDigraph(D, true);
1138+
SetIsBiconnectedDigraph(D, true);
1139+
fi;
11381140
return D;
11391141
end);
11401142

tst/standard/examples.tst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,18 @@ gap> D := CirculantGraph(10, [1, 5]);
546546
vertices, 30 edges>
547547
gap> IsIsomorphicDigraph(D, MobiusLadderGraph(5));
548548
true
549+
gap> Set(Filtered(Combinations([1 .. 6]),
550+
> x -> IsUndirectedForest(DigraphCopy(CirculantGraph(6, x)))));
551+
[ [ ], [ 3 ] ]
552+
gap> Set(Filtered(Combinations([1 .. 6]),
553+
> x -> IsUndirectedForest(CirculantGraph(6, x))));
554+
[ [ ], [ 3 ] ]
555+
gap> D := CirculantGraph(6, [3]);
556+
<immutable undirected forest with 6 vertices>
557+
gap> IsUndirectedForest(D);
558+
true
559+
gap> IsUndirectedForest(DigraphCopy(D));
560+
true
549561

550562
# CycleGraph
551563
gap> IsIsomorphicDigraph(CycleGraph(5), DigraphSymmetricClosure(CycleDigraph(5)));

tst/testinstall.tst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,29 @@ gap> d := Digraph([[2, 3, 4, 5], [1, 3, 4], [1, 2, 4, 5], [1, 2, 3, 5],
472472
gap> Length(SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([2, 3]), d));
473473
4
474474

475+
# Issue #764 Disconnected CirculantGraphs are not Hamiltonian, etc
476+
gap> D := CirculantGraph(12, [2, 4]);
477+
<immutable vertex-transitive symmetric digraph with 12 vertices, 48 edges>
478+
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
479+
false
480+
gap> D := DigraphCopy(D);;
481+
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
482+
false
483+
gap> IsVertexTransitive(D);
484+
true
485+
gap> D := CirculantGraph(4, [2]);
486+
<immutable undirected forest with 4 vertices>
487+
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
488+
false
489+
gap> D := CirculantGraph(6, [2]);
490+
<immutable vertex-transitive symmetric digraph with 6 vertices, 12 edges>
491+
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
492+
false
493+
gap> D := DigraphCopy(CirculantGraph(9, [3]));
494+
<immutable digraph with 9 vertices, 18 edges>
495+
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
496+
false
497+
475498
# Issue #818 IsConnectedDigraph for a digraph without vertices
476499
gap> D := Digraph([]);;
477500
gap> IsConnectedDigraph(D);

0 commit comments

Comments
 (0)