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
#include "main.h"
#include <fstream>
int n = 1000; // the number of peer
int k = 10; // each peer try to make k connections with the others
int maxPeer = 25; // no more that 25 connections per peer
int runs = 10; // use this to run the simulation multiple times to get more accurate values
const char* outName = "out.csv";
int main()
Results Simulate(mt19937 rng, int n, int k, int maxPeer, int maxDistanceFrom, int runs)
{
mt19937 rng(time(NULL));
Results results(maxPeer, 20);
for(int r=0; r<runs; r++)
{
cout << "\r \rRun " << r;
cout << "\r \rn = " << n << ", k = " << k << ", run = " << r;
cout.flush();
Graph graph(n, k, maxPeer, rng);
results.UpdateArity(graph);
// 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];
graph.GetDistancesFrom(i, distance);
......@@ -30,24 +30,26 @@ int main()
cout << "\r \r";
results.Finalise();
return results;
}
// Display the parameters we have mesured
cout << "Arity :" << endl;
for(int i=0; i<=results.maxArity; i++)
if(results.arityDistrib[i] != 0)
cout << i << " : " << results.arityDistrib[i] << endl;
int main(int argc, char** argv)
{
mt19937 rng(time(NULL));
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;
fstream output(outName, fstream::out);
output << "n,k,maxPeer,avgDistance,disconnected,maxDistance,maxArityDistrib" << endl;
cout << "Probability that a node is not reachable : "
<< results.disconnectionProba
<< " (" << results.disconnected << " total)" << 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;
}
cout << endl;
output.close();
return 0;
}
......
......@@ -33,16 +33,20 @@ public:
double* arityDistrib;
double* distanceDistrib;
double avgDistance;
int maxDistanceReached;
double disconnectionProba;
double arityTooBig;
double distanceTooBig;
int64_t disconnected;
int64_t nAritySample;
int64_t nDistanceSample;
int maxArity;
int maxDistance;
private:
void AddAritySample(int arity);
void AddDistanceSample(int distance);
int64_t nAritySample;
int64_t nDistanceSample;
};
......@@ -16,6 +16,8 @@ Results::Results(int maxArity, int maxDistance) :
arityTooBig = 0;
distanceTooBig = 0;
disconnected = 0;
avgDistance = 0;
maxDistanceReached = -1;
}
Results::~Results()
......@@ -49,11 +51,16 @@ void Results::AddDistanceSample(int distance)
{
if(distance == -1)
disconnected++;
else if(distance <= maxDistance)
else
{
avgDistance += distance;
if(distance <= maxDistance)
distanceDistrib[distance]++;
else
distanceTooBig++;
}
nDistanceSample++;
maxDistanceReached = max(maxDistanceReached, distance);
}
void Results::Finalise()
......@@ -65,4 +72,5 @@ void Results::Finalise()
disconnectionProba = ((double)disconnected)/nDistanceSample;
distanceTooBig/= nDistanceSample;
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