Skip to content

Commit

Permalink
Add RandomLattice method
Browse files Browse the repository at this point in the history
  • Loading branch information
reiniscirpons committed Apr 17, 2019
1 parent 836efb0 commit 2147941
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
12 changes: 12 additions & 0 deletions doc/digraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,18 @@ gap> RandomTournament(10);
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="RandomLattice">
<ManSection>
<Oper Name="RandomLattice" Arg="n"/>
<Returns>A digraph.</Returns>
<Description>
If <A>n</A> is a positive integer, this function return a random lattice
with <A>m</A> vertices, where it is guaranteed that <A>m</A> is between
<A>n</A> and <C>2 * <A>n</A></C>. See <Ref Prop="IsLatticeDigraph"/>. <P/>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="ChainDigraph">
<ManSection>
<Oper Name="ChainDigraph" Arg="n"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<#Include Label="RandomDigraph">
<#Include Label="RandomMultiDigraph">
<#Include Label="RandomTournament">
<#Include Label="RandomLattice">
</Section>

<Section><Heading>Standard examples</Heading>
Expand Down
2 changes: 2 additions & 0 deletions gap/digraph.gd
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ DeclareConstructor("RandomTournamentCons", [IsDigraph, IsInt]);
DeclareOperation("RandomTournament", [IsInt]);
DeclareOperation("RandomTournament", [IsFunction, IsInt]);

DeclareOperation("RandomLattice", [IsPosInt]);

# No mutable analogues of the following because we will withdraw multidigraphs
# the not too distant future!
DeclareOperation("RandomMultiDigraph", [IsPosInt]);
Expand Down
15 changes: 15 additions & 0 deletions gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1104,3 +1104,18 @@ InstallMethod(RandomTournament, "for a func and an integer",
function(func, n)
return RandomTournamentCons(func, n);
end);

InstallMethod(RandomLattice, "for a pos int",
[IsPosInt],
function(n)
local fam, rand_blist;

fam := [BlistList([1 .. n], [])];

while Length(fam) < n do
rand_blist := List([1 .. n], x -> Random([true, false]));
UniteSet(fam, List(fam, x -> UnionBlist(x, rand_blist)));
od;

return Digraph(fam, IsSubsetBlist);
end);
93 changes: 93 additions & 0 deletions tst/standard/digraph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,99 @@ Error, the argument <n> must be a non-negative integer,
gap> RandomTournament(IsMutableDigraph, 10);
<mutable digraph with 10 vertices, 45 edges>

# RandomLattice
gap> RandomLattice(25);;
gap> RandomLattice(1);
<digraph with 1 vertex, 1 edge>
gap> RandomLattice(-1);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `RandomLattice' on 1 arguments
# The list of random lattice Digraph6Strings D was generated by running the following command
# D := List([1 .. 100], x -> Digraph6String(RandomLattice(7)));
gap> D := [
> "&F~grwcIB?_", "&G~tSrCO{D?oC", "&F~kqG{IB?_", "&J~}jSpw`O~_t?a?{?g?o?_", "&H~zzIWxAGH?wB?G",
> "&G~t[~DosD?oC", "&F~kqG{IB?_", "&H~z~IgrAGN?gB?G", "&I~|TR~DSKoP?{@OB?C", "&G~s[jFOcD?oC",
> "&G~sc~EocF?oC", "&G~tSrCO{D?oC", "&F~kqG{IB?_", "&F~kqG{IB?_", "&I~|nqTFKKoP?{@OB?C",
> "&I~|OrPCCNoP?{@OB?C", "&F~kqG{IB?_", "&G~tSrCO{D?oC", "&H~ynMWbAWN?gB?G", "&G~tSrCO{D?oC",
> "&I~|Sr~DKLOP?{@OB?C", "&F~hrgcIB?_", "&G~s[rCOsD?oC", "&G~tCtCO{D?oC", "&F~lQG{IB?_",
> "&F~hrgcIB?_", "&I~|DRrDKGOP?{@OB?C", "&F~jRWcIB?_", "&G~tSpCO{D?oC", "&F~mrGcMB?_",
> "&F~iRwcMB?_", "&F~lQG{IB?_", "&F~lQG{IB?_", "&H~yhKw`BwH?wB?G", "&I~|zqdEKGO^?{@OB?C",
> "&G~tSrCO{D?oC", "&G~tSrCO{D?oC", "&G~tSrCO{D?oC", "&F~kqG{IB?_", "&F~lQG{IB?_", "&G~skxCOcF?oC",
> "&J~}dCggoo__~?a?{?g?o?_", "&F~lQG{IB?_", "&G~usdEocD?oC", "&G~tSrCO{D?oC", "&H~ybLG`BWH?wB?G",
> "&F~irgcIB?_", "&I~|TRBCCNoT?{@OB?C", "&F~iqwcMB?_", "&H~yTHgxAGH?gB?G", "&F~nqg{IB?_",
> "&I~|PRRCCNoR?{@OB?C", "&F~lqWcMB?_", "&J~}lKhgoo__~?e?s?g?o?_", "&F~nqW{IB?_", "&G~tSrCO{D?oC",
> "&F~jrWkMB?_", "&G~vKpCO{D?oC", "&F~irgcIB?_", "&H~y~LwnAWN?gB?G", "&F~kqG{IB?_",
> "&I~|zqdEKGO^?{@OB?C", "&G~t{`EocF?oC", "&H~zNGW~AGN?wB?G", "&H~zNGW~AgN?gB?G", "&F~nQgsIB?_",
> "&F~hrwkMB?_", "&G~vkbEocF?oC", "&G~s{zCOkF?oC", "&F~grwkMB?_", "&G~tKtCO{D?oC", "&F~nqwsIB?_",
> "&J~}jKpw_o~_r?a?{?g?o?_", "&F~nqg{IB?_", "&G~s{~DO{D?oC", "&G~tSrCO{D?oC",
> "&K~~\\tGdCTBr@p?`?P?N?D?B?@", "&G~tSrCO{D?oC", "&H~zjKW`BwJ?gB?G", "&K~~PrG^FnAd@b?`?R?N?D?B?@",
> "&H~ydKW`AWN?gB?G", "&F~lQG{IB?_", "&G~tSrCO{D?oC", "&H~zNGg~AGN?gB?G", "&G~u[bFocF?oC",
> "&H~yrMwrAGN?wB?G", "&G~t{zEocF?oC", "&H~yhJw`BWH?wB?G", "&G~uk`FokF?oC", "&F~lqGcMB?_",
> "&F~kqG{IB?_", "&G~sC~EocF?oC", "&F~lQG{IB?_", "&G~s[~EocF?oC", "&G~tKpCO{D?oC", "&F~jrGcMB?_",
> "&I~|SrNCKNoR?{@OB?C", "&F~lQG{IB?_", "&F~irgcIB?_", "&F~kqG{IB?_"];;
gap> D := List(D, x -> DigraphFromDigraph6String(x));;
gap> iso := [];;
gap> iso_distr := [];;
gap> eq := [];;
gap> eq_distr := [];;
gap> for i in [1 .. Length(D)] do
> iso_new := true;
> eq_new := true;
> for j in [1 .. Length(iso)] do
> if IsIsomorphicDigraph(D[i], iso[j]) then
> iso_distr[j] := iso_distr[j] + 1;
> iso_new := false;
> break;
> fi;
> od;
> for j in [1 .. Length(eq)] do
> if D[i] = eq[j] then
> eq_distr[j] := eq_distr[j] + 1;
> eq_new := false;
> break;
> fi;
> od;
> if iso_new then
> Add(iso, D[i]);
> Add(iso_distr, 1);
> fi;
> if eq_new then
> Add(eq, D[i]);
> Add(eq_distr, 1);
> fi;
> od;
# The total number of nonisomorphic digraphs generated, out of 100.
# It is known that there are 53 distinct lattices on 7 points according to OEIS A006966
gap> Length(iso);
41
# The distribution of nonisomorhpic generated lattices.
# To the left is the number of times a particular lattice occurs among the randomly generated ones.
# To the right is how many distinct lattices have
# this number of occurences.
# So entry [3, 5] means that there were five distinct lattices each of which was generated 3 times.
gap> Display(Collected(iso_distr));
[ [ 1, 26 ],
[ 2, 7 ],
[ 3, 3 ],
[ 4, 1 ],
[ 5, 2 ],
[ 14, 1 ],
[ 23, 1 ] ]
# Same as above but for non-equal lattices
gap> Length(eq);
69
gap> Display(Collected(eq_distr));
[ [ 1, 62 ],
[ 2, 3 ],
[ 3, 1 ],
[ 8, 1 ],
[ 9, 1 ],
[ 12, 1 ] ]
# Equals (\=) for two digraphs
gap> r1 := rec(DigraphNrVertices := 2, DigraphSource := [1, 1, 2], DigraphRange := [1, 2, 2]);;
gap> r2 := rec(DigraphNrVertices := 2, DigraphSource := [1, 1, 2], DigraphRange := [2, 1, 2]);;
Expand Down

0 comments on commit 2147941

Please sign in to comment.