Commit cc812286 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

A few more information can now be retrieve from results

You can now run a lot af simulation and save the results in a .csv file
parent 22d6d204
// To compile with -std=c++0x // To compile with -std=c++0x
#include "main.h" #include "main.h"
#include <fstream>
int n = 1000; // the number of peer int n = 1000; // the number of peer
int k = 10; // each peer try to make k connections with the others int k = 10; // each peer try to make k connections with the others
int maxPeer = 25; // no more that 25 connections per peer const char* outName = "out.csv";
int runs = 10; // use this to run the simulation multiple times to get more accurate values
int main()
Results Simulate(mt19937 rng, int n, int k, int maxPeer, int maxDistanceFrom, int runs)
{ {
mt19937 rng(time(NULL));
Results results(maxPeer, 20); Results results(maxPeer, 20);
for(int r=0; r<runs; r++) for(int r=0; r<runs; r++)
{ {
cout << "\r \rRun " << r; cout << "\r \rn = " << n << ", k = " << k << ", run = " << r;
cout.flush(); cout.flush();
Graph graph(n, k, maxPeer, rng); Graph graph(n, k, maxPeer, rng);
results.UpdateArity(graph); results.UpdateArity(graph);
// Compute the shortest path // Compute the shortest path
for(int i=0; i<graph.size; i++) for(int i=0; i<min(graph.size, maxDistanceFrom); i++)
{ {
int distance[graph.size]; int distance[graph.size];
graph.GetDistancesFrom(i, distance); graph.GetDistancesFrom(i, distance);
...@@ -30,24 +30,26 @@ int main() ...@@ -30,24 +30,26 @@ int main()
cout << "\r \r"; cout << "\r \r";
results.Finalise(); results.Finalise();
return results;
}
// Display the parameters we have mesured int main(int argc, char** argv)
cout << "Arity :" << endl; {
for(int i=0; i<=results.maxArity; i++) mt19937 rng(time(NULL));
if(results.arityDistrib[i] != 0)
cout << i << " : " << results.arityDistrib[i] << endl;
cout << "Distance :" << endl; fstream output(outName, fstream::out);
double nLinks = n*(n-1)*runs; output << "n,k,maxPeer,avgDistance,disconnected,maxDistance,maxArityDistrib" << endl;
for(int i=0; i<= results.maxDistance; i++)
if(results.distanceDistrib[i] != 0)
cout << i << " : " << results.distanceDistrib[i] << endl;
cout << "Probability that a node is not reachable : " for(int n=200; n<=20000; n*=2)
<< results.disconnectionProba for(int k=5; k<=50; k+=5)
<< " (" << results.disconnected << " total)" << endl; {
Results results = Simulate(rng, n, k, 3*k, 10000, 50);
output << n << "," << k << "," << 3*k << "," << results.avgDistance << ","
<< results.disconnected << "," << results.maxDistance << ","
<< results.arityDistrib[3*k] << endl;
}
cout << endl; output.close();
return 0; return 0;
} }
......
...@@ -33,16 +33,20 @@ public: ...@@ -33,16 +33,20 @@ public:
double* arityDistrib; double* arityDistrib;
double* distanceDistrib; double* distanceDistrib;
double avgDistance;
int maxDistanceReached;
double disconnectionProba; double disconnectionProba;
double arityTooBig; double arityTooBig;
double distanceTooBig; double distanceTooBig;
int64_t disconnected; int64_t disconnected;
int64_t nAritySample;
int64_t nDistanceSample;
int maxArity; int maxArity;
int maxDistance; int maxDistance;
private: private:
void AddAritySample(int arity); void AddAritySample(int arity);
void AddDistanceSample(int distance); void AddDistanceSample(int distance);
int64_t nAritySample;
int64_t nDistanceSample;
}; };
...@@ -16,6 +16,8 @@ Results::Results(int maxArity, int maxDistance) : ...@@ -16,6 +16,8 @@ Results::Results(int maxArity, int maxDistance) :
arityTooBig = 0; arityTooBig = 0;
distanceTooBig = 0; distanceTooBig = 0;
disconnected = 0; disconnected = 0;
avgDistance = 0;
maxDistanceReached = -1;
} }
Results::~Results() Results::~Results()
...@@ -49,11 +51,16 @@ void Results::AddDistanceSample(int distance) ...@@ -49,11 +51,16 @@ void Results::AddDistanceSample(int distance)
{ {
if(distance == -1) if(distance == -1)
disconnected++; disconnected++;
else if(distance <= maxDistance) else
{
avgDistance += distance;
if(distance <= maxDistance)
distanceDistrib[distance]++; distanceDistrib[distance]++;
else else
distanceTooBig++; distanceTooBig++;
}
nDistanceSample++; nDistanceSample++;
maxDistanceReached = max(maxDistanceReached, distance);
} }
void Results::Finalise() void Results::Finalise()
...@@ -65,4 +72,5 @@ void Results::Finalise() ...@@ -65,4 +72,5 @@ void Results::Finalise()
disconnectionProba = ((double)disconnected)/nDistanceSample; disconnectionProba = ((double)disconnected)/nDistanceSample;
distanceTooBig/= nDistanceSample; distanceTooBig/= nDistanceSample;
arityTooBig /= nAritySample; arityTooBig /= nAritySample;
avgDistance /= nDistanceSample - disconnected;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment