Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 25 additions & 10 deletions gap/cliques.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
18 changes: 18 additions & 0 deletions tst/standard/cliques.tst
Original file line number Diff line number Diff line change
Expand Up @@ -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");
<digraph with 100 vertices, 6 edges>
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);
Expand Down