From a01f608eb71a321feda9f6c2d13a063564494a20 Mon Sep 17 00:00:00 2001 From: Wilf Wilson Date: Thu, 22 Aug 2019 18:58:49 +0200 Subject: [PATCH] DenseDigraphRep -> DigraphByOutNeighboursRep --- doc/digraph.xml | 6 +- doc/z-chap2.xml | 2 +- gap/attr.gi | 169 +++++++++++++++++++++----------------- gap/cliques.gi | 22 ++--- gap/constructors.gi | 12 +-- gap/digraph.gd | 3 +- gap/digraph.gi | 33 ++++---- gap/display.gi | 15 ++-- gap/grahom.gi | 26 +++--- gap/io.gi | 12 ++- gap/oper.gi | 173 +++++++++++++++++++++------------------ gap/orbits.gi | 4 +- gap/prop.gi | 32 ++++---- tst/standard/cliques.tst | 4 +- tst/standard/digraph.tst | 4 +- tst/standard/oper.tst | 36 ++++---- 16 files changed, 301 insertions(+), 252 deletions(-) diff --git a/doc/digraph.xml b/doc/digraph.xml index eff32655f..18f5f61bb 100644 --- a/doc/digraph.xml +++ b/doc/digraph.xml @@ -159,12 +159,12 @@ true <#/GAPDoc> -<#GAPDoc Label="DenseDigraphType"> +<#GAPDoc Label="DigraphByOutNeighboursType"> - + - The type of all digraphs is DenseDigraphType. + The type of all digraphs is DigraphByOutNeighboursType. The family of all digraphs is DigraphFamily. diff --git a/doc/z-chap2.xml b/doc/z-chap2.xml index e4590ea4f..ae9c78c9c 100644 --- a/doc/z-chap2.xml +++ b/doc/z-chap2.xml @@ -6,7 +6,7 @@ <#Include Label="IsDigraph"> <#Include Label="IsCayleyDigraph"> <#Include Label="IsDigraphWithAdjacencyFunction"> - <#Include Label="DenseDigraphType"> + <#Include Label="DigraphByOutNeighboursType"> <#Include Label="Digraph"> <#Include Label="DigraphByAdjacencyMatrix"> <#Include Label="DigraphByEdges"> diff --git a/gap/attr.gi b/gap/attr.gi index 99d50aa4c..cfcf67408 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -8,16 +8,17 @@ ############################################################################# ## -InstallMethod(DigraphNrVertices, "for a dense digraph", [IsDenseDigraphRep], -DIGRAPH_NR_VERTICES); +InstallMethod(DigraphNrVertices, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], DIGRAPH_NR_VERTICES); -InstallMethod(OutNeighbours, "for a dense digraph", [IsDenseDigraphRep], -DIGRAPH_OUT_NEIGHBOURS); +InstallMethod(OutNeighbours, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], DIGRAPH_OUT_NEIGHBOURS); # The next method is (yet another) DFS as described in # http://www.eecs.wsu.edu/~holder/courses/CptS223/spr08/slides/graphapps.pdf -InstallMethod(ArticulationPoints, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(ArticulationPoints, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local copy, nbs, counter, visited, num, low, parent, points, points_seen, stack, depth, v, w, i; @@ -98,7 +99,8 @@ function(D) fi; end); -InstallMethod(ChromaticNumber, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(ChromaticNumber, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local nr, comps, upper, chrom, tmp_comps, tmp_upper, n, comp, bound, clique, c, i; @@ -246,10 +248,11 @@ end); # return out; # end); -InstallMethod(DigraphAdjacencyFunction, "for a dense digraph", [IsDigraph], -D -> {u, v} -> IsDigraphEdge(D, u, v)); +InstallMethod(DigraphAdjacencyFunction, "for a digraph by out-neighbours", +[IsDigraph], D -> {u, v} -> IsDigraphEdge(D, u, v)); -InstallMethod(AsTransformation, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(AsTransformation, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) if not IsFunctionalDigraph(D) then return fail; @@ -257,10 +260,11 @@ function(D) return Transformation(Concatenation(OutNeighbours(D))); end); -InstallMethod(DigraphNrEdges, "for a digraph", [IsDenseDigraphRep], +InstallMethod(DigraphNrEdges, "for a digraph", [IsDigraphByOutNeighboursRep], DIGRAPH_NREDGES); -InstallMethod(DigraphEdges, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphEdges, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, adj, nr, i, j; out := EmptyPlist(DigraphNrEdges(D)); @@ -283,8 +287,9 @@ InstallMethod(AsGraph, "for a digraph", [IsDigraph], Graph); InstallMethod(DigraphVertices, "for a digraph", [IsDigraph], D -> [1 .. DigraphNrVertices(D)]); -InstallMethod(DigraphRange, "for a dense digraph attribute storing digraph", -[IsDenseDigraphRep and IsImmutableDigraph], +InstallMethod(DigraphRange, +"for an immutable digraph by out-neighbours", +[IsDigraphByOutNeighboursRep and IsImmutableDigraph], function(D) if not IsBound(D!.DigraphRange) then DIGRAPH_SOURCE_RANGE(D); @@ -293,12 +298,14 @@ function(D) return D!.DigraphRange; end); -InstallMethod(DigraphRange, "for a dense digraph attribute storing digraph", -[IsDenseDigraphRep and IsMutableDigraph], +InstallMethod(DigraphRange, +"for a mutable digraph by out-neighbours", +[IsDigraphByOutNeighboursRep and IsMutableDigraph], D -> DIGRAPH_SOURCE_RANGE(D).DigraphRange); -InstallMethod(DigraphSource, "for a dense digraph attribute storing digraph", -[IsDenseDigraphRep and IsImmutableDigraph], +InstallMethod(DigraphSource, +"for an immutable digraph by out-neighbours", +[IsDigraphByOutNeighboursRep and IsImmutableDigraph], function(D) if not IsBound(D!.DigraphSource) then DIGRAPH_SOURCE_RANGE(D); @@ -307,18 +314,19 @@ function(D) return D!.DigraphSource; end); -InstallMethod(DigraphSource, "for a dense digraph attribute storing digraph", -[IsDenseDigraphRep and IsMutableDigraph], +InstallMethod(DigraphSource, +"for a mutable digraph by out-neighbours", +[IsDigraphByOutNeighboursRep and IsMutableDigraph], D -> DIGRAPH_SOURCE_RANGE(D).DigraphSource); -InstallMethod(InNeighbours, "for a digraph", [IsDenseDigraphRep], +InstallMethod(InNeighbours, "for a digraph", [IsDigraphByOutNeighboursRep], D -> DIGRAPH_IN_OUT_NBS(OutNeighbours(D))); -InstallMethod(AdjacencyMatrix, "for a digraph", [IsDenseDigraphRep], +InstallMethod(AdjacencyMatrix, "for a digraph", [IsDigraphByOutNeighboursRep], ADJACENCY_MATRIX); -InstallMethod(BooleanAdjacencyMatrix, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(BooleanAdjacencyMatrix, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n, nbs, mat, i, j; n := DigraphNrVertices(D); @@ -332,8 +340,8 @@ function(D) return mat; end); -InstallMethod(DigraphShortestDistances, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphShortestDistances, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local vertices, data, sum, distances, v, u; if HasDIGRAPHS_ConnectivityData(D) then @@ -365,12 +373,13 @@ end); # returns the vertices (i.e. numbers) of ordered so that there are no # edges from to for all greater than . -InstallMethod(DigraphTopologicalSort, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphTopologicalSort, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], D -> DIGRAPH_TOPO_SORT(OutNeighbours(D))); -InstallMethod(DigraphStronglyConnectedComponents, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphStronglyConnectedComponents, +"for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local verts; @@ -391,15 +400,16 @@ InstallMethod(DigraphNrStronglyConnectedComponents, "for a digraph", [IsDigraph], D -> Length(DigraphStronglyConnectedComponents(D).comps)); -InstallMethod(DigraphConnectedComponents, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphConnectedComponents, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], DIGRAPH_CONNECTED_COMPONENTS); InstallMethod(DigraphNrConnectedComponents, "for a digraph", [IsDigraph], D -> Length(DigraphConnectedComponents(D).comps)); -InstallMethod(OutDegrees, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(OutDegrees, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local adj, degs, i; adj := OutNeighbours(D); @@ -412,7 +422,7 @@ end); InstallMethod(InDegrees, "for a digraph with in neighbours", [IsDigraph and HasInNeighbours], -2, # to beat the method for IsDenseDigraphRep +2, # to beat the method for IsDigraphByOutNeighboursRep function(D) local inn, degs, i; inn := InNeighbours(D); @@ -423,7 +433,8 @@ function(D) return degs; end); -InstallMethod(InDegrees, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(InDegrees, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local adj, degs, x, i; adj := OutNeighbours(D); @@ -445,8 +456,8 @@ function(D) end); InstallMethod(OutDegreeSequence, -"for a dense digraph with known digraph group", -[IsDenseDigraphRep and HasDigraphGroup], +"for a digraph by out-neighbours with known digraph group", +[IsDigraphByOutNeighboursRep and HasDigraphGroup], function(D) local out, adj, orbs, orb; out := []; @@ -498,7 +509,7 @@ end); InstallMethod(DigraphSources, "for a digraph with in-neighbours", [IsDigraph and HasInNeighbours], -2, # to beat the method for IsDenseDigraphRep +2, # to beat the method for IsDigraphByOutNeighboursRep function(D) local inn, sources, count, i; @@ -515,7 +526,8 @@ function(D) return sources; end); -InstallMethod(DigraphSources, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphSources, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, seen, tmp, next, v; out := OutNeighbours(D); @@ -533,14 +545,15 @@ end); InstallMethod(DigraphSinks, "for a digraph with out-degrees", [IsDigraph and HasOutDegrees], -2, # to beat the method for IsDenseDigraphRep +2, # to beat the method for IsDigraphByOutNeighboursRep function(D) local degs; degs := OutDegrees(D); return Filtered(DigraphVertices(D), x -> degs[x] = 0); end); -InstallMethod(DigraphSinks, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphSinks, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, sinks, count, i; @@ -556,7 +569,7 @@ function(D) return sinks; end); -InstallMethod(DigraphPeriod, "for a digraph", [IsDenseDigraphRep], +InstallMethod(DigraphPeriod, "for a digraph", [IsDigraphByOutNeighboursRep], function(D) local comps, out, deg, nrvisited, period, stack, len, depth, current, olddepth, i; @@ -801,7 +814,8 @@ function(D) return DIGRAPHS_DiameterAndUndirectedGirth(D).girth; end); -InstallMethod(DigraphGirth, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphGirth, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local verts, girth, out, dist, i, j; if DigraphHasLoops(D) then @@ -893,8 +907,8 @@ function(D) return circs[Position(lens, max)]; end); -InstallMethod(DigraphAllSimpleCircuits, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphAllSimpleCircuits, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local UNBLOCK, CIRCUIT, out, stack, endofstack, C, scc, n, blocked, B, c_comp, comp, s, loops, i; @@ -1008,7 +1022,8 @@ end); # It is the backend to IsBipartiteDigraph, Bicomponents, and DigraphColouring # for a 2-colouring -InstallMethod(DIGRAPHS_Bipartite, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DIGRAPHS_Bipartite, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n, t, colours, in_nbrs, stack, pop, v, pos, nbrs, w, i; n := DigraphNrVertices(D); @@ -1063,7 +1078,8 @@ function(D) return b; end); -InstallMethod(DigraphLoops, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphLoops, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) if HasDigraphHasLoops(D) and not DigraphHasLoops(D) then return []; @@ -1089,7 +1105,8 @@ function(D) return DIGRAPHS_Degeneracy(DigraphRemoveLoops(D))[2]; end); -InstallMethod(DIGRAPHS_Degeneracy, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DIGRAPHS_Degeneracy, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local nbs, n, out, deg_vert, m, verts_deg, k, i, v, d, w; @@ -1219,7 +1236,8 @@ function(digraph) elif IsCompleteDigraph(digraph) then return DigraphVertexLabels(digraph); elif IsSymmetricDigraph(digraph) and IsBipartiteDigraph(digraph) then - i := First(DigraphVertices(digraph), i -> OutDegreeOfVertex(digraph, i) > 0); + i := First(DigraphVertices(digraph), + i -> OutDegreeOfVertex(digraph, i) > 0); return DigraphVertexLabels(digraph){ [i, OutNeighboursOfVertex(digraph, i)[1]]}; elif not IsConnectedDigraph(digraph) then @@ -1333,8 +1351,8 @@ end); # Things that are attributes for immutable digraphs, but operations for mutable. -InstallMethod(DigraphReverse, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphReverse, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local inn, C; if IsSymmetricDigraph(D) then @@ -1359,8 +1377,8 @@ InstallMethod(DigraphReverse, "for a digraph with known digraph reverse", InstallMethod(DigraphReverseAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphReverse); -InstallMethod(DigraphDual, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphDual, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local nodes, C, list, i; if IsMultiDigraph(D) then @@ -1392,8 +1410,8 @@ InstallMethod(DigraphDual, "for a digraph with known dual", InstallMethod(DigraphDualAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphDual); -InstallMethod(ReducedDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(ReducedDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local v, niv, old, C, i; if IsConnectedDigraph(D) then @@ -1425,8 +1443,9 @@ InstallMethod(ReducedDigraph, "for a digraph with known reduced digraph", InstallMethod(ReducedDigraphAttr, "for an immutable digraph", [IsImmutableDigraph], ReducedDigraph); -InstallMethod(DigraphRemoveAllMultipleEdges, "for a mutable dense digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(DigraphRemoveAllMultipleEdges, +"for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) local nodes, list, empty, seen, keep, v, u, pos; @@ -1464,8 +1483,8 @@ function(D) return D; end); -InstallMethod(DigraphAddAllLoops, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphAddAllLoops, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local ismulti, C, list, v; if HasIsReflexiveDigraph(D) and IsReflexiveDigraph(D) then @@ -1499,8 +1518,8 @@ InstallMethod(DigraphAddAllLoops, "for a digraph with known add-all-loops", InstallMethod(DigraphAddAllLoopsAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphAddAllLoops); -InstallMethod(DigraphRemoveLoops, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphRemoveLoops, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local C, out, lbl, pos, v; C := DigraphMutableCopyIfImmutable(D); @@ -1529,8 +1548,8 @@ InstallMethod(DigraphRemoveLoopsAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphRemoveLoops); # TODO (FLS): I've just added 1 as the edge label here, is this really desired? -InstallMethod(DigraphSymmetricClosure, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphSymmetricClosure, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n, m, verts, C, mat, out, x, i, j, k; @@ -1624,8 +1643,8 @@ DigraphSymmetricClosureAttr); InstallMethod(DigraphSymmetricClosureAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphSymmetricClosure); -InstallMethod(MaximalSymmetricSubdigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(MaximalSymmetricSubdigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local C, inn, out, i; @@ -1693,8 +1712,8 @@ function(D) return D; end); -InstallMethod(MaximalAntiSymmetricSubdigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(MaximalAntiSymmetricSubdigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n, C, m, out, i, j; @@ -1759,8 +1778,9 @@ MaximalAntiSymmetricSubdigraphAttr); InstallMethod(MaximalAntiSymmetricSubdigraphAttr, "for an immutable digraph", [IsImmutableDigraph], MaximalAntiSymmetricSubdigraph); -InstallMethod(DigraphTransitiveClosure, "for a mutable dense digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(DigraphTransitiveClosure, +"for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) local list, m, n, nodes, sorted, trans, tmp, mat, v, u, i; @@ -1851,8 +1871,8 @@ DigraphReflexiveTransitiveClosureAttr); InstallMethod(DigraphReflexiveTransitiveClosureAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphReflexiveTransitiveClosure); -InstallMethod(DigraphTransitiveReduction, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphTransitiveReduction, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local topo, p, C; if IsMultiDigraph(D) then @@ -1888,8 +1908,9 @@ InstallMethod(DigraphTransitiveReductionAttr, "for an immutable digraph", # For a topologically sortable digraph G, this returns the least subgraph G' # of G such that the (reflexive) transitive closures of G and G' are equal. -InstallMethod(DigraphReflexiveTransitiveReduction, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphReflexiveTransitiveReduction, +"for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local C; if IsMultiDigraph(D) then @@ -1925,8 +1946,8 @@ InstallMethod(DigraphReflexiveTransitiveReductionAttr, "for an immutable digraph", [IsImmutableDigraph], DigraphReflexiveTransitiveReduction); -InstallMethod(UndirectedSpanningForest, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(UndirectedSpanningForest, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local C; if DigraphNrVertices(D) = 0 then diff --git a/gap/cliques.gi b/gap/cliques.gi index d0d5328e7..498242fb1 100644 --- a/gap/cliques.gi +++ b/gap/cliques.gi @@ -13,8 +13,9 @@ InstallMethod(CliqueNumber, "for a digraph", [IsDigraph], D -> Maximum(List(DigraphMaximalCliquesReps(D), Length))); -InstallMethod(IsIndependentSet, "for a dense digraph and a homogeneous list", -[IsDenseDigraphRep, IsHomogeneousList], +InstallMethod(IsIndependentSet, +"for a digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, list) local x; if not IsDuplicateFreeList(list) @@ -31,8 +32,8 @@ function(D, list) end); InstallMethod(IsMaximalIndependentSet, -"for a dense digraph and a homogeneous list", -[IsDenseDigraphRep, IsHomogeneousList], +"for a digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, set) local nbs, vtx, try, i; @@ -56,8 +57,8 @@ function(D, set) return not ForAny(try, x -> IsEmpty(Intersection(set, nbs[x]))); end); -InstallMethod(IsClique, "for a dense digraph and a homogeneous list", -[IsDenseDigraphRep, IsHomogeneousList], +InstallMethod(IsClique, "for a digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, clique) local nbs, v; if not IsDuplicateFreeList(clique) @@ -74,8 +75,9 @@ function(D, clique) return true; end); -InstallMethod(IsMaximalClique, "for a dense digraph and a homogeneous list", -[IsDenseDigraphRep, IsHomogeneousList], +InstallMethod(IsMaximalClique, +"for a digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, clique) local nbs, try, n, i; @@ -244,8 +246,8 @@ function(arg) # Validate arg[2] D := arg[2]; - if not IsDenseDigraphRep(D) then - ErrorNoReturn("the 1st argument must be a dense digraph,"); + if not IsDigraphByOutNeighboursRep(D) then + ErrorNoReturn("the 1st argument must be a digraph by out-neighbours,"); fi; # Validate arg[3] diff --git a/gap/constructors.gi b/gap/constructors.gi index 97a50e231..c34b42afb 100644 --- a/gap/constructors.gi +++ b/gap/constructors.gi @@ -11,8 +11,8 @@ # This file contains constructions of certain types of digraphs, from other # digraphs. -InstallMethod(BipartiteDoubleDigraph, "for a dense mutable digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(BipartiteDoubleDigraph, "for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) local list, N, i, j; list := D!.OutNeighbours; @@ -43,8 +43,8 @@ function(D) return C; end); -InstallMethod(DoubleDigraph, "for a dense mutable digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(DoubleDigraph, "for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) local list, N, i, j; list := D!.OutNeighbours; @@ -76,8 +76,8 @@ function(D) end); InstallMethod(DistanceDigraph, -"for a dense mutable digraph and a list of distances", -[IsMutableDigraph and IsDenseDigraphRep, IsList], +"for a mutable digraph by out-neighbours and a list of distances", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsList], function(D, distances) local list, x; # Can't change D!.OutNeighbours in-place, since it is used by diff --git a/gap/digraph.gd b/gap/digraph.gd index 0e3b56488..bb4103ecd 100644 --- a/gap/digraph.gd +++ b/gap/digraph.gd @@ -19,7 +19,8 @@ DeclareSynonym("IsMutableDigraph", IsDigraph and IsMutable); BindGlobal("DigraphFamily", NewFamily("DigraphFamily", IsDigraph)); # Representations -DeclareRepresentation("IsDenseDigraphRep", IsDigraph and IsComponentObjectRep, +DeclareRepresentation("IsDigraphByOutNeighboursRep", + IsDigraph and IsComponentObjectRep, ["OutNeighbours"]); # 2. Digraph no-check constructors . . . diff --git a/gap/digraph.gi b/gap/digraph.gi index 60c1ad6f1..2dafaa1a9 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -28,8 +28,8 @@ # 1. Digraph types ######################################################################## -BindGlobal("DenseDigraphType", NewType(DigraphFamily, - IsDenseDigraphRep)); +BindGlobal("DigraphByOutNeighboursType", NewType(DigraphFamily, + IsDigraphByOutNeighboursRep)); ######################################################################## # 2. Digraph no-check constructors @@ -40,7 +40,7 @@ function(record) local D; Assert(1, IsBound(record.OutNeighbours)); Assert(1, Length(NamesOfComponents(record)) = 1); - D := Objectify(DenseDigraphType, record); + D := Objectify(DigraphByOutNeighboursType, record); SetFilterObj(D, IsMutable); return D; end); @@ -122,7 +122,8 @@ record -> DigraphConsNC(IsImmutableDigraph, record)); # 3. Digraph copies ######################################################################## -InstallMethod(DigraphMutableCopy, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DigraphMutableCopy, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local copy; copy := ConvertToMutableDigraphNC(OutNeighboursMutableCopy(D)); @@ -131,8 +132,8 @@ function(D) return copy; end); -InstallMethod(DigraphImmutableCopy, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DigraphImmutableCopy, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local copy; copy := ConvertToImmutableDigraphNC(OutNeighboursMutableCopy(D)); @@ -176,7 +177,7 @@ InstallMethod(DigraphMutableCopyIfMutable, "for an immutable digraph", ######################################################################## InstallMethod(PostMakeImmutable, "for a digraph", -[IsDigraph and IsDenseDigraphRep], +[IsDigraph and IsDigraphByOutNeighboursRep], function(D) MakeImmutable(D!.OutNeighbours); SetFilterObj(D, IsImmutableDigraph); @@ -570,32 +571,32 @@ function(D) return str; end); -InstallMethod(PrintString, "for a dense immutable digraph", -[IsImmutableDigraph and IsDenseDigraphRep], +InstallMethod(PrintString, "for an immutable digraph by out-neighbours", +[IsImmutableDigraph and IsDigraphByOutNeighboursRep], function(D) return Concatenation("Digraph( IsImmutableDigraph, ", PrintString(OutNeighbours(D)), " )"); end); -InstallMethod(PrintString, "for a dense mutable digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(PrintString, "for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) return Concatenation("Digraph( IsMutableDigraph, ", PrintString(OutNeighbours(D)), " )"); end); -InstallMethod(String, "for a dense immutable digraph", -[IsImmutableDigraph and IsDenseDigraphRep], +InstallMethod(String, "for an immutable digraph by out-neighbours", +[IsImmutableDigraph and IsDigraphByOutNeighboursRep], function(D) return Concatenation("Digraph( IsImmutableDigraph, ", String(OutNeighbours(D)), " )"); end); -InstallMethod(String, "for a dense mutable digraph", -[IsMutableDigraph and IsDenseDigraphRep], +InstallMethod(String, "for a mutable digraph by out-neighbours", +[IsMutableDigraph and IsDigraphByOutNeighboursRep], function(D) return Concatenation("Digraph( IsMutableDigraph, ", String(OutNeighbours(D)), @@ -907,7 +908,7 @@ InstallMethod(AsDigraph, "for a function and a transformation", InstallMethod(AsDigraph, "for a transformation", [IsTransformation], t -> AsDigraphCons(IsImmutableDigraph, t, DegreeOfTransformation(t))); -InstallMethod(AsBinaryRelation, "for a digraph", [IsDenseDigraphRep], +InstallMethod(AsBinaryRelation, "for a digraph", [IsDigraphByOutNeighboursRep], function(D) local rel; if DigraphNrVertices(D) = 0 then diff --git a/gap/display.gi b/gap/display.gi index 060d22347..33721b0ef 100644 --- a/gap/display.gi +++ b/gap/display.gi @@ -10,7 +10,8 @@ # AN's code, adapted by WW -InstallMethod(DotDigraph, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DotDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local str, out, i, j; str := "//dot\n"; @@ -29,8 +30,8 @@ function(D) return str; end); -InstallMethod(DotVertexLabelledDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DotVertexLabelledDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, str, i, j; out := OutNeighbours(D); @@ -55,8 +56,8 @@ function(D) return str; end); -InstallMethod(DotSymmetricDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(DotSymmetricDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, str, i, j; if not IsSymmetricDigraph(D) then @@ -259,8 +260,8 @@ InstallMethod(DotHighlightedDigraph, "for a digraph and list", {D, list} -> DotHighlightedDigraph(D, list, "black", "grey")); InstallMethod(DotHighlightedDigraph, -"for a dense digraph, list, and two strings", -[IsDenseDigraphRep, IsList, IsString, IsString], +"for a digraph by out-neighbours, list, and two strings", +[IsDigraphByOutNeighboursRep, IsList, IsString, IsString], function(D, highverts, highcolour, lowcolour) local lowverts, out, str, i, j; diff --git a/gap/grahom.gi b/gap/grahom.gi index b9e8cc354..395699071 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -143,8 +143,8 @@ function(D, order) end); InstallMethod(DigraphGreedyColouringNC, -"for a dense digraph and a homogeneous list", -[IsDenseDigraphRep, IsHomogeneousList], +"for a digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, order) local n, colour, colouring, out, inn, empty, all, available, nr_coloured, v; n := DigraphNrVertices(D); @@ -451,8 +451,9 @@ end); # IsDigraph{Homo/Epi/...}morphism ######################################################################## -InstallMethod(IsDigraphHomomorphism, "for a dense digraph, digraph, and perm", -[IsDenseDigraphRep, IsDigraph, IsPerm], +InstallMethod(IsDigraphHomomorphism, +"for a digraph by out-neighbours, a digraph, and a perm", +[IsDigraphByOutNeighboursRep, IsDigraph, IsPerm], function(src, ran, x) local i, j; if IsMultiDigraph(src) or IsMultiDigraph(ran) then @@ -475,8 +476,8 @@ InstallMethod(IsDigraphEndomorphism, "for a digraph and a perm", [IsDigraph, IsPerm], IsDigraphAutomorphism); InstallMethod(IsDigraphHomomorphism, -"for a dense digraph, digraph, and transformation", -[IsDenseDigraphRep, IsDigraph, IsTransformation], +"for a digraph by out-neighbours, digraph, and transformation", +[IsDigraphByOutNeighboursRep, IsDigraph, IsTransformation], function(src, ran, x) local i, j; if IsMultiDigraph(src) or IsMultiDigraph(ran) then @@ -525,8 +526,8 @@ InstallMethod(IsDigraphMonomorphism, "for digraph, digraph, and perm", [IsDigraph, IsDigraph, IsPerm], IsDigraphHomomorphism); InstallMethod(IsDigraphEmbedding, -"for digraph, dense digraph, and transformation", -[IsDigraph, IsDenseDigraphRep, IsTransformation], +"for digraph, digraph by out-neighbours, and transformation", +[IsDigraph, IsDigraphByOutNeighboursRep, IsTransformation], function(src, ran, x) local y, induced, i, j; if not IsDigraphMonomorphism(src, ran, x) then @@ -547,8 +548,9 @@ function(src, ran, x) return true; end); -InstallMethod(IsDigraphEmbedding, "for digraph, dense digraph, and perm", -[IsDigraph, IsDenseDigraphRep, IsPerm], +InstallMethod(IsDigraphEmbedding, +"for a digraph, a digraph by out-neighbours, and a perm", +[IsDigraph, IsDigraphByOutNeighboursRep, IsPerm], function(src, ran, x) local y, induced, i, j; if not IsDigraphHomomorphism(src, ran, x) then @@ -568,8 +570,8 @@ function(src, ran, x) return true; end); -InstallMethod(IsDigraphColouring, "for a dense digraph and a list", -[IsDenseDigraphRep, IsHomogeneousList], +InstallMethod(IsDigraphColouring, "for a digraph by out-neighbours and a list", +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, colours) local n, out, v, w; n := DigraphNrVertices(D); diff --git a/gap/io.gi b/gap/io.gi index cfbd59477..dedfc6a34 100644 --- a/gap/io.gi +++ b/gap/io.gi @@ -1445,7 +1445,8 @@ function(name, D, delimiter, offset) IO_Close(file); end); -InstallMethod(Graph6String, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(Graph6String, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local list, adj, n, lenlist, tablen, blist, i, j, pos, block; if (IsMultiDigraph(D) or not IsSymmetricDigraph(D) @@ -1497,7 +1498,8 @@ function(D) return List(list, i -> CharInt(i + 63)); end); -InstallMethod(Digraph6String, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(Digraph6String, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local list, adj, n, lenlist, tablen, blist, i, j, pos, block; # NOTE: this package originally used a version of digraph6 that reads down @@ -1547,7 +1549,8 @@ function(D) return List(list, i -> CharInt(i + 63)); end); -InstallMethod(Sparse6String, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(Sparse6String, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local list, n, lenlist, adj, nredges, k, blist, v, nextbit, AddBinary, i, j, bitstopad, pos, block; @@ -1653,7 +1656,8 @@ function(D) return List(list, i -> CharInt(i + 63)); end); -InstallMethod(DiSparse6String, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(DiSparse6String, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local list, n, lenlist, adj, source_i, range_i, source_d, range_d, len1, len2, sort_d, perm, sort_i, k, blist, v, nextbit, AddBinary, bitstopad, diff --git a/gap/oper.gi b/gap/oper.gi index b60b98eca..a27d4b2fd 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -27,8 +27,9 @@ # 1. Adding and removing vertices ############################################################################# -InstallMethod(DigraphAddVertex, "for a mutable dense digraph and an object", -[IsMutableDigraph and IsDenseDigraphRep, IsObject], +InstallMethod(DigraphAddVertex, +"for a mutable digraph by out-neighbours and an object", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsObject], function(D, label) Add(D!.OutNeighbours, []); SetDigraphVertexLabel(D, DigraphNrVertices(D), label); @@ -81,8 +82,8 @@ InstallMethod(DigraphAddVertices, "for an immutable digraph and an integer", {D, m} -> MakeImmutable(DigraphAddVertices(DigraphMutableCopy(D), m))); InstallMethod(DigraphRemoveVertex, -"for a mutable dense digraph and positive integer", -[IsMutableDigraph and IsDenseDigraphRep, IsPosInt], +"for a mutable digraph by out-neighbours and positive integer", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt], function(D, u) local pos, w, v; if u > DigraphNrVertices(D) then @@ -150,8 +151,8 @@ InstallMethod(DigraphRemoveVertices, "for an immutable digraph and a list", ############################################################################# InstallMethod(DigraphAddEdge, -"for a mutable dense digraph, a positive integer, and a positive integer", -[IsMutableDigraph and IsDenseDigraphRep, IsPosInt, IsPosInt], +"for a mutable digraph by out-neighbours, a two positive integers", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, src, ran) if not src in DigraphVertices(D)then ErrorNoReturn("the 2nd argument must be a vertex of the ", @@ -168,7 +169,7 @@ function(D, src, ran) end); InstallMethod(DigraphAddEdge, -"for an immutable digraph, a positive integer, and a positive integer", +"for an immutable digraph and two positive integers", [IsImmutableDigraph, IsPosInt, IsPosInt], function(D, src, ran) return MakeImmutable(DigraphAddEdge(DigraphMutableCopy(D), src, ran)); @@ -202,8 +203,8 @@ InstallMethod(DigraphAddEdges, "for an immutable digraph and a list", {D, edges} -> MakeImmutable(DigraphAddEdges(DigraphMutableCopy(D), edges))); InstallMethod(DigraphRemoveEdge, -"for a mutable dense digraph, a positive integer, and a positive integer", -[IsMutableDigraph and IsDenseDigraphRep, IsPosInt, IsPosInt], +"for a mutable digraph by out-neighbours and two positive integers", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, src, ran) local pos; if IsMultiDigraph(D) then @@ -225,7 +226,7 @@ function(D, src, ran) end); InstallMethod(DigraphRemoveEdge, -"for a immutable digraph, a positive integer, and a positive integer", +"for a immutable digraph and two positive integers", [IsImmutableDigraph, IsPosInt, IsPosInt], function(D, src, ran) return MakeImmutable(DigraphRemoveEdge(DigraphMutableCopy(D), src, ran)); @@ -257,8 +258,8 @@ InstallMethod(DigraphRemoveEdges, "for an immutable digraph and a list", {D, edges} -> MakeImmutable(DigraphRemoveEdges(DigraphMutableCopy(D), edges))); InstallMethod(DigraphReverseEdge, -"for a mutable dense digraph, positive integer, and positive integer", -[IsMutableDigraph and IsDenseDigraphRep, IsPosInt, IsPosInt], +"for a mutable digraph by out-neighbours and two positive integers", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, u, v) local pos; if IsMultiDigraph(D) then @@ -316,8 +317,8 @@ InstallMethod(DigraphReverseEdges, "for an immutable digraph and a list", {D, E} -> MakeImmutable(DigraphReverseEdges(DigraphMutableCopy(D), E))); InstallMethod(DigraphClosure, -"for a mutable dense digraph and a positive integer", -[IsMutableDigraph and IsDenseDigraphRep, IsPosInt], +"for a mutable digraph by out-neighbours and a positive integer", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt], function(D, k) local list, mat, deg, n, stop, i, j; @@ -352,7 +353,7 @@ function(D, k) end); InstallMethod(DigraphClosure, -"for an immutable dense digraph and a positive integer", +"for an immutable digraph by out-neighbours and a positive integer", [IsImmutableDigraph, IsPosInt], {D, k} -> MakeImmutable(DigraphClosure(DigraphMutableCopy(D), k))); @@ -393,9 +394,10 @@ function(arg) arg := arg[1]; fi; - if not IsList(arg) or IsEmpty(arg) or not ForAll(arg, IsDenseDigraphRep) then - ErrorNoReturn("the arguments must be dense digraphs, or a single ", - "list of dense digraphs,"); + if not IsList(arg) or IsEmpty(arg) + or not ForAll(arg, IsDigraphByOutNeighboursRep) then + ErrorNoReturn("the arguments must be digraphs by out-neighbours, or a ", + "single list of digraphs by out-neighbours,"); fi; D := arg[1]; @@ -422,9 +424,10 @@ function(arg) arg := arg[1]; fi; - if not IsList(arg) or IsEmpty(arg) or not ForAll(arg, IsDenseDigraphRep) then - ErrorNoReturn("the arguments must be dense digraphs, or a single ", - "list of dense digraphs,"); + if not IsList(arg) or IsEmpty(arg) + or not ForAll(arg, IsDigraphByOutNeighboursRep) then + ErrorNoReturn("the arguments must be digraphs by out-neighbours, or a ", + "single list of digraphs by out-neighbours,"); fi; D := arg[1]; @@ -462,9 +465,10 @@ function(arg) arg := arg[1]; fi; - if not IsList(arg) or IsEmpty(arg) or not ForAll(arg, IsDenseDigraphRep) then - ErrorNoReturn("the arguments must be dense digraphs, or a single ", - "list of dense digraphs,"); + if not IsList(arg) or IsEmpty(arg) + or not ForAll(arg, IsDigraphByOutNeighboursRep) then + ErrorNoReturn("the arguments must be digraphs by out-neighbours, or a ", + "single list of digraphs by out-neighbours,"); fi; D := arg[1]; @@ -495,8 +499,8 @@ end); # 4. Actions ############################################################################### -InstallMethod(OnDigraphs, "for a mutable dense digraph and a perm", -[IsMutableDigraph and IsDenseDigraphRep, IsPerm], +InstallMethod(OnDigraphs, "for a mutable digraph by out-neighbours and a perm", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPerm], function(D, p) local out; if ForAll(DigraphVertices(D), i -> i ^ p = i) then @@ -521,8 +525,9 @@ function(D, p) return MakeImmutable(OnDigraphs(DigraphMutableCopy(D), p)); end); -InstallMethod(OnDigraphs, "for a mutable dense digraph and a transformation", -[IsMutableDigraph and IsDenseDigraphRep, IsTransformation], +InstallMethod(OnDigraphs, +"for a mutable digraph by out-neighbours and a transformation", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsTransformation], function(D, t) local old, new, v; if ForAll(DigraphVertices(D), i -> i ^ t = i) then @@ -580,8 +585,8 @@ end); ############################################################################# InstallMethod(InducedSubdigraph, -"for a dense mutable digraph and a homogeneous list", -[IsDenseDigraphRep and IsMutableDigraph, IsHomogeneousList], +"for a mutable digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep and IsMutableDigraph, IsHomogeneousList], function(D, list) local M, N, old, old_edl, new_edl, lookup, next, vv, w, old_labels, v, i; @@ -639,8 +644,8 @@ function(D, list) end); InstallMethod(QuotientDigraph, -"for a dense mutable digraph and a homogeneous list", -[IsDenseDigraphRep and IsMutableDigraph, IsHomogeneousList], +"for a mutable digraph by out-neighbours and a homogeneous list", +[IsDigraphByOutNeighboursRep and IsMutableDigraph, IsHomogeneousList], function(D, partition) local N, M, check, lookup, new, new_vl, old, old_vl, x, i, u, v; @@ -704,7 +709,7 @@ end); # 6. In and out degrees, neighbours, and edges of vertices ############################################################################# -InstallMethod(InNeighboursOfVertex, "for a digraph and a vertex", +InstallMethod(InNeighboursOfVertex, "for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) if not v in DigraphVertices(D) then @@ -715,13 +720,14 @@ function(D, v) end); InstallMethod(InNeighboursOfVertexNC, -"for a digraph with in-neighbours and a vertex", +"for a digraph with in-neighbours and a positive integer", [IsDigraph and HasInNeighbours, IsPosInt], -2, # to beat the next method for IsDenseDigraphRep +2, # to beat the next method for IsDigraphByOutNeighboursRep {D, v} -> InNeighbours(D)[v]); -InstallMethod(InNeighboursOfVertexNC, "for a dense digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(InNeighboursOfVertexNC, +"for a digraph by out-neighbours and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], function(D, v) local inn, out, i, j; @@ -737,8 +743,9 @@ function(D, v) return inn; end); -InstallMethod(OutNeighboursOfVertex, "for a dense digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(OutNeighboursOfVertex, +"for a digraph by out-neighbours and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], function(D, v) if not v in DigraphVertices(D) then ErrorNoReturn("the 2nd argument is not a vertex of the ", @@ -747,11 +754,12 @@ function(D, v) return OutNeighboursOfVertexNC(D, v); end); -InstallMethod(OutNeighboursOfVertexNC, "for a dense digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(OutNeighboursOfVertexNC, +"for a digraph by out-neighbours and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], {D, v} -> OutNeighbours(D)[v]); -InstallMethod(InDegreeOfVertex, "for a digraph and a vertex", +InstallMethod(InDegreeOfVertex, "for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) if not v in DigraphVertices(D) then @@ -761,18 +769,19 @@ function(D, v) return InDegreeOfVertexNC(D, v); end); -InstallMethod(InDegreeOfVertexNC, "for a digraph with in-degrees and a vertex", +InstallMethod(InDegreeOfVertexNC, +"for a digraph with in-degrees and a positive integer", [IsDigraph and HasInDegrees, IsPosInt], 4, {D, v} -> InDegrees(D)[v]); InstallMethod(InDegreeOfVertexNC, -"for a digraph with in-neighbours and a vertex", +"for a digraph with in-neighbours and a positive integer", [IsDigraph and HasInNeighbours, IsPosInt], -2, # to beat the next method for IsDenseDigraphRep +2, # to beat the next method for IsDigraphByOutNeighboursRep {D, v} -> Length(InNeighbours(D)[v])); -InstallMethod(InDegreeOfVertexNC, "for a digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(InDegreeOfVertexNC, "for a digraph and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], function(D, v) local count, out, x, i; count := 0; @@ -787,7 +796,7 @@ function(D, v) return count; end); -InstallMethod(OutDegreeOfVertex, "for a digraph and a vertex", +InstallMethod(OutDegreeOfVertex, "for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) if not v in DigraphVertices(D) then @@ -798,17 +807,19 @@ function(D, v) end); InstallMethod(OutDegreeOfVertexNC, -"for a digraph with out-degrees and a vertex", +"for a digraph with out-degrees and a positive integer", [IsDigraph and HasOutDegrees, IsPosInt], -2, # to beat the next method for IsDenseDigraphRep +2, # to beat the next method for IsDigraphByOutNeighboursRep {D, v} -> OutDegrees(D)[v]); -InstallMethod(OutDegreeOfVertexNC, "for a dense digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(OutDegreeOfVertexNC, +"for a digraph by out-neighbours and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], {D, v} -> Length(OutNeighbours(D)[v])); -InstallMethod(DigraphOutEdges, "for a dense digraph and a vertex", -[IsDenseDigraphRep, IsPosInt], +InstallMethod(DigraphOutEdges, +"for a digraph by out-neighbours and a positive integer", +[IsDigraphByOutNeighboursRep, IsPosInt], function(D, v) if not v in DigraphVertices(D) then ErrorNoReturn("the 2nd argument is not a vertex of the ", @@ -817,7 +828,7 @@ function(D, v) return List(OutNeighboursOfVertex(D, v), x -> [v, x]); end); -InstallMethod(DigraphInEdges, "for a digraph and a vertex", +InstallMethod(DigraphInEdges, "for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) if not v in DigraphVertices(D) then @@ -831,8 +842,8 @@ end); # 7. Copies of out/in-neighbours ############################################################################# -InstallMethod(OutNeighboursMutableCopy, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(OutNeighboursMutableCopy, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], D -> List(OutNeighbours(D), ShallowCopy)); InstallMethod(InNeighboursMutableCopy, "for a digraph", [IsDigraph], @@ -857,8 +868,8 @@ function(D, edge) return IsDigraphEdge(D, edge[1], edge[2]); end); -InstallMethod(IsDigraphEdge, "for a dense digraph, int, int", -[IsDenseDigraphRep, IsInt, IsInt], +InstallMethod(IsDigraphEdge, "for a digraph by out-neighbours, int, int", +[IsDigraphByOutNeighboursRep, IsInt, IsInt], function(D, u, v) local n; @@ -874,8 +885,9 @@ function(D, u, v) return v in OutNeighboursOfVertex(D, u); end); -InstallMethod(IsSubdigraph, "for a dense digraph and dense digraph", -[IsDenseDigraphRep, IsDenseDigraphRep], +InstallMethod(IsSubdigraph, +"for two digraphs by out-neighbours", +[IsDigraphByOutNeighboursRep, IsDigraphByOutNeighboursRep], function(super, sub) local n, x, y, i, j; @@ -912,7 +924,7 @@ function(super, sub) return true; end); -InstallMethod(IsUndirectedSpanningForest, "for a digraph and a digraph", +InstallMethod(IsUndirectedSpanningForest, "for two digraphs", [IsDigraph, IsDigraph], function(super, sub) local sym, comps1, comps2; @@ -989,7 +1001,7 @@ function(D, edges) end); InstallMethod(IsMaximalMatching, "for a digraph and a list", -[IsDenseDigraphRep, IsHomogeneousList], +[IsDigraphByOutNeighboursRep, IsHomogeneousList], function(D, edges) local seen, nbs, i, j; @@ -1015,8 +1027,8 @@ end); ############################################################################# InstallMethod(DigraphFloydWarshall, -"for a dense digraph, function, object, and object", -[IsDenseDigraphRep, IsFunction, IsObject, IsObject], +"for a digraph by out-neighbours, function, object, and object", +[IsDigraphByOutNeighboursRep, IsFunction, IsObject, IsObject], function(D, func, nopath, edge) local vertices, n, mat, out, i, j, k; @@ -1049,7 +1061,8 @@ function(D, func, nopath, edge) return mat; end); -InstallMethod(DigraphStronglyConnectedComponent, "for a digraph and a vertex", +InstallMethod(DigraphStronglyConnectedComponent, +"for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) local scc; @@ -1064,7 +1077,7 @@ function(D, v) return scc.comps[scc.id[v]]; end); -InstallMethod(DigraphConnectedComponent, "for a digraph and a vertex", +InstallMethod(DigraphConnectedComponent, "for a digraph and a positive integer", [IsDigraph, IsPosInt], function(D, v) local wcc; @@ -1096,8 +1109,8 @@ function(D, u, v) return DigraphPath(D, u, v) <> fail; end); -InstallMethod(DigraphPath, "for a dense digraph and two pos ints", -[IsDenseDigraphRep, IsPosInt, IsPosInt], +InstallMethod(DigraphPath, "for a digraph by out-neighbours and two pos ints", +[IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, u, v) local verts; @@ -1119,8 +1132,9 @@ function(D, u, v) return DIGRAPH_PATH(OutNeighbours(D), u, v); end); -InstallMethod(DigraphShortestPath, "for a dense digraph and two pos ints", -[IsDenseDigraphRep, IsPosInt, IsPosInt], +InstallMethod(DigraphShortestPath, +"for a digraph by out-neighbours and two pos ints", +[IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, u, v) local current, next, parent, distance, falselist, verts, nbs, path, edge, n, a, b, i; @@ -1174,7 +1188,7 @@ function(D, u, v) Add(path[2], edge[b]); b := parent[b]; od; - Add(path[1], u); # Adds the starting vertex to the list of vertices. + Add(path[1], u); # Adds the starting vertex to the list of vertices return [Reversed(path[1]), Reversed(path[2])]; fi; od; @@ -1185,8 +1199,9 @@ function(D, u, v) return fail; end); -InstallMethod(IteratorOfPaths, "for a dense digraph and two pos ints", -[IsDenseDigraphRep, IsPosInt, IsPosInt], +InstallMethod(IteratorOfPaths, +"for a digraph by out-neighbours and two pos ints", +[IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, u, v) if not (u in DigraphVertices(D) and v in DigraphVertices(D)) then ErrorNoReturn("the 2nd and 3rd arguments and must be ", @@ -1325,7 +1340,7 @@ function(D, u, v) end); InstallMethod(DigraphLongestDistanceFromVertex, "for a digraph and a pos int", -[IsDenseDigraphRep, IsPosInt], +[IsDigraphByOutNeighboursRep, IsPosInt], function(D, v) local dist; @@ -1340,7 +1355,7 @@ function(D, v) return dist; end); -InstallMethod(DigraphLayers, "for a digraph, and a vertex", +InstallMethod(DigraphLayers, "for a digraph, and a positive integer", [IsDigraph, IsPosInt], function(D, v) local layers, gens, sch, trace, rep, word, orbs, layers_with_orbnums, @@ -1427,7 +1442,7 @@ function(D, vertex, distances) end); InstallMethod(DigraphShortestDistance, -"for a digraph, a vertex, and a vertex", +"for a digraph, a vertex, and a positive integer", [IsDigraph, IsPosInt, IsPosInt], function(D, u, v) local dist; @@ -1495,8 +1510,8 @@ end); ############################################################################# InstallMethod(PartialOrderDigraphJoinOfVertices, -"for a dense digraph and two positive integers", -[IsDenseDigraphRep, IsPosInt, IsPosInt], +"for a digraph by out-neighbours and two positive integers", +[IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, i, j) local x, nbs, intr; diff --git a/gap/orbits.gi b/gap/orbits.gi index 10b5d9ab1..c3bfe4867 100644 --- a/gap/orbits.gi +++ b/gap/orbits.gi @@ -68,8 +68,8 @@ function(G, domain) return rec(orbits := orbs, schreier := sch, lookup := lookup); end); -InstallMethod(RepresentativeOutNeighbours, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(RepresentativeOutNeighbours, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local reps, out, nbs, i; diff --git a/gap/prop.gi b/gap/prop.gi index 554a39494..f0012e8ad 100644 --- a/gap/prop.gi +++ b/gap/prop.gi @@ -9,7 +9,8 @@ ## # "multi" means it has at least one multiple edges -InstallMethod(IsMultiDigraph, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(IsMultiDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], IS_MULTI_DIGRAPH); InstallMethod(IsChainDigraph, "for a digraph", [IsDigraph], @@ -51,8 +52,8 @@ function(nbs) return true; end); -InstallMethod(IsJoinSemilatticeDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsJoinSemilatticeDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local topo; if not IsPartialOrderDigraph(D) then @@ -66,7 +67,7 @@ function(D) end); InstallMethod(IsMeetSemilatticeDigraph, "for a digraph", -[IsDenseDigraphRep], +[IsDigraphByOutNeighboursRep], function(D) local topo, list; if not IsPartialOrderDigraph(D) then @@ -79,8 +80,8 @@ function(D) return DIGRAPHS_IsMeetJoinSemilatticeDigraph(list); end); -InstallMethod(IsStronglyConnectedDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsStronglyConnectedDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], D -> IS_STRONGLY_CONNECTED_DIGRAPH(OutNeighbours(D))); InstallMethod(IsCompleteDigraph, "for a digraph", @@ -135,8 +136,8 @@ InstallImmediateMethod(IsAcyclicDigraph, "for a strongly connected digraph", IsStronglyConnectedDigraph, 0, D -> DigraphNrVertices(D) <= 1 and IsEmptyDigraph(D)); -InstallMethod(IsAcyclicDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsAcyclicDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n; n := DigraphNrVertices(D); @@ -159,8 +160,8 @@ end); # Complexity O(number of edges) # this could probably be improved further ! JDM -InstallMethod(IsSymmetricDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsSymmetricDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local out, inn, new, i; @@ -178,8 +179,8 @@ end); # Functional: for every vertex v there is exactly one edge with source v -InstallMethod(IsFunctionalDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsFunctionalDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], D -> ForAll(OutNeighbours(D), x -> Length(x) = 1)); InstallMethod(IsTournament, "for a digraph", [IsDigraph], @@ -248,11 +249,12 @@ D -> ForAny(DigraphVertices(D), x -> IsDigraphEdge(D, x, x))); InstallMethod(IsAperiodicDigraph, "for a digraph", [IsDigraph], D -> DigraphPeriod(D) = 1); -InstallMethod(IsAntisymmetricDigraph, "for a dense digraph", -[IsDenseDigraphRep], +InstallMethod(IsAntisymmetricDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], D -> IS_ANTISYMMETRIC_DIGRAPH(OutNeighbours(D))); -InstallMethod(IsTransitiveDigraph, "for a dense digraph", [IsDenseDigraphRep], +InstallMethod(IsTransitiveDigraph, "for a digraph by out-neighbours", +[IsDigraphByOutNeighboursRep], function(D) local n, m, sorted, verts, out, trans, reflex, v, u; diff --git a/tst/standard/cliques.tst b/tst/standard/cliques.tst index 29f77948b..845ceb2a0 100644 --- a/tst/standard/cliques.tst +++ b/tst/standard/cliques.tst @@ -226,9 +226,9 @@ Error, at least 1 argument is required, gap> DigraphClique(); Error, at least 1 argument is required, gap> DigraphMaximalClique(1); -Error, the 1st argument must be a dense digraph, +Error, the 1st argument must be a digraph by out-neighbours, gap> DigraphClique(1); -Error, the 1st argument must be a dense digraph, +Error, the 1st argument must be a digraph by out-neighbours, gap> DigraphMaximalClique(gr); [ 5, 4, 3, 2, 1 ] gap> DigraphClique(gr); diff --git a/tst/standard/digraph.tst b/tst/standard/digraph.tst index 7c67450c5..0e8c02c24 100644 --- a/tst/standard/digraph.tst +++ b/tst/standard/digraph.tst @@ -1084,7 +1084,7 @@ gap> G := DihedralGroup(8); gap> digraph := Digraph(AsSet(G), ReturnTrue); -gap> IsDenseDigraphRep(digraph); +gap> IsDigraphByOutNeighboursRep(digraph); true gap> digraph := Digraph("abcd", function(i, j) return i < j; end); @@ -1097,7 +1097,7 @@ gap> digraph := Digraph(["hello", "world", 13, true, (1, 4, 3)], gap> HasDigraphAdjacencyFunction(digraph); true -gap> IsDenseDigraphRep(digraph); +gap> IsDigraphByOutNeighboursRep(digraph); true # Digraphs with known automorphisms diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index 40fb19893..bc8976d62 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -864,14 +864,14 @@ gap> gr2 := CompleteDigraph(100); gap> DigraphDisjointUnion(gr) = gr; true gap> DigraphDisjointUnion([[]]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphDisjointUnion([gr], [gr]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphDisjointUnion(gr, Group(())); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphDisjointUnion(gr, gr); gap> DigraphDisjointUnion([gr2, gr2]); @@ -914,14 +914,14 @@ gap> gr2 := DigraphFromDiSparse6String(".H`OS?aEMC?bneOY`l_?QCJ"); gap> DigraphEdgeUnion(gr1) = gr1; true gap> DigraphEdgeUnion([[]]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphEdgeUnion([gr1], [gr1]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphEdgeUnion(gr1, Group(())); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> m1 := DigraphEdgeUnion(gr1, gr2); gap> m2 := DigraphEdgeUnion(gr2, gr1); @@ -961,14 +961,14 @@ gap> gr2 := EmptyDigraph(10); gap> DigraphJoin(gr) = gr; true gap> DigraphJoin([[]]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphJoin([gr], [gr]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphJoin([gr, Group(())]); -Error, the arguments must be dense digraphs, or a single list of dense digraph\ -s, +Error, the arguments must be digraphs by out-neighbours, or a single list of d\ +igraphs by out-neighbours, gap> DigraphJoin(gr, gr2); gap> DigraphJoin(gr, EmptyDigraph(0));