results.cpp 1.97 KB
Newer Older
1 2
#include "main.h"

3
Results::Results(int maxArity, int maxDistance) :
4 5 6 7 8 9 10 11 12 13
    maxArity(maxArity), maxDistance(maxDistance)
{
    arityDistrib = new double[maxArity+1];
    for(int i=0; i<=maxArity; i++)
        arityDistrib[i] = 0;

    distanceDistrib = new double[maxDistance+1];
    for(int i=0; i<=maxDistance; i++)
        distanceDistrib[i] = 0;

14
    nAccessibilitySample = 0;
15 16
    nAritySample = 0;
    nDistanceSample = 0;
17
    avgAccessibility = 0;
18 19 20
    arityTooBig = 0;
    distanceTooBig = 0;
    disconnected = 0;
21
    avgDistance = 0;
22
    minKConnexity = -1;
23
    maxDistanceReached = -1;
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
}

Results::~Results()
{
    delete[] arityDistrib;
    delete[] distanceDistrib;
}

void Results::UpdateArity(const Graph& graph)
{
    for(int i=0; i<graph.size; i++)
        AddAritySample(graph.adjacency[i].size());
}

void Results::UpdateDistance(int* distance, int nSamples)
{
    for(int i=0; i<nSamples; i++)
        AddDistanceSample(distance[i]);
}

void Results::AddAritySample(int arity)
{
    if(arity <= maxArity)
        arityDistrib[arity]++;
    else
        distanceTooBig++;
    nAritySample++;
}

void Results::AddDistanceSample(int distance)
{
    if(distance == -1)
        disconnected++;
57
    else
58 59 60 61 62 63 64
    {
        avgDistance += distance;
        if(distance <= maxDistance)
            distanceDistrib[distance]++;
        else
            distanceTooBig++;
    }
65
    nDistanceSample++;
66
    maxDistanceReached = max(maxDistanceReached, distance);
67 68
}

69 70 71 72 73 74
void Results::AddAccessibilitySample(double accessibility)
{
    avgAccessibility += accessibility;
    nAccessibilitySample++;
}

75 76 77 78 79 80 81 82 83
void Results::Finalise()
{
    for(int i=0; i<=maxArity; i++)
        arityDistrib[i] /= nAritySample;
    for(int i=0; i<=maxDistance; i++)
        distanceDistrib[i] /= nDistanceSample;
    disconnectionProba = ((double)disconnected)/nDistanceSample;
    distanceTooBig/= nDistanceSample;
    arityTooBig /= nAritySample;
84
    avgDistance /= nDistanceSample - disconnected;
85
    avgAccessibility /= nAccessibilitySample;
86
}