diff --git a/doc/digraph.xml b/doc/digraph.xml index 05e578e11..603f544e1 100644 --- a/doc/digraph.xml +++ b/doc/digraph.xml @@ -761,7 +761,7 @@ gap> List(D, Size); <#GAPDoc Label="RandomDigraph"> - + A digraph. &STANDARD_FILT_TEXT; @@ -788,12 +788,18 @@ gap> List(D, Size); For and , edges are added between any pairs of vertices with probability approximately p.

+ If the optional second argument rs is a random source (see ) then it + is used to generate the random choices made when creating the digraph. If rs is not specified, then the + global random source GlobalMersenneTwister is used. Two calls with the same arguments and random sources + in the same state return the same digraph, which makes it possible to reproduce a random digraph by resetting the + random source.

+ If n is a positive integer, then this function returns a random digraph with n vertices and without multiple edges. The result may or may not have loops. If using , the resulting graph will not have any loops by definition.

- If the optional second argument p is a float with value + If the optional fourth argument p is a float with value 0 \leq p \leq 1, then an edge will exist between each pair of vertices with probability approximately p. If p is not specified, then a random probability will be assumed @@ -803,6 +809,12 @@ gap> RandomDigraph(1000); gap> RandomDigraph(10000, 0.023); +gap> RandomDigraph(GlobalMersenneTwister, 1000); + +gap> RandomDigraph(IsMutableDigraph, GlobalMersenneTwister, 1000); + +gap> RandomDigraph(IsMutableDigraph, GlobalMersenneTwister, 1000, 0.5); + gap> RandomDigraph(IsMutableDigraph, 1000, 1 / 2); gap> RandomDigraph(IsConnectedDigraph, 1000, 0.75); diff --git a/gap/digraph.gd b/gap/digraph.gd index 46cb83d79..19d39733c 100644 --- a/gap/digraph.gd +++ b/gap/digraph.gd @@ -128,17 +128,32 @@ DeclareOperation("AsMonoid", [IsFunction, IsDigraph]); DeclareOperation("AsSemigroup", [IsFunction, IsDigraph, IsDenseList, IsDenseList]); -# 10. Random digraphs . . . +# 10. ``Random digraphs . . . +DeclareOperation("RandomDigraphOutNeighbours", [IsInt, IsFloat]); +DeclareOperation("RandomDigraphOutNeighbours", + [IsRandomSource, IsInt, IsFloat]); + DeclareConstructor("RandomDigraphCons", [IsDigraph, IsInt]); DeclareConstructor("RandomDigraphCons", [IsDigraph, IsInt, IsRat]); DeclareConstructor("RandomDigraphCons", [IsDigraph, IsInt, IsFloat]); +DeclareConstructor("RandomDigraphCons", [IsDigraph, IsRandomSource, IsInt]); +DeclareConstructor("RandomDigraphCons", + [IsDigraph, IsRandomSource, IsInt, IsRat]); +DeclareConstructor("RandomDigraphCons", + [IsDigraph, IsRandomSource, IsInt, IsFloat]); DeclareOperation("RandomDigraph", [IsInt]); DeclareOperation("RandomDigraph", [IsInt, IsRat]); DeclareOperation("RandomDigraph", [IsInt, IsFloat]); +DeclareOperation("RandomDigraph", [IsRandomSource, IsInt]); +DeclareOperation("RandomDigraph", [IsRandomSource, IsInt, IsRat]); +DeclareOperation("RandomDigraph", [IsRandomSource, IsInt, IsFloat]); DeclareOperation("RandomDigraph", [IsFunction, IsInt]); DeclareOperation("RandomDigraph", [IsFunction, IsInt, IsRat]); DeclareOperation("RandomDigraph", [IsFunction, IsInt, IsFloat]); +DeclareOperation("RandomDigraph", [IsFunction, IsRandomSource, IsInt]); +DeclareOperation("RandomDigraph", [IsFunction, IsRandomSource, IsInt, IsRat]); +DeclareOperation("RandomDigraph", [IsFunction, IsRandomSource, IsInt, IsFloat]); DeclareConstructor("RandomTournamentCons", [IsDigraph, IsInt]); DeclareOperation("RandomTournament", [IsInt]); diff --git a/gap/digraph.gi b/gap/digraph.gi index 337bfef4a..45f385115 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -1395,9 +1395,31 @@ end); ######################################################################## # 10. Random digraphs -######################################################################## +######################################################################### + +BindGlobal("DIGRAPHS_RandomOutNeighbours", function(rs, n, p) + local adj, i, j, q; + if p < 0.0 or p > 1.0 then + ErrorNoReturn("the 3rd argument

must be between 0 and 1"); + fi; + adj := List([1 .. n], i -> []); + for i in [1 .. n] do + for j in [1 .. n] do + q := Float(Random(rs, 0, 2 ^ 52 - 1 + n ^ 2)) / Float(2 ^ 52 + n ^ 2); + # We think adding n^2 will increase resolution for + # large digraphs + if q < p then + Add(adj[i], j); + fi; + od; + od; + return adj; +end); # Methods for probability unspecified or given as a rational +# Installing methods for RandomDigraphCons both with and +# without random source, since a lot of code relies on the +# version of it without a random source argument for filter in ["IsMutableDigraph", "IsImmutableDigraph", "IsHamiltonianDigraph", @@ -1406,31 +1428,57 @@ for filter in ["IsMutableDigraph", "IsStronglyConnectedDigraph", "IsAcyclicDigraph", "IsSymmetricDigraph"] do + + InstallMethod(RandomDigraphCons, + Concatenation("for ", filter, ", a random source, and an integer"), + [EvalString(filter), IsRandomSource, IsInt], + {f, rs, n} -> + RandomDigraphCons(f, rs, n, Float(Random(rs, 0, n ^ 2) / (n ^ 2)))); + + InstallMethod(RandomDigraphCons, + Concatenation("for ", filter, + ", a random source, an integer, and a rational"), + [EvalString(filter), IsRandomSource, IsInt, IsRat], + {f, rs, n, p} -> RandomDigraphCons(f, rs, n, Float(p))); + InstallMethod(RandomDigraphCons, Concatenation("for ", filter, " and an integer"), [EvalString(filter), IsInt], - {f, n} -> RandomDigraphCons(f, n, Float(Random(0, n ^ 2) / n ^ 2))); + {f, n} -> + RandomDigraphCons(f, n, Float(Random(0, n ^ 2) / (n ^ 2)))); InstallMethod(RandomDigraphCons, Concatenation("for ", filter, ", an integer, and a rational"), [EvalString(filter), IsInt, IsRat], {f, n, p} -> RandomDigraphCons(f, n, Float(p))); + od; InstallMethod(RandomDigraphCons, -"for IsMutableDigraph, a positive integer, and a float", -[IsMutableDigraph, IsPosInt, IsFloat], +"for IsMutableDigraph, a random source, an integer, and a float", +[IsMutableDigraph, IsRandomSource, IsInt, IsFloat], +function(_, rs, n, p) + if p < 0.0 or 1.0 < p then + ErrorNoReturn("the probability

must be between 0 and 1,"); + fi; + return DigraphNC(IsMutableDigraph, DIGRAPHS_RandomOutNeighbours(rs, n, p)); +end); + +InstallMethod(RandomDigraphCons, +"for IsMutableDigraph, an integer, and a float", +[IsMutableDigraph, IsInt, IsFloat], function(_, n, p) if p < 0.0 or 1.0 < p then - ErrorNoReturn("the 2nd argument

must be between 0 and 1,"); + ErrorNoReturn("the probability

must be between 0 and 1,"); fi; - return DigraphNC(IsMutableDigraph, RANDOM_DIGRAPH(n, p)); + return DigraphNC(IsMutableDigraph, + DIGRAPHS_RandomOutNeighbours(GlobalMersenneTwister, n, p)); end); # This function takes an existing adjacency list after solely creating # a Hamiltonian cycle or tree, and randomly adds edges between all # remaining vertices in the graph. -BindGlobal("DIGRAPHS_FillOutGraph", function(n, p, adjacencyList) +BindGlobal("DIGRAPHS_FillOutGraph", function(rs, n, p, adjacencyList) local vertices, probability, i, j; vertices := [1 .. n]; @@ -1439,7 +1487,7 @@ BindGlobal("DIGRAPHS_FillOutGraph", function(n, p, adjacencyList) for i in vertices do for j in vertices do if (not (j in adjacencyList[i])) then - if Float(Random(probability) / 100) < p then + if Float(Random(rs, probability) / 100) < p then Add(adjacencyList[i], j); fi; fi; @@ -1449,6 +1497,53 @@ BindGlobal("DIGRAPHS_FillOutGraph", function(n, p, adjacencyList) return adjacencyList; end); +InstallMethod(RandomDigraphCons, +"for IsHamiltonianDigraph, a random source, a positive integer, and a float", +[IsHamiltonianDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local adjacencyList, vertices, i, startVertex, hamiltonianCycle, x, j; + + adjacencyList := EmptyPlist(n); + + vertices := [1 .. n]; + + for i in vertices do + Add(adjacencyList, []); + od; + + # Edge Case + if n = 1 then + if Float(Random(rs, [0 .. 99]) / 100) < p then + Add(adjacencyList[1], 1); + fi; + return DigraphNC(adjacencyList); + fi; + + # Starting from a random vertex, we create a Hamiltonian cycle + startVertex := Remove(vertices, Random(rs, vertices)); + hamiltonianCycle := EmptyPlist(n); + hamiltonianCycle[1] := startVertex; + + # While there are remaining n-1 vertices to be added to the Hamiltonian + # cycle + for x in [1 .. n - 1] do + # Create a random edge from the last vertex in the cycle + # to a random vertex not in the cycle + i := hamiltonianCycle[x]; + j := Remove(vertices, Random(rs, [1 .. Length(vertices)])); + Add(hamiltonianCycle, j); + Add(adjacencyList[i], j); + od; + + Add(adjacencyList[hamiltonianCycle[n]], startVertex); + + # Once we have created a Hamiltonian cycle, fill out the rest of the graph + # with random edges according to p + adjacencyList := DIGRAPHS_FillOutGraph(rs, n, p, adjacencyList); + + return DigraphNC(adjacencyList); +end); + InstallMethod(RandomDigraphCons, "for IsHamiltonianDigraph, a positive integer, and a float", [IsHamiltonianDigraph, IsPosInt, IsFloat], @@ -1496,6 +1591,105 @@ function(_, n, p) return DigraphNC(adjacencyList); end); +InstallMethod(RandomDigraphCons, +"for IsEulerianDigraph, a random source, a positive integer, and a float", +[IsEulerianDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local adjacencyList, vertices, probability, startVertex, circuitVertex, i, + continueCircuit, verticesToConsider, connectedVertices, verticesToCheck; + + adjacencyList := EmptyPlist(n); + + vertices := [1 .. n]; + probability := [0 .. 99]; + + for i in vertices do + Add(adjacencyList, []); + od; + + # Edge Case + if n = 1 then + if Float(Random(rs, probability) / 100) < p then + Add(adjacencyList[1], 1); + fi; + return DigraphNC(adjacencyList); + fi; + + # Starting from a random vertex, we create an Eulerian circuit + startVertex := Random(rs, vertices); + circuitVertex := startVertex; + continueCircuit := true; + + # This will keep track of the vertices left to consider when deciding + # whether to extend the cycle. For example, if we want to extend from the + # current circuitVertex, we can check - verticesToConsider[circuitVertex] - + # to see which vertices it hasn't previously considered. + verticesToConsider := EmptyPlist(n); + for i in vertices do + Add(verticesToConsider, [1 .. n]); + od; + + # Eulerian graphs must be connected, so we store a list of connected + # vertices and check if a vertex isn't in the list + connectedVertices := [startVertex]; + + while continueCircuit do + while Length(verticesToConsider[circuitVertex]) > 0 do + # From the remaining vertices to check, select a random one to see + # if an edge will be added + i := Random(rs, verticesToConsider[circuitVertex]); + Remove(verticesToConsider[circuitVertex], + Position(verticesToConsider[circuitVertex], i)); + + # Check that the edge doesn't already exist + if (not (i in adjacencyList[circuitVertex])) then + # First we guarantee that we get a connected graph by checking + # if the vertex isn't already connected + if (not (i in connectedVertices)) then + Add(adjacencyList[circuitVertex], i); + Add(connectedVertices, i); + circuitVertex := i; + break; + elif Float(Random(rs, probability) / 100) < p then + Add(adjacencyList[circuitVertex], i); + circuitVertex := i; + break; + fi; + fi; + od; + + # If there are not more vertices to consider, we can end the circuit + if Length(verticesToConsider[circuitVertex]) = 0 then + continueCircuit := false; + fi; + od; + + # Finish the circuit by adding an edge back to the start vertex + # (if it isn't already at the start vertex) + if circuitVertex <> startVertex then + # If an edge already exists between the finish vertex and the start + # vertex, we must find another path to the start vertex to avoid + # generating a multidigraph. + while (startVertex in adjacencyList[circuitVertex]) do + # Here we consider all possible edges again, including previously + # rejected edges, to guarantee a path back to the start + verticesToCheck := [1 .. n]; + while Length(verticesToCheck) > 0 do + i := Remove(verticesToCheck, + Random(rs, [1 .. Length(verticesToCheck)])); + if (not (i in adjacencyList[circuitVertex])) then + Add(adjacencyList[circuitVertex], i); + circuitVertex := i; + break; + fi; + od; + od; + Add(adjacencyList[circuitVertex], startVertex); + fi; + + return DigraphNC(adjacencyList); +end); + InstallMethod(RandomDigraphCons, "for IsEulerianDigraph, a positive integer, and a float", [IsEulerianDigraph, IsPosInt, IsFloat], @@ -1595,6 +1789,41 @@ function(_, n, p) return DigraphNC(adjacencyList); end); +InstallMethod(RandomDigraphCons, +"for IsConnectedDigraph, a random source, a positive integer, and a float", +[IsConnectedDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local adjacencyList, vertices, startVertex, tree, x, i, j; + + adjacencyList := EmptyPlist(n); + + vertices := [1 .. n]; + + for i in vertices do + Add(adjacencyList, []); + od; + + # Starting from a random vertex, we first create a tree to guarantee + # connectivity + startVertex := Remove(vertices, Random(rs, vertices)); + tree := [startVertex]; + + # While there are n-1 remaining vertices to be added to the tree + for x in [1 .. n - 1] do + # Create an edge from a random vertex in the tree, to a random vertex + # outside of it + i := Random(rs, tree); + j := Remove(vertices, Random(rs, [1 .. Length(vertices)])); + Add(tree, j); + Add(adjacencyList[i], j); + od; + + # Once the tree has been created, we fill out the rest of the graph with + # random edges according to p + adjacencyList := DIGRAPHS_FillOutGraph(rs, n, p, adjacencyList); + return DigraphNC(adjacencyList); +end); + InstallMethod(RandomDigraphCons, "for IsConnectedDigraph, a positive integer, and a float", [IsConnectedDigraph, IsPosInt, IsFloat], @@ -1626,10 +1855,50 @@ function(_, n, p) # Once the tree has been created, we fill out the rest of the graph with # random edges according to p - adjacencyList := DIGRAPHS_FillOutGraph(n, p, adjacencyList); + adjacencyList := + DIGRAPHS_FillOutGraph(GlobalMersenneTwister, n, p, adjacencyList); return DigraphNC(adjacencyList); end); +InstallMethod(RandomDigraphCons, +Concatenation("for IsStronglyConnectedDigraph, a random source," +, "a positive integer, and a float"), +[IsStronglyConnectedDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local d, adjMatrix, stronglyConnectedComponents, + scc_a, scc_b, i, random_u, random_v; + + d := RandomDigraph(n, p); + + stronglyConnectedComponents := DigraphStronglyConnectedComponents(d); + + adjMatrix := AdjacencyMatrixMutableCopy(d); + + for i in [1 .. Size(stronglyConnectedComponents.comps) - 1] do + scc_a := stronglyConnectedComponents.comps[i]; + scc_b := stronglyConnectedComponents.comps[i + 1]; + + # add a connection from u to v + random_u := Random(rs, scc_a); + random_v := Random(rs, scc_b); + + adjMatrix[random_u][random_v] := 1; + od; + + # connect end scc to first scc + scc_a := stronglyConnectedComponents.comps[ + Size(stronglyConnectedComponents.comps)]; + scc_b := stronglyConnectedComponents.comps[1]; + + # add a connection from u to v + random_u := Random(rs, scc_a); + random_v := Random(rs, scc_b); + + adjMatrix[random_u][random_v] := 1; + + return DigraphByAdjacencyMatrix(adjMatrix); +end); + InstallMethod(RandomDigraphCons, "for IsStronglyConnectedDigraph, a positive integer, and a float", [IsStronglyConnectedDigraph, IsPosInt, IsFloat], @@ -1668,6 +1937,39 @@ function(_, n, p) return DigraphByAdjacencyMatrix(adjMatrix); end); +InstallMethod(RandomDigraphCons, +"for IsAcyclicDigraph, a random source, a positive integer, and a float", +[IsAcyclicDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local adjacencyList, vertices, probability, i, j; + + adjacencyList := EmptyPlist(n); + + vertices := [1 .. n]; + probability := [0 .. 99]; + + for i in vertices do + Add(adjacencyList, []); + od; + + # We shuffle the vertices and treat the order of the vertices as a + # hierarchy where all vertices to the right of a vertex in the list are + # potential edges. This idea is that the edges flow downwards in the + # hierarchy, avoiding cycles. + Shuffle(vertices); + + # From position i in the list, we consider all vertices j to the right of i + for i in vertices do + for j in [i + 1 .. n] do + if Float(Random(rs, probability) / 100) < p then + Add(adjacencyList[vertices[i]], vertices[j]); + fi; + od; + od; + + return DigraphNC(adjacencyList); +end); + InstallMethod(RandomDigraphCons, "for IsAcyclicDigraph, a positive integer, and a float", [IsAcyclicDigraph, IsPosInt, IsFloat], @@ -1701,6 +2003,39 @@ function(_, n, p) return DigraphNC(adjacencyList); end); +InstallMethod(RandomDigraphCons, +"for IsSymmetricDigraph, a random source, a positive integer, and a float", +[IsSymmetricDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local adjacencyList, vertices, probability, i, j; + + adjacencyList := EmptyPlist(n); + + vertices := [1 .. n]; + probability := [0 .. 99]; + + for i in vertices do + Add(adjacencyList, []); + od; + + for i in vertices do + for j in [i .. n] do + if Float(Random(rs, probability) / 100) < p then + # If it's a self-loop, only add one edge otherwise we would + # have a multi-edge. + if i = j then + Add(adjacencyList[i], j); + else + Add(adjacencyList[i], j); + Add(adjacencyList[j], i); + fi; + fi; + od; + od; + + return DigraphNC(adjacencyList); +end); + InstallMethod(RandomDigraphCons, "for IsSymmetricDigraph, a positive integer, and a float", [IsSymmetricDigraph, IsPosInt, IsFloat], @@ -1734,6 +2069,16 @@ function(_, n, p) return DigraphNC(adjacencyList); end); +InstallMethod(RandomDigraphCons, +"for IsImmutableDigraph, a random source, a positive integer, and a float", +[IsImmutableDigraph, IsRandomSource, IsPosInt, IsFloat], +function(_, rs, n, p) + local D; + D := MakeImmutable(RandomDigraphCons(IsMutableDigraph, rs, n, p)); + SetIsMultiDigraph(D, false); + return D; +end); + InstallMethod(RandomDigraphCons, "for IsImmutableDigraph, a positive integer, and a float", [IsImmutableDigraph, IsPosInt, IsFloat], @@ -1745,22 +2090,48 @@ function(_, n, p) end); InstallMethod(RandomDigraph, "for a pos int", [IsPosInt], -n -> RandomDigraphCons(IsImmutableDigraph, n)); +n -> RandomDigraphCons(IsImmutableDigraph, GlobalMersenneTwister, n)); InstallMethod(RandomDigraph, "for a pos int and a rational", [IsPosInt, IsRat], -{n, p} -> RandomDigraphCons(IsImmutableDigraph, n, p)); +{n, p} -> +RandomDigraphCons(IsImmutableDigraph, GlobalMersenneTwister, n, Float(p))); InstallMethod(RandomDigraph, "for a pos int and a float", [IsPosInt, IsFloat], -{n, p} -> RandomDigraphCons(IsImmutableDigraph, n, p)); +{n, p} -> RandomDigraphCons(IsImmutableDigraph, GlobalMersenneTwister, n, p)); + +InstallMethod(RandomDigraph, "for a random source and a pos int", +[IsRandomSource, IsPosInt], +{rs, n} -> RandomDigraphCons(IsImmutableDigraph, rs, n)); + +InstallMethod(RandomDigraph, "for a random source, a pos int and a rational", +[IsRandomSource, IsPosInt, IsRat], +{rs, n, p} -> RandomDigraphCons(IsImmutableDigraph, rs, n, p)); + +InstallMethod(RandomDigraph, "for a random source, a pos int and a float", +[IsRandomSource, IsPosInt, IsFloat], +{rs, n, p} -> RandomDigraphCons(IsImmutableDigraph, rs, n, p)); InstallMethod(RandomDigraph, "for a func and a pos int", [IsFunction, IsPosInt], -RandomDigraphCons); +{f, n} -> RandomDigraphCons(f, GlobalMersenneTwister, n)); InstallMethod(RandomDigraph, "for a func, a pos int, and a rational", -[IsFunction, IsPosInt, IsRat], RandomDigraphCons); +[IsFunction, IsPosInt, IsRat], +{f, n, p} -> RandomDigraphCons(f, GlobalMersenneTwister, n, Float(p))); InstallMethod(RandomDigraph, "for a func, a pos int, and a float", -[IsFunction, IsPosInt, IsFloat], RandomDigraphCons); +[IsFunction, IsPosInt, IsFloat], +{f, n, p} -> RandomDigraphCons(f, GlobalMersenneTwister, n, p)); + +InstallMethod(RandomDigraph, "for a func, a random source, a pos int", +[IsFunction, IsRandomSource, IsPosInt], RandomDigraphCons); + +InstallMethod(RandomDigraph, +"for a func, a random source, a pos int and a rational", +[IsFunction, IsRandomSource, IsPosInt, IsRat], RandomDigraphCons); + +InstallMethod(RandomDigraph, +"for a func, a random source, a pos int and a float", +[IsFunction, IsRandomSource, IsPosInt, IsFloat], RandomDigraphCons); InstallMethod(RandomMultiDigraph, "for a pos int", [IsPosInt], n -> RandomMultiDigraph(n, Random([1 .. (n * (n - 1)) / 2]))); diff --git a/tst/standard/digraph.tst b/tst/standard/digraph.tst index 4c458f29e..7c8199067 100644 --- a/tst/standard/digraph.tst +++ b/tst/standard/digraph.tst @@ -583,9 +583,9 @@ Error, no 1st choice method found for `RandomDigraph' on 1 arguments gap> RandomDigraph(4, 0); gap> RandomDigraph(10, 1.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(10, -0.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(10, 1 / 10);; # RandomDigraph(IsImmutableDigraph, ...) @@ -606,9 +606,9 @@ Error, no 1st choice method found for `RandomDigraph' on 2 arguments gap> RandomDigraph(IsImmutableDigraph, 4, 0); gap> RandomDigraph(IsImmutableDigraph, 10, 1.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(IsImmutableDigraph, 10, -0.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(IsImmutableDigraph, 10, 1 / 10);; # RandomDigraph(IsMutableDigraph, ...) @@ -629,9 +629,9 @@ Error, no 1st choice method found for `RandomDigraph' on 2 arguments gap> RandomDigraph(IsMutableDigraph, 4, 0); gap> RandomDigraph(IsMutableDigraph, 10, 1.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(IsMutableDigraph, 10, -0.01); -Error, the 2nd argument

must be between 0 and 1, +Error, the probability

must be between 0 and 1, gap> RandomDigraph(IsMutableDigraph, 10, 1 / 10);; # RandomMultiDigraph @@ -2063,6 +2063,10 @@ gap> graph := RandomDigraph(IsAcyclicDigraph, 10);; > fi; # Random Eulerian Digraph +gap> graph := RandomDigraph(IsEulerianDigraph, 10);; +> if not IsEulerianDigraph(graph) then +> Print("False"); +> fi; gap> graph := RandomDigraph(IsEulerianDigraph, 1, 0);; > if DigraphNrEdges(graph) <> 0 then > Print("False"); @@ -2083,11 +2087,65 @@ gap> for p in [1 .. 9] do > Print("False"); > fi; > od; -gap> graph := RandomDigraph(IsEulerianDigraph, 10);; -> if not IsEulerianDigraph(graph) then -> Print("False"); -> fi; + +#Random Digraph with Random Source +gap> graph := RandomDigraph(IsMutableDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsMutableDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsImmutableDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsImmutableDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsHamiltonianDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsHamiltonianDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsEulerianDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsEulerianDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsConnectedDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsConnectedDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsStronglyConnectedDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsStronglyConnectedDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsAcyclicDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsAcyclicDigraph(graph) then +> Print("False"); +> fi; +gap> graph := RandomDigraph(IsSymmetricDigraph, GlobalMersenneTwister, 10, 0.5);; +> if not IsSymmetricDigraph(graph) then +> Print("False"); +> fi; +gap> Reset(GlobalMersenneTwister);; +gap> graph := RandomDigraph(GlobalMersenneTwister, 10, 0.5); + +gap> Reset(GlobalMersenneTwister);; +gap> graph2 := RandomDigraph(GlobalMersenneTwister, 10, 0.5); + +gap> graph = graph2; +true +gap> Reset(GlobalMersenneTwister);; +gap> graph := RandomDigraph(IsAcyclicDigraph, 10, 0.3); + +gap> Reset(GlobalMersenneTwister);; +gap> graph2 := RandomDigraph(IsAcyclicDigraph, 10, 0.3); + +gap> graph = graph2; +true +gap> Reset(GlobalMersenneTwister);; +gap> graph := RandomDigraph(IsHamiltonianDigraph, 10); + +gap> Reset(GlobalMersenneTwister);; +gap> graph2 := RandomDigraph(IsHamiltonianDigraph, 10); + +gap> graph = graph2; +true # gap> DIGRAPHS_StopTest(); -gap> STOP_TEST("Digraphs package: standard/digraph.tst", 0); +gap> STOP_TEST("Digraphs package: standard/digraph.tst", 0); \ No newline at end of file