Skip to content

Commit cfa2b53

Browse files
authored
Merge pull request #37 from wilfwilson/fix-issue-23
Fix Issue #23: DigraphMaximalCliques
2 parents 861222c + a02c06a commit cfa2b53

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

gap/cliques.gi

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,9 @@ function(gr, hook, user_param, limit, include, exclude, max, size, reps)
723723
end);
724724

725725
InstallGlobalFunction(DIGRAPHS_BronKerbosch,
726-
function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
727-
local vtx, grp, invariant_inc, invariant_exc, invariant, adj, exc_inv, start,
728-
possible, found_orbits, add, bk, num, x;
726+
function(gr, hook, param, lim, inc, exc, max, size, reps, inc_var, exc_var)
727+
local vtx, invariant_inc, invariant_exc, invariant, adj, exc_inv, start,
728+
possible, isolated, grp, found_orbits, add, bk, num, x, gen;
729729

730730
# Arguments must be:
731731
# gr - a digraph
@@ -759,7 +759,6 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
759759

760760
gr := MaximalSymmetricSubdigraphWithoutLoops(gr);
761761
vtx := DigraphVertices(gr);
762-
grp := AutomorphismGroup(gr);
763762

764763
invariant_inc := Length(inc_var) = 0;
765764
invariant_exc := Length(exc_var) = 0;
@@ -793,6 +792,22 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
793792
IntersectBlist(possible, adj[x]);
794793
od;
795794

795+
isolated := DigraphSources(gr); # sources = sinks = isolated vertices
796+
if reps and not IsEmpty(isolated) then
797+
# Optimisation for when there are isolated vertices
798+
grp := Group(());
799+
for gen in GeneratorsOfGroup(AutomorphismGroup(gr)) do
800+
# Discard generators which act on the isolated points
801+
if not SmallestMovedPoint(gen) in isolated then
802+
grp := ClosureGroup(grp, gen);
803+
fi;
804+
od;
805+
SubtractBlist(possible, BlistList(vtx, isolated));
806+
possible[isolated[1]] := true;
807+
else
808+
grp := AutomorphismGroup(gr);
809+
fi;
810+
796811
found_orbits := [];
797812

798813
# Function to find the valid cliques of an orbit given an orbit rep
@@ -801,7 +816,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
801816

802817
c := ListBlist(vtx, c);
803818
if reps then # we are only looking for orbit reps, so add the rep
804-
hook(user_param, c);
819+
hook(param, c);
805820
num := num + 1;
806821
return;
807822
elif not ForAny(found_orbits, x -> c in x) then
@@ -814,7 +829,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
814829
# are invariant so there is nothing extra to check
815830
n := Minimum(lim - num, n);
816831
for c in orb{[1 .. n]} do
817-
hook(user_param, c);
832+
hook(param, c);
818833
od;
819834
num := num + n;
820835
return;
@@ -827,7 +842,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
827842
i := i + 1;
828843
c := BlistList(vtx, orb[i]);
829844
if SizeBlist(IntersectionBlist(exc_var, c)) = 0 then
830-
hook(user_param, orb[i]);
845+
hook(param, orb[i]);
831846
num := num + 1;
832847
fi;
833848
od;
@@ -838,7 +853,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
838853
i := i + 1;
839854
c := BlistList(vtx, orb[i]);
840855
if IsSubsetBlist(c, inc_var) then
841-
hook(user_param, orb[i]);
856+
hook(param, orb[i]);
842857
num := num + 1;
843858
fi;
844859
od;
@@ -851,7 +866,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
851866
c := BlistList(vtx, orb[i]);
852867
if SizeBlist(IntersectionBlist(exc_var, c)) = 0
853868
and IsSubsetBlist(c, inc_var) then
854-
hook(user_param, orb[i]);
869+
hook(param, orb[i]);
855870
num := num + 1;
856871
fi;
857872
od;
@@ -973,5 +988,5 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var)
973988
num := 0;
974989

975990
bk(start, possible, BlistList(vtx, []), grp, Length(inc));
976-
return user_param;
991+
return param;
977992
end);

tst/standard/cliques.tst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,24 @@ gap> c := DigraphMaximalCliques(gr);;
503503
gap> Length(c);
504504
12815
505505

506+
#T# Issue #23: Digraphs with isolated vertices
507+
gap> gr := DigraphFromSparse6String(":~?@c__EC?_F");
508+
<digraph with 100 vertices, 6 edges>
509+
gap> DigraphMaximalCliquesReps(gr);
510+
[ [ 1 ], [ 2, 3, 5 ] ]
511+
gap> DigraphMaximalCliques(gr);
512+
[ [ 1 ], [ 4 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ], [ 10 ], [ 11 ], [ 12 ], [ 13 ],
513+
[ 14 ], [ 15 ], [ 16 ], [ 17 ], [ 18 ], [ 19 ], [ 20 ], [ 21 ], [ 22 ],
514+
[ 23 ], [ 24 ], [ 25 ], [ 26 ], [ 27 ], [ 28 ], [ 29 ], [ 30 ], [ 31 ],
515+
[ 32 ], [ 33 ], [ 34 ], [ 35 ], [ 36 ], [ 37 ], [ 38 ], [ 39 ], [ 40 ],
516+
[ 41 ], [ 42 ], [ 43 ], [ 44 ], [ 45 ], [ 46 ], [ 47 ], [ 48 ], [ 49 ],
517+
[ 50 ], [ 51 ], [ 52 ], [ 53 ], [ 54 ], [ 55 ], [ 56 ], [ 57 ], [ 58 ],
518+
[ 59 ], [ 60 ], [ 61 ], [ 62 ], [ 63 ], [ 64 ], [ 65 ], [ 66 ], [ 67 ],
519+
[ 68 ], [ 69 ], [ 70 ], [ 71 ], [ 72 ], [ 73 ], [ 74 ], [ 75 ], [ 76 ],
520+
[ 77 ], [ 78 ], [ 79 ], [ 80 ], [ 81 ], [ 82 ], [ 83 ], [ 84 ], [ 85 ],
521+
[ 86 ], [ 87 ], [ 88 ], [ 89 ], [ 90 ], [ 91 ], [ 92 ], [ 93 ], [ 94 ],
522+
[ 95 ], [ 96 ], [ 97 ], [ 98 ], [ 99 ], [ 100 ], [ 2, 3, 5 ] ]
523+
506524
#T# DIGRAPHS_UnbindVariables
507525
gap> Unbind(f);
508526
gap> Unbind(c);

0 commit comments

Comments
 (0)