main.h 1.62 KB
Newer Older
1 2 3 4 5
#include <iostream>
#include <vector>
#include <random>
#include <queue>
#include <set>
6
#include <unordered_set>
7 8 9

using namespace std;

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
template<class T>
struct nullable
{ 
    T v;
    bool null;

    nullable() : null(false) { };
    nullable(T t) : v(t), null(false) { };
};

class MinCutGraph
{
public:
    vector<nullable<pair<int, int>>> edges;
    vector<nullable<unordered_set<int>>> nodes;
    MinCutGraph(vector<int>* adjacency, int n);
    void Merge(int nMerge, mt19937& rng);
private:
    void Check();
    void RenumEdges();
    void RenumNodes();
};


34 35 36
class Graph
{
public:
37
    Graph(int size, int k, int maxPeers, mt19937& rng);
38 39 40
    ~Graph() { delete[] adjacency; };

    void GetDistancesFrom(int node, int* distance);
41
    void KillMachines(float proportion);
42 43 44
    int GetMinCut();
    //void SplitAS(float proportionAS1, float proportionAS2);

45 46 47
    vector<int>* adjacency;
    int size;
private:
48 49
    int GetMinCut(MinCutGraph& graph);

50
    uniform_int_distribution<int> distrib;
51
    mt19937& generator;
52 53
};

54 55 56 57 58 59 60 61 62 63 64 65
class Results
{
public:
    Results(int maxArity, int maxDistance);
    ~Results();

    void UpdateArity(const Graph& graph);
    void UpdateDistance(int* distance, int nSamples);
    void Finalise();

    double* arityDistrib;
    double* distanceDistrib;
66 67
    double avgDistance;
    int maxDistanceReached;
68
    int minKConnexity;
69

70 71 72 73
    double disconnectionProba;
    double arityTooBig;
    double distanceTooBig;
    int64_t disconnected;
74
    
75 76 77 78 79 80
    int maxArity;
    int maxDistance;

private:
    void AddAritySample(int arity);
    void AddDistanceSample(int distance);
81

82 83
    int64_t nAritySample;
    int64_t nDistanceSample;
84
};