Skip to content

Commit

Permalink
digraph: allow rationals as 2nd arg of RandomDigraph
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell committed Jan 31, 2019
1 parent 4443b58 commit 403c5f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions gap/digraph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ DeclareOperation("AsDigraph", [IsTransformation, IsInt]);
DeclareOperation("DigraphCopy", [IsDigraph]);

DeclareOperation("RandomDigraph", [IsPosInt]);
DeclareOperation("RandomDigraph", [IsPosInt, IsRat]);
DeclareOperation("RandomDigraph", [IsPosInt, IsFloat]);
DeclareOperation("RandomMultiDigraph", [IsPosInt]);
DeclareOperation("RandomMultiDigraph", [IsPosInt, IsPosInt]);
Expand Down
8 changes: 7 additions & 1 deletion gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,20 @@ function(n)
return RandomDigraph(n, Float(Random([0 .. 10000])) / 10000);
end);

InstallMethod(RandomDigraph, "for a pos int and a rational",
[IsPosInt, IsRat],
function(n, p)
return RandomDigraph(n, Float(p));
end);

InstallMethod(RandomDigraph, "for a pos int and a float",
[IsPosInt, IsFloat],
function(n, p)
local out;

if p < 0.0 or 1.0 < p then
ErrorNoReturn("Digraphs: RandomDigraph: usage,\n",
"the second argument <p> must be a float between 0 and 1,");
"the second argument <p> must be between 0 and 1,");
fi;
out := DigraphNC(RANDOM_DIGRAPH(n, Int(p * 10000)));
SetIsMultiDigraph(out, false);
Expand Down
8 changes: 4 additions & 4 deletions tst/standard/digraph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -611,14 +611,14 @@ gap> RandomDigraph("a");
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `RandomDigraph' on 1 arguments
gap> RandomDigraph(4, 0);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `RandomDigraph' on 2 arguments
<digraph with 4 vertices, 0 edges>
gap> RandomDigraph(10, 1.01);
Error, Digraphs: RandomDigraph: usage,
the second argument <p> must be a float between 0 and 1,
the second argument <p> must be between 0 and 1,
gap> RandomDigraph(10, -0.01);
Error, Digraphs: RandomDigraph: usage,
the second argument <p> must be a float between 0 and 1,
the second argument <p> must be between 0 and 1,
gap> RandomDigraph(10, 1 / 10);;
# RandomMultiDigraph
gap> DigraphNrVertices(RandomMultiDigraph(100));
Expand Down

0 comments on commit 403c5f2

Please sign in to comment.