Remove trailing whitespaces
[re6stnet.git] / simulation / main.h
1 #include <iostream>
2 #include <vector>
3 #include <random>
4 #include <queue>
5 #include <set>
6 #include <unordered_set>
7
8 using namespace std;
9
10 template<class T>
11 struct nullable
12 {
13 T v;
14 bool null;
15
16 nullable() : null(false) { };
17 nullable(T t) : v(t), null(false) { };
18 };
19
20 class MinCutGraph
21 {
22 public:
23 vector<nullable<pair<int, int>>> edges;
24 vector<nullable<unordered_set<int>>> nodes;
25 MinCutGraph(vector<int>* adjacency, int n);
26 void Merge(int nMerge, mt19937& rng);
27 private:
28 void Check();
29 void RenumEdges();
30 void RenumNodes();
31 };
32
33
34 class Graph
35 {
36 public:
37 Graph(int size, int k, int maxPeers, mt19937& rng);
38 ~Graph() { delete[] adjacency; };
39
40 void GetDistancesFrom(int node, int* distance);
41 int GetMinCut();
42 int CountUnreachableFrom(int node);
43
44 void KillMachines(float proportion);
45 //void SplitAS(float proportionAS1, float proportionAS2);
46
47 vector<int>* adjacency;
48 int size;
49 private:
50 int GetMinCut(MinCutGraph& graph);
51
52 uniform_int_distribution<int> distrib;
53 mt19937& generator;
54 };
55
56 class Results
57 {
58 public:
59 Results(int maxArity, int maxDistance);
60 ~Results();
61
62 void UpdateArity(const Graph& graph);
63 void AddAccessibilitySample(double accessibility);
64 void UpdateDistance(int* distance, int nSamples);
65 void Finalise();
66
67 double* arityDistrib;
68 double* distanceDistrib;
69 double avgDistance;
70 double avgAccessibility;
71 int maxDistanceReached;
72 int minKConnexity;
73
74 double disconnectionProba;
75 double arityTooBig;
76 double distanceTooBig;
77 int64_t disconnected;
78
79 int maxArity;
80 int maxDistance;
81
82 private:
83 void AddAritySample(int arity);
84 void AddDistanceSample(int distance);
85
86 int64_t nAritySample;
87 int64_t nDistanceSample;
88 int64_t nAccessibilitySample;
89 };