Skip to content

Commit

Permalink
Resolve issue #704
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Nov 11, 2024
1 parent f6166a8 commit b0fe223
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 63 deletions.
2 changes: 1 addition & 1 deletion doc/grahom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ gap> MonomorphismsDigraphsRepresentatives(gr1, CompleteDigraph(3));
<Example><![CDATA[
gap> SubdigraphsMonomorphisms(CompleteBipartiteDigraph(2, 2),
> CompleteDigraph(4));
[ Transformation( [ 1, 3, 2 ] ), Transformation( [ 2, 3, 1 ] ),
[ Transformation( [ 2, 3, 1 ] ), Transformation( [ 1, 3, 2 ] ),
Transformation( [ 3, 4, 2, 1 ] ) ]
gap> SubdigraphsMonomorphismsRepresentatives(
> CompleteBipartiteDigraph(2, 2), CompleteDigraph(4));
Expand Down
7 changes: 4 additions & 3 deletions gap/cliques.gi
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ function(arg...)
orbits := HashMap();
for c in cliques do
if not c in orbits then
DIGRAPHS_AddOrbitToHashMap(G, c, orbits);
DIGRAPHS_AddOrbitToHashMap(G, c, OnSets, orbits);
fi;
od;
out := Keys(orbits);
Expand Down Expand Up @@ -709,7 +709,8 @@ function(digraph, hook, user_param, limit, include, exclude, max, size, reps)

new_found := 0;
if not clique in found_orbits then
orbit := DIGRAPHS_AddOrbitToHashMap(group, clique, found_orbits);
orbit :=
DIGRAPHS_AddOrbitToHashMap(group, clique, OnSets, found_orbits);
n := Length(orbit);

if invariant_include and invariant_exclude then
Expand Down Expand Up @@ -895,7 +896,7 @@ function(D, hook, param, lim, inc, exc, max, size, reps, inc_var, exc_var)
num := num + 1;
return;
elif not c in found_orbits then
orb := DIGRAPHS_AddOrbitToHashMap(grp, c, found_orbits);
orb := DIGRAPHS_AddOrbitToHashMap(grp, c, OnSets, found_orbits);
n := Length(orb);

if invariant then # we're not just looking for orbit reps, but inc and
Expand Down
88 changes: 36 additions & 52 deletions gap/grahom.gi
Original file line number Diff line number Diff line change
Expand Up @@ -333,75 +333,59 @@ end);
InstallMethod(SubdigraphsMonomorphismsRepresentatives,
"for a digraph and a digraph", [IsDigraph, IsDigraph],
function(H, G)
local GV, HN, map, reps, result, set, rep;

GV := DigraphVertices(G);
HN := DigraphNrVertices(H);
local AG, map, result, K, rep;

AG := AutomorphismGroup(G);
map := HashMap();
reps := [];
result := [];

for set in Combinations(GV, HN) do
if not set in map then
Add(reps, set);
DIGRAPHS_AddOrbitToHashMap(AutomorphismGroup(G), set, map);
for rep in MonomorphismsDigraphsRepresentatives(H, G) do
K := OnSetsTuples(DigraphEdges(H), rep);
if not K in map then
Add(result, rep);
DIGRAPHS_AddOrbitToHashMap(AG, K, OnSetsTuples, map);
fi;
od;

result := [];
for rep in reps do
map :=
HomomorphismDigraphsFinder(H, # domain
G, # range
fail, # hook
[], # user_param
1, # max_results
HN, # hint (i.e. rank)
true, # injective
rep, # image
[], # partial_map
fail, # colors1
fail, # colors2
DigraphWelshPowellOrder(H),
Group(()));
if Length(map) <> 0 then
Add(result, map[1]);
fi;
od;
return result;
end);

InstallMethod(SubdigraphsMonomorphisms, "for a digraph and a digraph",
[IsDigraph, IsDigraph],
function(H, G)
local ApplyHomomorphismNC, reps, AG, result, sub, o, x, rep, i;

ApplyHomomorphismNC := function(D1, D2, t)
local old, new, v, im;
old := OutNeighbours(D1);
new := List([1 .. DigraphNrVertices(D2)], x -> []);
for v in DigraphVertices(D1) do
im := v ^ t;
if not IsBound(new[im]) then
new[im] := [];
fi;
Append(new[im], OnTuples(old[v], t));
local AddOrbitToHashMap, AG, map, K, rep;

AddOrbitToHashMap := function(G, set, act, hashmap, rep)
local gens, o, im, pt, g;

gens := GeneratorsOfGroup(G);
o := [set];
Assert(1, not set in hashmap);
hashmap[set] := rep;
for pt in o do
for g in gens do
im := act(pt, g);
if not im in hashmap then
hashmap[im] := hashmap[pt] * g;
# Assert(0, OnSetsTuples(set, hashmap[im]) = im);
Add(o, im);
fi;
od;
od;
return DigraphNC(new);
return o;
end;

reps := SubdigraphsMonomorphismsRepresentatives(H, G);
AG := AutomorphismGroup(G);
result := [];
for rep in reps do
sub := ApplyHomomorphismNC(H, G, rep);
o := Enumerate(Orb(AG, sub, OnDigraphs, rec(schreier := true)));
for i in [1 .. Length(o)] do
x := EvaluateWord(GeneratorsOfGroup(AG), TraceSchreierTreeForward(o, i));
Add(result, rep * x);
od;
map := HashMap();

for rep in MonomorphismsDigraphsRepresentatives(H, G) do
K := OnSetsTuples(DigraphEdges(H), rep);
if not K in map then
AddOrbitToHashMap(AG, K, OnSetsTuples, map, rep);
fi;
od;
return result;

return Values(map);
end);

################################################################################
Expand Down
4 changes: 2 additions & 2 deletions gap/orbits.gi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function(G, domain)
end);

InstallGlobalFunction(DIGRAPHS_AddOrbitToHashMap,
function(G, set, hashmap)
function(G, set, act, hashmap)
local gens, o, im, pt, g;

gens := GeneratorsOfGroup(G);
Expand All @@ -78,7 +78,7 @@ function(G, set, hashmap)
hashmap[set] := true;
for pt in o do
for g in gens do
im := OnSets(pt, g);
im := act(pt, g);
if not im in hashmap then
hashmap[im] := true;
Add(o, im);
Expand Down
12 changes: 7 additions & 5 deletions tst/standard/grahom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ true
# SubdigraphsMonomorphisms
gap> SubdigraphsMonomorphisms(CompleteBipartiteDigraph(2, 2),
> CompleteDigraph(4));
[ Transformation( [ 1, 3, 2 ] ), Transformation( [ 2, 3, 1 ] ),
[ Transformation( [ 2, 3, 1 ] ), Transformation( [ 1, 3, 2 ] ),
Transformation( [ 3, 4, 2, 1 ] ) ]
gap> D := DigraphFromGraph6String("D^{");
<immutable symmetric digraph with 5 vertices, 18 edges>
Expand All @@ -2776,10 +2776,12 @@ gap> D := DigraphFromGraph6String("K^vMMF@oM?{@");
<immutable symmetric digraph with 12 vertices, 60 edges>
gap> Length(SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([2, 5]), D));
252
gap> D := DigraphFromGraph6String("O^vMMF@oM?w@o@o?w?N?@");
<immutable symmetric digraph with 16 vertices, 84 edges>
gap> Length(SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([2, 7]), D));
3432

# The next test is a bit slow
# gap> D := DigraphFromGraph6String("O^vMMF@oM?w@o@o?w?N?@");
# <immutable symmetric digraph with 16 vertices, 84 edges>
# gap> Length(SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([2, 7]), D));
# 3432

#
gap> H := DigraphFromGraph6String("F~CWw");
Expand Down
7 changes: 7 additions & 0 deletions tst/testinstall.tst
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ gap> C := DigraphContractEdge(D, 2, 1);
gap> DigraphEdges(C);
[ [ 2, 1 ] ]

# Issue #704 SubdigraphsMonomorphisms bug
gap> d := Digraph([[2, 3, 4, 5], [1, 3, 4], [1, 2, 4, 5], [1, 2, 3, 5],
> [1, 3, 4]]);;
gap> SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([2, 3]), d);
[ Transformation( [ 1, 3, 2 ] ), Transformation( [ 2, 5, 1, 3, 4 ] ),
Transformation( [ 1, 4, 2, 3 ] ), Transformation( [ 3, 4, 2, 1 ] ) ]

# DIGRAPHS_UnbindVariables
gap> Unbind(C);
gap> Unbind(D);
Expand Down

0 comments on commit b0fe223

Please sign in to comment.