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);
results.UpdateDistance(distance, graph.size); results.UpdateDistance(distance, graph.size);
} }
} }
cout << "\r \r"; cout << "\r \r";
results.Finalise(); results.Finalise();
return results;
}
int main(int argc, char** argv)
{
mt19937 rng(time(NULL));
fstream output(outName, fstream::out);
output << "n,k,maxPeer,avgDistance,disconnected,maxDistance,maxArityDistrib" << endl;
for(int n=200; n<=20000; n*=2)
for(int k=5; k<=50; k+=5)
{
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;
}
// Display the parameters we have mesured output.close();
cout << "Arity :" << endl;
for(int i=0; i<=results.maxArity; i++)
if(results.arityDistrib[i] != 0)
cout << i << " : " << results.arityDistrib[i] << endl;
cout << "Distance :" << endl;
double nLinks = n*(n-1)*runs;
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 : "
<< results.disconnectionProba
<< " (" << results.disconnected << " total)" << endl;
cout << endl;
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
distanceDistrib[distance]++; {
else avgDistance += distance;
distanceTooBig++; if(distance <= maxDistance)
distanceDistrib[distance]++;
else
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