Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/pkg/digraphs/tst/   (GAP Algebra Version 4.15.1©)  Datei vom 27.8.2025 mit Größe 18 kB image not shown  

Quelle  testinstall.tst   Sprache: unbekannt

 
Spracherkennung für: .tst vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

#############################################################################
##
#W  testinstall.tst
#Y  Copyright (C) 2014                                   James D. Mitchell
##
##  Licensing information can be found in the README file of this package.
##
#############################################################################
##

#@local C, D
#@local adj, comps, d, distances, edges, f, func, gr, gr1, gr2, i, id, out, p
#@local parents, r, str, topo
gap> START_TEST("Digraphs package: testinstall.tst");
gap> LoadPackage("digraphs", false);;

#
gap> DIGRAPHS_StartTest();

#  Conversion to and from GRAPE graphs
gap> gr := Digraph(
> [[8], [45689], [245710], [9],
> [14679], [236710], [34589],
> [34910], [12356910], [24569]]);
<immutable digraph with 10 vertices, 43 edges>
gap> OutNeighbours(gr);
[ [ 8 ], [ 45689 ], [ 245710 ], [ 9 ], [ 14679 ], 
  [ 236710 ], [ 34589 ], [ 34910 ], 
  [ 12356910 ], [ 24569 ] ]
gap> not DIGRAPHS_IsGrapeLoaded()
> or (DIGRAPHS_IsGrapeLoaded() and Digraph(Graph(gr)) = gr);
true
gap> not DIGRAPHS_IsGrapeLoaded()
> or (DIGRAPHS_IsGrapeLoaded() and Graph(Digraph(Graph(gr))).adjacencies =
>     Graph(gr).adjacencies);
true
gap> adj := [
> [1719], [1720], [1718], [1720], [1718], [1819],
> [1820], [1719], [1920], [1720], [1920], [1819],
> [1920], [1719], [1820], [1820],
> [1234581014], [3567121516],
> [168911121314], [24791011131516]];;
gap> func := function(x, y) return y in adj[x]; end;
function( x, y ) ... end
gap> not DIGRAPHS_IsGrapeLoaded() or
> (DIGRAPHS_IsGrapeLoaded() and
>  Digraph(Graph(Group(()), [1 .. 20], OnPoints, func, true)) = Digraph(adj));
true

#  IsAcyclicDigraph
gap> gr := Digraph([
>  [12410], [315], [315], [13789111213],
>  [48], [1245678101415], [346111315],
>  [3567891015], [256789101112],
>  [23101114], [351415], [79101415],
>  [1478101415], [1247131415],
>  [1239101112131415]]);
<immutable digraph with 15 vertices, 89 edges>
gap> IsMultiDigraph(gr);
false
gap> IsAcyclicDigraph(gr);
false
gap> r := rec(DigraphNrVertices := 10000,
>             DigraphSource := [],
>             DigraphRange := []);;
gap> for i in [1 .. 9999] do
>    Add(r.DigraphSource, i);
>    Add(r.DigraphRange, i + 1);
>  od;
gap> Add(r.DigraphSource, 10000);; Add(r.DigraphRange, 1);;
gap> gr := Digraph(r);
<immutable digraph with 10000 vertices, 10000 edges>
gap> IsAcyclicDigraph(gr);
false
gap> gr := DigraphRemoveEdge(gr, 100001);
<immutable digraph with 10000 vertices, 9999 edges>
gap> IsAcyclicDigraph(gr);
true
gap> gr := Digraph([[23], [45], [56], [], [], [], [3]]);
<immutable digraph with 7 vertices, 7 edges>
gap> IsDigraph(gr);
true

#  OutNeighbours
# Check that it can handle non-plists in the source and range
gap> gr := Digraph(rec(DigraphNrVertices := 1000,
>                      DigraphSource := [1 .. 1000],
>                      DigraphRange := Concatenation([2 .. 1000], [1])));;
gap> OutNeighbours(gr);;

#  IsMultiDigraph: for an empty digraph
gap> d := Digraph(rec(DigraphVertices := [1 .. 5], 
>                     DigraphRange := [], 
>                     DigraphSource := []));
<immutable empty digraph with 5 vertices>
gap> IsMultiDigraph(d);
false

#  DigraphFromSparse6String
gap> DigraphFromSparse6String(":Fa@x^");
<immutable symmetric digraph with 7 vertices, 8 edges>

#  (In/Out)Neighbours and (In/Out)NeighboursOfVertex and (In/Out)DegreeOfVertex
gap> gr := Digraph([[4], [22], [2314], [1]]);
<immutable multidigraph with 4 vertices, 8 edges>
gap> InDegreeOfVertex(gr, 2);
3
gap> InNeighboursOfVertex(gr, 2);
223 ]
gap> InNeighbours(gr);
[ [ 34 ], [ 223 ], [ 3 ], [ 13 ] ]
gap> gr := Digraph(rec(DigraphNrVertices := 10
>                      DigraphSource := [112333],
>                      DigraphRange := [311441]));
<immutable multidigraph with 10 vertices, 6 edges>
gap> InNeighboursOfVertex(gr, 5);
[  ]
gap> InDegreeOfVertex(gr, 5);
0
gap> InNeighbours(gr);
[ [ 123 ], [  ], [ 1 ], [ 33 ], [  ], [  ], [  ], [  ], [  ], [  ] ]
gap> InDegreeOfVertex(gr, 1);
3
gap> OutDegreeOfVertex(gr, 3);
3
gap> OutNeighboursOfVertex(gr, 3);
441 ]
gap> OutNeighbours(gr);
[ [ 31 ], [ 1 ], [ 441 ], [  ], [  ], [  ], [  ], [  ], [  ], [  ] ]

# DigraphInEdges and DigraphOutEdges for a vertex
gap> gr := Digraph([[5515], [], [], [231], [4]]);
<immutable multidigraph with 5 vertices, 8 edges>
gap> DigraphInEdges(gr, 5);
[ [ 15 ], [ 15 ], [ 15 ] ]
gap> DigraphOutEdges(gr, 2);
[  ]
gap> DigraphOutEdges(gr, 4);
[ [ 42 ], [ 43 ], [ 41 ] ]

#  DigraphPeriod and IsAperiodicDigraph
gap> gr := Digraph([[2], [3], [4], [5], [1], [7], [6]]);
<immutable digraph with 7 vertices, 7 edges>
gap> DigraphPeriod(gr);
1
gap> IsAperiodicDigraph(gr);
true
gap> gr := Digraph([[2], [3], [4], [5], [6], [1]]);
<immutable digraph with 6 vertices, 6 edges>
gap> DigraphPeriod(gr);
6
gap> IsAperiodicDigraph(gr);
false

#  IsDigraphEdge
gap> gr := Digraph(rec(DigraphNrVertices := 5
>                      DigraphSource := [12345],
>                      DigraphRange := [23451]));
<immutable digraph with 5 vertices, 5 edges>
gap> IsDigraphEdge(gr, [12]);
true
gap> IsDigraphEdge(gr, [22]);
false

#  DigraphReverseEdge and DigraphEdges

#
gap> gr := Digraph([[2], [35], [4], [5], [12]]);
<immutable digraph with 5 vertices, 7 edges>
gap> DigraphEdges(gr);
[ [ 12 ], [ 23 ], [ 25 ], [ 34 ], [ 45 ], [ 51 ], [ 52 ] ]
gap> gr2 := DigraphReverseEdge(gr, [23]);
<immutable digraph with 5 vertices, 7 edges>
gap> DigraphEdges(gr2);
[ [ 12 ], [ 25 ], [ 34 ], [ 32 ], [ 45 ], [ 51 ], [ 52 ] ]

#
gap> gr := Digraph([[123], [35], [4], [5], [12], [57], [6]]);
<immutable digraph with 7 vertices, 12 edges>
gap> gr2 := DigraphReverseEdge(gr, [11]);
<immutable digraph with 7 vertices, 12 edges>
gap> gr = gr2;
true
gap> gr2 := DigraphReverseEdge(gr, 12);
<immutable digraph with 7 vertices, 12 edges>

#  DigraphTopologicalSort
gap> gr := Digraph([[23], [3], [], [56], [6], []]);
<immutable digraph with 6 vertices, 6 edges>
gap> topo := DigraphTopologicalSort(gr);
321654 ]
gap> p := Permutation(Transformation(topo), topo);
(1,3)(4,6)
gap> gr1 := OnDigraphs(gr, p);;
gap> DigraphTopologicalSort(gr1) = DigraphVertices(gr1);
true
gap> gr := Digraph([[], [3], [], [5], [], [2371], [1], [2345]]);
<immutable digraph with 8 vertices, 11 edges>
gap> topo := DigraphTopologicalSort(gr);
13254768 ]
gap> p := Permutation(Transformation(topo), topo);
(2,3)(4,5)(6,7)
gap> gr1 := OnDigraphs(gr, p ^ -1);;
gap> DigraphTopologicalSort(gr1) = DigraphVertices(gr1);
true

#  DIGRAPH_IN_OUT_NBS: for a list containing ranges
# A segfault was caused by assuming that an element of OutNeighbours was a
# PLIST. This is solved by using PLAIN_LIST on each entry of OutNeighbours.
gap> gr := Digraph(List([1 .. 5], x -> [1 .. 5]));;
gap> out := OutNeighbours(gr);
[ [ 1 .. 5 ], [ 1 .. 5 ], [ 1 .. 5 ], [ 1 .. 5 ], [ 1 .. 5 ] ]
gap> IsMultiDigraph(gr);
false
gap> out;
[ [ 12345 ], [ 12345 ], [ 12345 ], [ 12345 ], 
  [ 12345 ] ]
gap> InNeighbours(gr) = out;
true

#  Issue 13: DigraphAllSimpleCircuits, reported by JDM
gap> gr := Digraph([[3], [4], [5], [15], [12]]);
<immutable digraph with 5 vertices, 7 edges>
gap> DigraphAllSimpleCircuits(gr);
[ [ 135 ], [ 13524 ], [ 524 ] ]

#  DigraphMaximalCliquesReps was returning too few results, since the choice
# of a pivot vertex was not necessarily valid when the stabilizer was
# non-trivial
gap> gr := DigraphFromGraph6String("L~~~ySrJ[N{NT^");
<immutable symmetric digraph with 13 vertices, 108 edges>
gap> gr = MaximalSymmetricSubdigraphWithoutLoops(gr);
true
gap> DigraphMaximalCliquesReps(gr);
[ [ 1234567 ], [ 12312 ], [ 281213 ], [ 4913 ], 
  [ 8910111213 ] ]
gap> gr := DigraphFromGraph6String("I~~wzfJhw");
<immutable symmetric digraph with 10 vertices, 66 edges>
gap> gr = MaximalSymmetricSubdigraphWithoutLoops(gr);
true
gap> DigraphMaximalCliquesReps(gr);
[ [ 123456 ], [ 1259 ], [ 1910 ], [ 78910 ] ]

#  DigraphClosure
gap> gr := CompleteDigraph(7);;
gap> gr2 := DigraphClosure(gr, 7);;
gap> gr = gr2;
true
gap> gr := DigraphRemoveEdge(gr, [12]);;
gap> gr := DigraphRemoveEdges(gr, [[12], [21]]);;
gap> DigraphNrEdges(gr);
40
gap> DigraphNrAdjacencies(gr);
20
gap> gr2 := DigraphClosure(gr, 7);;
gap> DigraphNrEdges(gr2);
42
gap> DigraphNrAdjacencies(gr2);
21

#  Fix seg fault cause by wrong handling of no edges in
# FuncDIGRAPH_SOURCE_RANGE
gap> gr := Digraph([[]]);
<immutable empty digraph with 1 vertex>
gap> DigraphSource(gr);
[  ]
gap> DigraphRange(gr);
[  ]

#  Issue 17: Bug in OnDigraphs for a digraph and a transformation
gap> d := Digraph([[2], [3], [11]]);
<immutable multidigraph with 3 vertices, 4 edges>
gap> OutNeighbours(OnDigraphs(d, PermList([231])));
[ [ 22 ], [ 3 ], [ 1 ] ]
gap> OutNeighbours(OnDigraphs(d, Transformation([231])));
[ [ 22 ], [ 3 ], [ 1 ] ]

#  Issue 42: Bug in AsDigraph for a transformation and an integer
gap> f := Transformation([7101017910423]);
Transformation( [ 7101017910423 ] )
gap> AsDigraph(f);
<immutable functional digraph with 10 vertices>
gap> AsDigraph(f, 4);
fail

# Issue 52: Bug in FuncIS_ANTISYMMETRIC_DIGRAPH causing seg fault
gap> gr := Digraph([[1], [2], [1 .. 3]]);;
gap> IsAntisymmetricDigraph(gr);
true

#  Issue 55: Bug in FuncDIGRAPH_TOPO_SORT
gap> gr := Digraph([[1 .. 4], [24], [34], [4]]);
<immutable digraph with 4 vertices, 9 edges>
gap> DigraphTopologicalSort(gr);
4231 ]

#  Issue 81: Bug in Digraph for a malformed list of out-neighbours
gap> gr := Digraph([[1],, [2]]);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `DigraphCons' on 2 arguments
gap> gr := Digraph([[1], 2, [2]]);
Error, the argument <list> must be a list of lists of positive integers not ex\
ceeding the length of the argument,

#  Symmetric closure of a digraph with no vertices
gap> gr := EmptyDigraph(0);;
gap> DigraphSymmetricClosure(gr);
<immutable empty digraph with 0 vertices>

# Issue 114: Bug in NautyTracesInterface for graphs with 0 vertices
gap> not DIGRAPHS_NautyAvailable or 
> NautyAutomorphismGroup(NullDigraph(0)) = Group(());
true
gap> not DIGRAPHS_NautyAvailable or 
> NautyAutomorphismGroup(NullDigraph(0), []) = Group(());
true
gap> not DIGRAPHS_NautyAvailable or 
> NautyCanonicalLabelling(NullDigraph(0)) = ();
true
gap> not DIGRAPHS_NautyAvailable or 
> NautyCanonicalLabelling(NullDigraph(0), []) = ();
true

# Issue 158: Digraph6 file format incompatibility (with nauty)
gap> SortedList(DigraphEdges(DigraphFromDigraph6String("&DI?AO?")) - 1);
[ [ 02 ], [ 04 ], [ 31 ], [ 34 ] ]
gap> str := "&O?????C??O?@??C??O?@??C??O?@??C??O?@??C??o??";;
gap> gr := DigraphFromDigraph6String(str);
<immutable digraph with 16 vertices, 15 edges>
gap> str = Digraph6String(gr);
true

# MakeImmutable
gap> D := NullDigraph(IsMutableDigraph, 10);
<mutable empty digraph with 10 vertices>
gap> MakeImmutable(D);
<immutable empty digraph with 10 vertices>

# Issue 272: ViewString for known non-complete digraphs
gap> D := Digraph([[2], []]);;
gap> IsCompleteDigraph(D);
false
gap> D;
<immutable digraph with 2 vertices, 1 edge>

# Issue 276: ViewString for mutable empty digraphs
gap> D := EmptyDigraph(IsMutableDigraph, 3);
<mutable empty digraph with 3 vertices>
gap> IsAcyclicDigraph(D);
true
gap> DigraphDisjointUnion(D, CycleDigraph(IsMutableDigraph, 3));
<mutable digraph with 6 vertices, 3 edges>
gap> IsAcyclicDigraph(D);
false
gap> D := EmptyDigraph(IsMutableDigraph, 3);
<mutable empty digraph with 3 vertices>
gap> IsAcyclicDigraph(D);
true
gap> DigraphDisjointUnion(D, CycleDigraph(IsImmutableDigraph, 3));
<mutable digraph with 6 vertices, 3 edges>
gap> IsAcyclicDigraph(D);
false

# Issue 276: Correct mutability for DigraphDisjointUnion
gap> D := EmptyDigraph(IsMutableDigraph, 3);
<mutable empty digraph with 3 vertices>
gap> DigraphDisjointUnion(D, CycleDigraph(3));
<mutable digraph with 6 vertices, 3 edges>
gap> IsMutable(D!.OutNeighbours);
true
gap> ForAll(D!.OutNeighbours, IsMutable);
true

# Issue 284: HomomorphismDigraphsFinder not finding any homomorphisms
gap> HomomorphismDigraphsFinder(NullDigraph(1), NullDigraph(100), fail, [], infinity,
> fail, 2, [1 .. 100], [], fail, fail);
[ IdentityTransformation ]
gap> HomomorphismDigraphsFinder(NullDigraph(1), NullDigraph(100), fail, [], infinity,
> fail, 2, [1 .. 100], [], fail, fail);
[ IdentityTransformation ]
gap> HomomorphismDigraphsFinder(NullDigraph(2), NullDigraph(2), fail, [], infinity,  
> fail, 2, [12], [], fail, fail); 
[ IdentityTransformation ]
gap> HomomorphismDigraphsFinder(NullDigraph(1), NullDigraph(100), fail, [], infinity,
> fail, 2, [1 .. 100], [], fail, fail);
[ IdentityTransformation ]

# Issue 367: bug in the homomorphisms finder c code
gap> D := Digraph([[22], []]);;
gap> GeneratorsOfEndomorphismMonoid(D);
Error, expected a digraph without multiple edges!
gap> D := Digraph([[22222], []]);;
gap> GeneratorsOfEndomorphismMonoid(D);
Error, expected a digraph without multiple edges!

# Issue 517: bug in String for digraphs satisfying IsChainDigraph or
# IsCycleDigraph but not being equal to ChainDigraph or CycleDigraph.
gap> D := ChainDigraph(4);
<immutable chain digraph with 4 vertices>
gap> D := DigraphReverse(D);
<immutable digraph with 4 vertices, 3 edges>
gap> IsChainDigraph(D);
true
gap> D = ChainDigraph(4);
false
gap> String(D);
"DigraphFromDigraph6String(\"&CACG\")"
gap> String(ChainDigraph(4));
"ChainDigraph(4)"
gap> D := CycleDigraph(4);
<immutable cycle digraph with 4 vertices>
gap> D := DigraphReverse(D);
<immutable digraph with 4 vertices, 4 edges>
gap> IsCycleDigraph(D);
true
gap> D = CycleDigraph(4);
false
gap> String(D);
"DigraphFromDigraph6String(\"&CECG\")"
gap> String(CycleDigraph(4));
"CycleDigraph(4)"

# Edge-weighted digraphs
gap> d := EdgeWeightedDigraph([[2], [1]], [[5], [10]]);
<immutable digraph with 2 vertices, 2 edges>
gap> EdgeWeights(d);
[ [ 5 ], [ 10 ] ]
gap> EdgeWeightedDigraphTotalWeight(d);
15
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
<immutable digraph with 2 vertices, 1 edge>
gap> d := EdgeWeightedDigraph([[2], [12]], [[5], [55]]);
<immutable digraph with 2 vertices, 3 edges>
gap> EdgeWeightedDigraphShortestPaths(d, 1);
rec( distances := [ 05 ], edges := [ fail, 1 ], parents := [ fail, 1 ] )
gap> EdgeWeightedDigraphShortestPaths(d);
rec( distances := [ [ 05 ], [ 50 ] ], 
  edges := [ [ fail, 1 ], [ 1, fail ] ], 
  parents := [ [ fail, 1 ], [ 2, fail ] ] )
gap> EdgeWeightedDigraphShortestPath(d, 12);
[ [ 12 ], [ 1 ] ]

# Is2EdgeTransitive
gap> Is2EdgeTransitive(DigraphByEdges([[12], [23], [31]]));
true

# Issue 617: bug in DigraphRemoveEdge, wasn't removing edge labels
gap> D := DigraphByEdges(IsMutableDigraph, [[12], [23], [34], [41], [11]]);;
gap> DigraphEdgeLabels(D);
[ [ 11 ], [ 1 ], [ 1 ], [ 1 ] ]
gap> DigraphRemoveEdge(D, [12]);;
gap> DigraphEdgeLabels(D);
[ [ 1 ], [ 1 ], [ 1 ], [ 1 ] ]
gap> D := DigraphByEdges(IsMutableDigraph, [[12], [23], [34], [41], [11]]);;
gap> SetDigraphEdgeLabel(D, 12, "test");
gap> DigraphRemoveEdge(D, 12);;
gap> DigraphEdgeLabels(D);
[ [ 1 ], [ 1 ], [ 1 ], [ 1 ] ]

# DigraphContractEdge
gap> D := DigraphByEdges(IsMutableDigraph, [[12], [21]]);
<mutable digraph with 2 vertices, 2 edges>
gap> DigraphContractEdge(D, 21);;
gap> DigraphEdges(D);
[  ]
gap> D := DigraphByEdges([[12], [21], [23]]);
<immutable digraph with 3 vertices, 3 edges>
gap> C := DigraphContractEdge(D, 21);
<immutable digraph with 2 vertices, 1 edge>
gap> DigraphEdges(C);
[ [ 21 ] ]

# Issue #704 SubdigraphsMonomorphisms bug
gap> d := Digraph([[2345], [134], [1245], [1235], 
> [134]]);;
gap> Length(SubdigraphsMonomorphisms(CompleteMultipartiteDigraph([23]), d));
4

# Issue #764 Disconnected CirculantGraphs are not Hamiltonian, etc
gap> D := CirculantGraph(12, [24]);
<immutable vertex-transitive symmetric digraph with 12 vertices, 48 edges>
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
false
gap> D := DigraphCopy(D);;
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
false
gap> IsVertexTransitive(D);
true
gap> D := CirculantGraph(4, [2]);
<immutable undirected forest with 4 vertices>
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
false
gap> D := CirculantGraph(6, [2]);
<immutable vertex-transitive symmetric digraph with 6 vertices, 12 edges>
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
false
gap> D := DigraphCopy(CirculantGraph(9, [3]));
<immutable digraph with 9 vertices, 18 edges>
gap> IsHamiltonianDigraph(D) or IsBiconnectedDigraph(D);
false

# Issue #818 IsConnectedDigraph for a digraph without vertices
gap> D := Digraph([]);;
gap> IsConnectedDigraph(D);
true
gap> D := Digraph([]);;
gap> DigraphConnectedComponents(D);
rec( comps := [  ], id := [  ] )
gap> IsConnectedDigraph(D);
true

# Issue #850: Problems with AutomorphismGroup for CompleteBipartiteDigraph
gap> D := CompleteBipartiteDigraph(15);
<immutable complete bipartite digraph with bicomponent sizes 1 and 5>
gap> AutomorphismGroup(D) = SymmetricGroup([2 .. 6]);
true
gap> not DIGRAPHS_IsGrapeLoaded() or
> (DIGRAPHS_IsGrapeLoaded() and
>  IsomorphismDigraphs(Digraph(Graph(D)), D) <> fail);
true
gap> not DIGRAPHS_IsGrapeLoaded() or
> (DIGRAPHS_IsGrapeLoaded() and
>  OnDigraphs(D, IsomorphismDigraphs(Digraph(Graph(D)), D)) = D);
true
gap> D := CompleteBipartiteDigraph(51);
<immutable complete bipartite digraph with bicomponent sizes 5 and 1>
gap> AutomorphismGroup(D) = SymmetricGroup([1 .. 5]);
true
gap> D := CompleteBipartiteDigraph(11);
<immutable complete digraph with 2 vertices>
gap> AutomorphismGroup(D) = Group([(12)]);
true
gap> D := CompleteBipartiteDigraph(33);
<immutable complete bipartite digraph with bicomponents of size 3>
gap> AutomorphismGroup(D)
> = Group([(123), (12), (456), (45), (14)(25)(36)]);
true

#
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: testinstall.tst", 0);

[Dauer der Verarbeitung: 0.15 Sekunden, vorverarbeitet 2026-06-23]