wip
[re6stnet.git] / simulation / results.cpp
1 #include "main.h"
2
3 Results::Results(int maxArity, int maxDistance) :
4 maxArity(maxArity), maxDistance(maxDistance)
5 {
6 arityDistrib = new double[maxArity+1];
7 for(int i=0; i<=maxArity; i++)
8 arityDistrib[i] = 0;
9
10 distanceDistrib = new double[maxDistance+1];
11 for(int i=0; i<=maxDistance; i++)
12 distanceDistrib[i] = 0;
13
14 nAccessibilitySample = 0;
15 nAritySample = 0;
16 nDistanceSample = 0;
17 avgAccessibility = 0;
18 arityTooBig = 0;
19 distanceTooBig = 0;
20 disconnected = 0;
21 avgDistance = 0;
22 minKConnexity = -1;
23 maxDistanceReached = -1;
24 }
25
26 Results::~Results()
27 {
28 delete[] arityDistrib;
29 delete[] distanceDistrib;
30 }
31
32 void Results::UpdateArity(const Graph& graph)
33 {
34 for(int i=0; i<graph.size; i++)
35 AddAritySample(graph.adjacency[i].size());
36 }
37
38 void Results::UpdateDistance(int* distance, int nSamples)
39 {
40 for(int i=0; i<nSamples; i++)
41 AddDistanceSample(distance[i]);
42 }
43
44 void Results::AddAritySample(int arity)
45 {
46 if(arity <= maxArity)
47 arityDistrib[arity]++;
48 else
49 distanceTooBig++;
50 nAritySample++;
51 }
52
53 void Results::AddDistanceSample(int distance)
54 {
55 if(distance == -1)
56 disconnected++;
57 else
58 {
59 avgDistance += distance;
60 if(distance <= maxDistance)
61 distanceDistrib[distance]++;
62 else
63 distanceTooBig++;
64 }
65 nDistanceSample++;
66 maxDistanceReached = max(maxDistanceReached, distance);
67 }
68
69 void Results::AddAccessibilitySample(double accessibility)
70 {
71 avgAccessibility += accessibility;
72 nAccessibilitySample++;
73 }
74
75 void Results::Finalise()
76 {
77 for(int i=0; i<=maxArity; i++)
78 arityDistrib[i] /= nAritySample;
79 for(int i=0; i<=maxDistance; i++)
80 distanceDistrib[i] /= nDistanceSample;
81 disconnectionProba = ((double)disconnected)/nDistanceSample;
82 distanceTooBig/= nDistanceSample;
83 arityTooBig /= nAritySample;
84 avgDistance /= nDistanceSample - disconnected;
85 avgAccessibility /= nAccessibilitySample;
86 }