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
50 changes: 50 additions & 0 deletions doc/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,56 @@ gap> DigraphCore(D);
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphMaximalQuotients">
<ManSection>
<Attr Name="DigraphMaximalQuotients" Arg="digraph"/>
<Returns>A list of digraphs.</Returns>
<Description>
If <A>digraph</A> is a digraph with <C>n</C> vertices, then this
attribute returns a list containing all maximal proper quotients of
<A>digraph</A>, up to isomorphism. That is, the list contains precisely
one representative from each isomorphism class of maximal proper quotients
of <A>digraph</A>.
<P/>

A <E>maximal proper quotient</E> of <A>digraph</A> is a quotient (see
<Ref Oper="QuotientDigraph"/>) obtained by amalgamating precisely two
vertices of <A>digraph</A>. Thus, each maximal proper quotient of
<A>digraph</A> has <C>n - 1</C> vertices. If <A>digraph</A> has fewer
than two vertices, an empty list is returned.
Comment thread
mtorpey marked this conversation as resolved.
Resolved
<P/>

The quotients are defined as in <Ref Oper="QuotientDigraph"/>. In
particular, they never contain multiple edges, even if <A>digraph</A>
does. However, loops may appear through identifying two adjacent vertices.
<P/>

The attribute has at least quadratic complexity in the number of vertices
of <A>digraph</A>.
<Example><![CDATA[
gap> D := CycleDigraph(4);
<immutable cycle digraph with 4 vertices>
gap> DigraphVertices(D);
[ 1 .. 4 ]
gap> DigraphEdges(D);
[ [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 1 ] ]
gap> mq := DigraphMaximalQuotients(D);
[ <immutable digraph with 3 vertices, 4 edges>,
<immutable digraph with 3 vertices, 4 edges> ]
gap> List(mq, DigraphNrVertices);
[ 3, 3 ]
gap> List(mq, DigraphEdges);
[ [ [ 1, 1 ], [ 1, 2 ], [ 2, 3 ], [ 3, 1 ] ],
[ [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 3, 1 ] ] ]
gap> DigraphMaximalQuotients(EmptyDigraph(1));
[ ]
gap> DigraphMaximalQuotients(EmptyDigraph(5));
[ <immutable empty digraph with 4 vertices> ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="CharacteristicPolynomial">
<ManSection>
<Attr Name="CharacteristicPolynomial" Arg="digraph"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<#Include Label="UndirectedSpanningTree">
<#Include Label="DigraphShortestPathSpanningTree">
<#Include Label="QuotientDigraph">
<#Include Label="DigraphMaximalQuotients">
<#Include Label="DigraphHalfSquare">
<#Include Label="DigraphReverse">
<#Include Label="DigraphDual">
Expand Down
1 change: 1 addition & 0 deletions gap/attr.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ DeclareAttribute("ChromaticNumber", IsDigraph);
DeclareAttribute("DigraphBicomponents", IsDigraph);
DeclareAttribute("DIGRAPHS_Bipartite", IsDigraph);
DeclareAttribute("DigraphCore", IsDigraph);
DeclareAttribute("DigraphMaximalQuotients", IsDigraph);

DeclareAttribute("CharacteristicPolynomial", IsDigraph);
DeclareAttribute("NrSpanningTrees", IsDigraph);
Expand Down
47 changes: 47 additions & 0 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,53 @@ function(D)
return DigraphVertexLabels(D);
end);

InstallMethod(DigraphMaximalQuotients, "for a digraph", [IsDigraph],
function(D)
local n, aut, orbs, pairs_to_merge, candidates, c, distinct_canons,
max_quotients;

D := DigraphImmutableCopyIfMutable(D);

n := DigraphNrVertices(D);
if n < 2 then
return [];
elif IsEmptyDigraph(D) then
return [EmptyDigraph(n - 1)];
fi;

# This is to ensure compatibility with AutomorphismGroup and QuotientDigraph.
if IsMultiDigraph(D) then
aut := AutomorphismGroup(DigraphRemoveAllMultipleEdges(D));
Comment thread
mtorpey marked this conversation as resolved.
Resolved
else
aut := AutomorphismGroup(D);
fi;

# Creating orbit representatives.
# TODO: Use EnumeratorOfCombinations here once available.
orbs := Orbits(aut, Combinations(DigraphVertices(D), 2), OnSets);
Comment thread
mtorpey marked this conversation as resolved.
Resolved
pairs_to_merge := List(orbs, Representative);

# Creating list of candidate maximal quotients.
candidates := List(pairs_to_merge,
pair -> QuotientDigraph(D, Concatenation([pair],
List(Difference(DigraphVertices(D), pair), v -> [v]))));

# Filtering candidate list based on isomorphism.
distinct_canons := Set([]);
max_quotients := [];

# This part could be optimised.
for c in candidates do
AddSet(distinct_canons, BlissCanonicalDigraph(c));

if Length(distinct_canons) > Length(max_quotients) then
Add(max_quotients, c);
fi;
od;

return max_quotients;
end);

InstallMethod(CharacteristicPolynomial, "for a digraph", [IsDigraph],
D -> CharacteristicPolynomial(AdjacencyMatrix(D)));

Expand Down
141 changes: 140 additions & 1 deletion tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#@local G, H, M, M1, P, S, a, adj, adj1, adj2, adjacencies, b
#@local circuit, complete15, comps, cycle12, e, edgeCut, erev, filename, forest
#@local g, gNew, gr, gr1, gr2, gr3, gr4, grid, group, i, id, isGraph, j, mat
#@local multiple, names, nbs, nonPlanar, order, outs, planar, probs, proj, r, rd
#@local mq, mq1, mq_all, multiple, names, nbs, nonPlanar, order, outs, planar
#@local probs, proj, r, rd
#@local reflextrans, reflextrans1, reflextrans2, representatives, rev, rgr
#@local rotationSy, rotationSystem, scc, schreierVector, sink, soccer, str
#@local table, temp, topo, trans, trans1, trans2, tree, wcc, x, y, z
Expand Down Expand Up @@ -2564,6 +2565,144 @@ gap> D := Digraph([[2], [1, 3], []]);;
gap> DigraphCore(D);
[ 1, 2 ]

# DigraphMaximalQuotients
gap> DigraphMaximalQuotients(EmptyDigraph(0));
[ ]
gap> DigraphMaximalQuotients(EmptyDigraph(1));
[ ]
gap> DigraphMaximalQuotients(EmptyDigraph(5));
[ <immutable empty digraph with 4 vertices> ]
gap> D := ChainDigraph(2);;
gap> mq := DigraphMaximalQuotients(D);;
gap> mq = [Digraph([[1]])];
true
gap> DigraphNrLoops(D);
0
gap> DigraphNrLoops(mq[1]);
1
gap> D := CompleteDigraph(2);;
gap> DigraphMaximalQuotients(D) = [Digraph([[1]])];
true
gap> D := Digraph([[2], [2]]);;
gap> DigraphNrEdges(D);
2
gap> DigraphNrLoops(D);
1
gap> mq := DigraphMaximalQuotients(D);;
gap> mq = [Digraph([[1]])];
true
gap> Length(mq);
1
gap> DigraphNrEdges(mq[1]);
1
gap> DigraphNrLoops(mq[1]);
1
gap> D := CompleteDigraph(5);;
gap> DigraphNrLoops(D);
0
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
1
gap> DigraphNrVertices(mq[1]);
4
gap> DigraphNrEdges(mq[1]);
13
gap> DigraphNrLoops(mq[1]);
1
gap> D := ChainDigraph(3);;
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
3
gap> ForAll([Digraph([[1, 2], []]), Digraph([[2], [2]]), Digraph([[2], [1]])],
> d -> ForAny(mq, q -> IsIsomorphicDigraph(d, q)));
true
gap> D := Digraph([[2], [], []]);;
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
2
gap> ForAll([Digraph([[1], []]), Digraph([[2], []])],
> d -> ForAny(mq, q -> IsIsomorphicDigraph(d, q)));
true
gap> D := CycleDigraph(4);;
gap> mq := DigraphMaximalQuotients(D);;
gap> mq_all := List(PartitionsSet(DigraphVertices(D),
> DigraphNrVertices(D) - 1), p -> QuotientDigraph(D, p));;
gap> Length(mq);
2
gap> Length(mq_all);
6
gap> ForAll([Digraph([[2], [2, 3], [1]]), Digraph([[2], [1, 3], [2]])],
> d -> ForAny(mq, q -> IsIsomorphicDigraph(d, q)));
true
gap> ForAll(mq_all, q -> ForAny(mq, r -> IsIsomorphicDigraph(q, r)));
true
gap> D := AndrasfaiGraph(3);;
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
4
gap> mq_all := List(PartitionsSet(DigraphVertices(D),
> DigraphNrVertices(D) - 1), p -> QuotientDigraph(D, p));;
gap> Length(mq_all);
28
gap> ForAll(mq_all, q -> ForAny(mq, r -> IsIsomorphicDigraph(q, r)));
true
gap> ForAll(Combinations(mq, 2), p -> not IsIsomorphicDigraph(p[1], p[2]));
true
gap> D := Digraph([[2, 3], [3], [1, 4], [5], [1], [2, 6]]);;
gap> mq := DigraphMaximalQuotients(D);;
gap> mq_all := List(PartitionsSet(DigraphVertices(D),
> DigraphNrVertices(D) - 1), p -> QuotientDigraph(D, p));;
gap> ForAll(mq, q -> DigraphNrVertices(q) = 5);
true
gap> ForAll(Combinations(mq, 2), p -> not IsIsomorphicDigraph(p[1], p[2]));
true
gap> ForAll(mq_all, q -> ForAny(mq, r -> IsIsomorphicDigraph(q, r)));
true
gap> D1 := OnDigraphs(D, (1, 2, 3, 4, 5, 6));;
gap> D <> D1;
true
gap> IsIsomorphicDigraph(D, D1);
true
gap> mq1 := DigraphMaximalQuotients(D1);;
gap> ForAll(mq, q -> ForAny(mq1, r -> IsIsomorphicDigraph(q, r)))
> and ForAll(mq1, q -> ForAny(mq, r -> IsIsomorphicDigraph(q, r)));
true
gap> D := DigraphDisjointUnion(ChainDigraph(5), EmptyDigraph(1));;
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
11
gap> mq_all := List(PartitionsSet(DigraphVertices(D),
> DigraphNrVertices(D) - 1), p -> QuotientDigraph(D, p));;
gap> Length(mq_all);
15
gap> ForAll(mq_all, q -> ForAny(mq, r -> IsIsomorphicDigraph(q, r)));
true
gap> ForAll(Combinations(mq, 2), p -> not IsIsomorphicDigraph(p[1], p[2]));
true
gap> D := Digraph([[2, 2], [3], [3]]);;
gap> IsMultiDigraph(D);
true
gap> mq := DigraphMaximalQuotients(D);;
gap> Length(mq);
3
gap> ForAny(mq, IsMultiDigraph);
false
gap> ForAll([Digraph([[1, 2], [2]]), Digraph([[2], [2]]),
> Digraph([[2], [1, 2]])],
> d -> ForAny(mq, q -> IsIsomorphicDigraph(d, q)));
true
gap> D := Digraph(IsMutableDigraph, [[2], [3], [1]]);;
gap> IsMutableDigraph(D);
true
gap> mq := DigraphMaximalQuotients(D);
[ <immutable digraph with 2 vertices, 3 edges> ]
gap> OutNeighbours(D);
[ [ 2 ], [ 3 ], [ 1 ] ]
gap> IsMutableDigraph(D);
true
gap> ForAll(mq, IsImmutableDigraph);
true

# MaximalAntiSymmetricSubdigraph
gap> MaximalAntiSymmetricSubdigraph(Digraph([[2, 2], [1]]));
<immutable antisymmetric digraph with 2 vertices, 1 edge>
Expand Down
Loading