diff --git a/gap/cliques.gi b/gap/cliques.gi index 79dd45834..4275e6433 100644 --- a/gap/cliques.gi +++ b/gap/cliques.gi @@ -723,9 +723,9 @@ function(gr, hook, user_param, limit, include, exclude, max, size, reps) end); InstallGlobalFunction(DIGRAPHS_BronKerbosch, -function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) - local vtx, grp, invariant_inc, invariant_exc, invariant, adj, exc_inv, start, - possible, found_orbits, add, bk, num, x; +function(gr, hook, param, lim, inc, exc, max, size, reps, inc_var, exc_var) + local vtx, invariant_inc, invariant_exc, invariant, adj, exc_inv, start, + possible, isolated, grp, found_orbits, add, bk, num, x, gen; # Arguments must be: # gr - a digraph @@ -759,7 +759,6 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) gr := MaximalSymmetricSubdigraphWithoutLoops(gr); vtx := DigraphVertices(gr); - grp := AutomorphismGroup(gr); invariant_inc := Length(inc_var) = 0; 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) IntersectBlist(possible, adj[x]); od; + isolated := DigraphSources(gr); # sources = sinks = isolated vertices + if reps and not IsEmpty(isolated) then + # Optimisation for when there are isolated vertices + grp := Group(()); + for gen in GeneratorsOfGroup(AutomorphismGroup(gr)) do + # Discard generators which act on the isolated points + if not SmallestMovedPoint(gen) in isolated then + grp := ClosureGroup(grp, gen); + fi; + od; + SubtractBlist(possible, BlistList(vtx, isolated)); + possible[isolated[1]] := true; + else + grp := AutomorphismGroup(gr); + fi; + found_orbits := []; # 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) c := ListBlist(vtx, c); if reps then # we are only looking for orbit reps, so add the rep - hook(user_param, c); + hook(param, c); num := num + 1; return; 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) # are invariant so there is nothing extra to check n := Minimum(lim - num, n); for c in orb{[1 .. n]} do - hook(user_param, c); + hook(param, c); od; num := num + n; return; @@ -827,7 +842,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) i := i + 1; c := BlistList(vtx, orb[i]); if SizeBlist(IntersectionBlist(exc_var, c)) = 0 then - hook(user_param, orb[i]); + hook(param, orb[i]); num := num + 1; fi; od; @@ -838,7 +853,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) i := i + 1; c := BlistList(vtx, orb[i]); if IsSubsetBlist(c, inc_var) then - hook(user_param, orb[i]); + hook(param, orb[i]); num := num + 1; fi; od; @@ -851,7 +866,7 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) c := BlistList(vtx, orb[i]); if SizeBlist(IntersectionBlist(exc_var, c)) = 0 and IsSubsetBlist(c, inc_var) then - hook(user_param, orb[i]); + hook(param, orb[i]); num := num + 1; fi; od; @@ -973,5 +988,5 @@ function(gr, hook, user_param, lim, inc, exc, max, size, reps, inc_var, exc_var) num := 0; bk(start, possible, BlistList(vtx, []), grp, Length(inc)); - return user_param; + return param; end); diff --git a/tst/standard/cliques.tst b/tst/standard/cliques.tst index cdb5af3ae..feaf268b0 100644 --- a/tst/standard/cliques.tst +++ b/tst/standard/cliques.tst @@ -503,6 +503,24 @@ gap> c := DigraphMaximalCliques(gr);; gap> Length(c); 12815 +#T# Issue #23: Digraphs with isolated vertices +gap> gr := DigraphFromSparse6String(":~?@c__EC?_F"); + +gap> DigraphMaximalCliquesReps(gr); +[ [ 1 ], [ 2, 3, 5 ] ] +gap> DigraphMaximalCliques(gr); +[ [ 1 ], [ 4 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ], [ 10 ], [ 11 ], [ 12 ], [ 13 ], + [ 14 ], [ 15 ], [ 16 ], [ 17 ], [ 18 ], [ 19 ], [ 20 ], [ 21 ], [ 22 ], + [ 23 ], [ 24 ], [ 25 ], [ 26 ], [ 27 ], [ 28 ], [ 29 ], [ 30 ], [ 31 ], + [ 32 ], [ 33 ], [ 34 ], [ 35 ], [ 36 ], [ 37 ], [ 38 ], [ 39 ], [ 40 ], + [ 41 ], [ 42 ], [ 43 ], [ 44 ], [ 45 ], [ 46 ], [ 47 ], [ 48 ], [ 49 ], + [ 50 ], [ 51 ], [ 52 ], [ 53 ], [ 54 ], [ 55 ], [ 56 ], [ 57 ], [ 58 ], + [ 59 ], [ 60 ], [ 61 ], [ 62 ], [ 63 ], [ 64 ], [ 65 ], [ 66 ], [ 67 ], + [ 68 ], [ 69 ], [ 70 ], [ 71 ], [ 72 ], [ 73 ], [ 74 ], [ 75 ], [ 76 ], + [ 77 ], [ 78 ], [ 79 ], [ 80 ], [ 81 ], [ 82 ], [ 83 ], [ 84 ], [ 85 ], + [ 86 ], [ 87 ], [ 88 ], [ 89 ], [ 90 ], [ 91 ], [ 92 ], [ 93 ], [ 94 ], + [ 95 ], [ 96 ], [ 97 ], [ 98 ], [ 99 ], [ 100 ], [ 2, 3, 5 ] ] + #T# DIGRAPHS_UnbindVariables gap> Unbind(f); gap> Unbind(c);