Skip to content

Commit 467459c

Browse files
Added code for Erdos-Renyi complexity/star complexity experiment.
1 parent db14c23 commit 467459c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

models/starComplexity.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,3 +625,24 @@ unsigned StarComplexityGen::starUpperBound(const linkRep& x) const
625625
assert(ub>0 && complementUb>0);
626626
return min(ub, complementUb);
627627
}
628+
629+
GraphComplexity StarComplexityGen::randomERGraph(unsigned nodes, unsigned links)
630+
{
631+
linkRep g=0;
632+
if (links>nodes*(nodes-1)/2)
633+
throw runtime_error("links requested exceeds maximum possible: "+to_string(nodes*(nodes-1)/2));
634+
for (unsigned l=0; l<links; ++l)
635+
{
636+
unsigned node1=nodes*uni.rand(), node2;
637+
do
638+
node2=nodes*uni.rand();
639+
while (node1==node2);
640+
g|=edge(node1,node2);
641+
}
642+
643+
GraphComplexity r;
644+
r.starComplexity=::starUpperBound(g,nodes);
645+
NautyRep ng=toNautyRep(g, nodes);
646+
r.complexity=ecolab::complexity(ng, true);
647+
return r;
648+
}

models/starComplexity.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// hard code maximum number of nodes
2-
constexpr unsigned maxNodes=22, maxStars=2*maxNodes-1;
2+
constexpr unsigned maxNodes=1000, maxStars=2*maxNodes-1;
33

44
#include "netcomplexity.h"
55

@@ -156,5 +156,11 @@ struct StarComplexityGen
156156

157157
/// return an upper bound on the number of stars in the link representation
158158
unsigned starUpperBound(const linkRep&) const;
159+
160+
/// random number generator
161+
ecolab::urand uni;
162+
163+
/// randomly generate an ER graph, and return the starUpperBound and complexity
164+
GraphComplexity randomERGraph(unsigned nodes, unsigned links);
159165
};
160166

0 commit comments

Comments
 (0)