Skip to content

Commit

Permalink
Add SubdigraphsMonomorphisms
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Aug 30, 2024
1 parent 32db214 commit f24fb1b
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 124 deletions.
219 changes: 120 additions & 99 deletions doc/grahom.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion doc/z-chap6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are
&nauty; (via &NautyTracesInterface;) to calculate canonical labellings and
automorphism groups of digraphs; see <Cite Key="JK07"/> and <Cite
Key="MP14"/> for more details about &bliss; and &nauty;,
respectively.
respectively.

<#Include Label="DigraphsUseNauty">
<#Include Label="AutomorphismGroupDigraph">
Expand Down Expand Up @@ -65,6 +65,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are
<#Include Label="EmbeddingsDigraphs">
<#Include Label="IsDigraphHomomorphism">
<#Include Label="IsDigraphEmbedding">
<#Include Label="SubdigraphsMonomorphisms">
<#Include Label="DigraphsRespectsColouring">
<#Include Label="GeneratorsOfEndomorphismMonoid">
<#Include Label="DigraphColouring">
Expand Down
26 changes: 3 additions & 23 deletions gap/cliques.gi
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@
#############################################################################
##

BindGlobal("AddOrbitToHashMap",
function(G, set, hashmap)
local gens, o, im, pt, g;

gens := GeneratorsOfGroup(G);
o := [set];
Assert(1, not set in hashmap);
hashmap[set] := true;
for pt in o do
for g in gens do
im := OnSets(pt, g);
if not im in hashmap then
hashmap[im] := true;
Add(o, im);
fi;
od;
od;
return o;
end);

InstallMethod(CliqueNumber, "for a digraph", [IsDigraph],
D -> Maximum(List(DigraphMaximalCliquesReps(D), Length)));

Expand Down Expand Up @@ -570,7 +550,7 @@ function(arg)
orbits := HashMap();
for c in cliques do
if not c in orbits then
AddOrbitToHashMap(G, c, orbits);
DIGRAPHS_AddOrbitToHashMap(G, c, orbits);
fi;
od;
out := Keys(orbits);
Expand Down Expand Up @@ -729,7 +709,7 @@ function(digraph, hook, user_param, limit, include, exclude, max, size, reps)

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

if invariant_include and invariant_exclude then
Expand Down Expand Up @@ -915,7 +895,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 := AddOrbitToHashMap(grp, c, found_orbits);
orb := DIGRAPHS_AddOrbitToHashMap(grp, c, found_orbits);
n := Length(orb);

if invariant then # we're not just looking for orbit reps, but inc and
Expand Down
5 changes: 5 additions & 0 deletions gap/grahom.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ DeclareOperation("MonomorphismsDigraphs", [IsDigraph, IsDigraph]);
DeclareOperation("MonomorphismsDigraphsRepresentatives",
[IsDigraph, IsDigraph]);

DeclareOperation("SubdigraphsMonomorphismsRepresentatives",
[IsDigraph, IsDigraph]);
DeclareOperation("SubdigraphsMonomorphisms",
[IsDigraph, IsDigraph]);

DeclareOperation("DigraphEpimorphism", [IsDigraph, IsDigraph]);
DeclareOperation("EpimorphismsDigraphs", [IsDigraph, IsDigraph]);
DeclareOperation("EpimorphismsDigraphsRepresentatives", [IsDigraph, IsDigraph]);
Expand Down
73 changes: 73 additions & 0 deletions gap/grahom.gi
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,79 @@ function(D1, D2)
return Union(List(aut, x -> hom * x));
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);

map := HashMap();
reps := [];

for set in Combinations(GV, HN) do
if not set in map then
Add(reps, set);
DIGRAPHS_AddOrbitToHashMap(AutomorphismGroup(G), set, 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));
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));
od;
return DigraphNC(new);
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;
od;
return result;
end);

################################################################################
# SURJECTIVE HOMOMORPHISMS

Expand Down
1 change: 1 addition & 0 deletions gap/orbits.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DeclareGlobalFunction("DIGRAPHS_Orbits");
DeclareGlobalFunction("DIGRAPHS_TraceSchreierVector");
DeclareGlobalFunction("DIGRAPHS_EvaluateWord");
DeclareAttribute("DIGRAPHS_Stabilizers", IsDigraph, "mutable");
DeclareGlobalFunction("DIGRAPHS_AddOrbitToHashMap");

DeclareAttribute("DigraphGroup", IsDigraph);
DeclareAttribute("DigraphOrbits", IsDigraph);
Expand Down
20 changes: 20 additions & 0 deletions gap/orbits.gi
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ function(G, domain)
return rec(orbits := orbs, schreier := sch, lookup := lookup);
end);

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

gens := GeneratorsOfGroup(G);
o := [set];
Assert(1, not set in hashmap);
hashmap[set] := true;
for pt in o do
for g in gens do
im := OnSets(pt, g);
if not im in hashmap then
hashmap[im] := true;
Add(o, im);
fi;
od;
od;
return o;
end);

InstallMethod(RepresentativeOutNeighbours, "for a digraph by out-neighbours",
[IsDigraphByOutNeighboursRep],
function(D)
Expand Down
3 changes: 2 additions & 1 deletion gap/utils.gi
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ function(arg)
s := InputTextString(ex[1]);

start_time := IO_gettimeofday();
test := Test(s, rec(ignoreComments := false,
test := Test(s, rec(compareFunction := "uptowhitespace",
ignoreComments := false,
width := 72,
EQ := EQ,
reportDiff := Ignore,
Expand Down
20 changes: 20 additions & 0 deletions tst/standard/grahom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,26 @@ false
gap> IsLatticeEpimorphism(D, D, (2, 3));
true

# SubdigraphsMonomorphisms
gap> SubdigraphsMonomorphisms(CompleteBipartiteDigraph(2, 2),
> CompleteDigraph(4));
[ Transformation( [ 1, 3, 2 ] ), Transformation( [ 2, 3, 1 ] ),
Transformation( [ 3, 4, 2, 1 ] ) ]
gap> D := DigraphFromGraph6String("D^{");
<immutable symmetric digraph with 5 vertices, 18 edges>
gap> SubdigraphsMonomorphisms(CompleteDigraph(4), D);
[ Transformation( [ 1, 3, 4, 5, 5 ] ), Transformation( [ 2, 3, 4, 5, 5 ] ) ]
gap> Length(SubdigraphsMonomorphisms(CompleteDigraph(4), CompleteDigraph(12)));
495
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

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

0 comments on commit f24fb1b

Please sign in to comment.