-
Notifications
You must be signed in to change notification settings - Fork 0
/
expected_cycles.cpp
59 lines (43 loc) · 903 Bytes
/
expected_cycles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <cmath>
// computes the expected number of cycles in a random graph G_p
using namespace std;
typedef long long ll;
double p;
ll fact(int n) {
return n == 0 ? 1 : n*fact(n-1);
}
// computes fallfact(n/k) p^k
double gross(int n, int k) {
double val = 0;
for (int i=0; i<k; ++i) {
val += log((n-i)*p);
//cout << val << endl;
}
// cout << k << " " << val << endl;
return exp(val);
}
double cliques(int n, int k) {
double val = 0;
for (int i=0; i<k; ++i) {
val += log(n-i) - log(i+1);
}
val += log(p) * k*(k-1)/2;
return exp(val);
}
int main(int argc, char* argv[]) {
p = 1;
if (argc > 1) {
p = atof(argv[1]);
}
int n = 10000;
double cyc = 0;
for (int k=3; k<n; k+=2) {
cyc += gross(n,k) / (2*k);
}
// cout << cyc << endl;
for (int k=n; k>0; --k) {
if (cliques(n, k) > 0) cout << k << " " << cliques(n, k) << endl;
}
return 0;
}