Commit bde5fdec authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Addition of a function to check the connectivity from a single node,

much faster than calculating distance distance
parent f6113c52
#include "main.h" #include "main.h"
#include <cmath> #include <cmath>
#include <map> #include <map>
#include <queue>
Graph::Graph(int size, int k, int maxPeers, mt19937& rng) : Graph::Graph(int size, int k, int maxPeers, mt19937& rng) :
distrib(uniform_int_distribution<int>(0, size-1)), distrib(uniform_int_distribution<int>(0, size-1)),
...@@ -49,6 +50,35 @@ void Graph::GetDistancesFrom(int node, int* distance) ...@@ -49,6 +50,35 @@ void Graph::GetDistancesFrom(int node, int* distance)
} }
} }
int Graph::CountUnreachableFrom(int node)
{
bool accessibility[size];
for(int i=0; i<size; i++)
accessibility[i] = false;
accessibility[node] = true;
int unAccessible = size;
queue<int> toVisit;
toVisit.push(node);
while(!toVisit.empty())
{
int n = toVisit.front();
for(int i : adjacency[n])
{
if(!accessibility[i])
{
toVisit.push(i);
accessibility[i] = true;
}
}
unAccessible--;
toVisit.pop();
}
return unAccessible;
}
// kill the last proportion*size machines of the graph // kill the last proportion*size machines of the graph
void Graph::KillMachines(float proportion) void Graph::KillMachines(float proportion)
{ {
...@@ -68,7 +98,7 @@ void Graph::KillMachines(float proportion) ...@@ -68,7 +98,7 @@ void Graph::KillMachines(float proportion)
int Graph::GetMinCut() int Graph::GetMinCut()
{ {
int nIter = log(size)*log(size); int nIter = log(size);
int minCut = -1; int minCut = -1;
for(int i=0; i<nIter; i++) for(int i=0; i<nIter; i++)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "main.h" #include "main.h"
#include <future> #include <future>
#include <sstream> #include <sstream>
#include <unistd.h>
const char* outName = "out.csv"; const char* outName = "out.csv";
...@@ -14,10 +15,11 @@ Results Simulate(int seed, int n, int k, int maxPeer, int maxDistanceFrom, floa ...@@ -14,10 +15,11 @@ Results Simulate(int seed, int n, int k, int maxPeer, int maxDistanceFrom, floa
{ {
Graph graph(n, k, maxPeer, rng); Graph graph(n, k, maxPeer, rng);
graph.KillMachines(alivePercent); graph.KillMachines(alivePercent);
int minCut = graph.GetMinCut(); results.AddAccessibilitySample(((double)graph.CountUnreachableFrom(0))/((double)n));
if(results.minKConnexity == -1 || results.minKConnexity > minCut) //int minCut = graph.GetMinCut();
results.minKConnexity = minCut; //if(results.minKConnexity == -1 || results.minKConnexity > minCut)
results.UpdateArity(graph); //results.minKConnexity = minCut;
//results.UpdateArity(graph);
// Compute the shortest path // Compute the shortest path
/*for(int i=0; i<min(graph.size, maxDistanceFrom); i++) /*for(int i=0; i<min(graph.size, maxDistanceFrom); i++)
...@@ -38,21 +40,27 @@ int main(int argc, char** argv) ...@@ -38,21 +40,27 @@ int main(int argc, char** argv)
FILE* output = fopen(outName, "wt"); FILE* output = fopen(outName, "wt");
int fno = fileno(output); int fno = fileno(output);
fprintf(output, "n,k,a,maxPeer,avgDistance,disconnected,disconnectionProba,maxDistance,maxArityDistrib,minCut\n"); fprintf(output, "n,k,a,maxPeer,avgDistance,disconnected,disconnectionProba,"
"maxDistance,maxArityDistrib,minCut,accessibility\n");
vector<future<string>> outputStrings; vector<future<string>> outputStrings;
for(int n=2000; n<=2000; n*=2) for(int n=2000; n<=2000; n*=2)
for(int k=10; k<=10; k+=5) for(int k=10; k<=10; k+=5)
for(float a=1; a<=1; a+=0.05) for(float a=0.01; a<=1; a+=0.05)
{ {
int seed = rng(); int seed = rng();
outputStrings.push_back(async(launch::async, [seed, n, k, a]() outputStrings.push_back(async(launch::async, [seed, n, k, a]()
{ {
Results results = Simulate(seed, n, k, 3*k, 10000, a, 1); Results results = Simulate(seed, n, k, 3*k, 10000, a, 1);
ostringstream out; ostringstream out;
out << n << "," << k << "," << a << "," << 3*k << "," << results.avgDistance << "," out << n << "," << k << "," << a << "," << 3*k << ","
<< results.disconnected << "," << results.disconnectionProba << "," << results.avgDistance << ","
<< results.maxDistanceReached << "," << results.arityDistrib[3*k] << "," << results.minKConnexity << results.disconnected << ","
<< results.disconnectionProba << ","
<< results.maxDistanceReached << ","
<< results.arityDistrib[3*k] << ","
<< results.minKConnexity << ","
<< results.avgAccessibility
<< endl; << endl;
return out.str(); return out.str();
})); }));
......
...@@ -38,8 +38,10 @@ public: ...@@ -38,8 +38,10 @@ public:
~Graph() { delete[] adjacency; }; ~Graph() { delete[] adjacency; };
void GetDistancesFrom(int node, int* distance); void GetDistancesFrom(int node, int* distance);
void KillMachines(float proportion);
int GetMinCut(); int GetMinCut();
int CountUnreachableFrom(int node);
void KillMachines(float proportion);
//void SplitAS(float proportionAS1, float proportionAS2); //void SplitAS(float proportionAS1, float proportionAS2);
vector<int>* adjacency; vector<int>* adjacency;
...@@ -58,12 +60,14 @@ public: ...@@ -58,12 +60,14 @@ public:
~Results(); ~Results();
void UpdateArity(const Graph& graph); void UpdateArity(const Graph& graph);
void AddAccessibilitySample(double accessibility);
void UpdateDistance(int* distance, int nSamples); void UpdateDistance(int* distance, int nSamples);
void Finalise(); void Finalise();
double* arityDistrib; double* arityDistrib;
double* distanceDistrib; double* distanceDistrib;
double avgDistance; double avgDistance;
double avgAccessibility;
int maxDistanceReached; int maxDistanceReached;
int minKConnexity; int minKConnexity;
...@@ -81,4 +85,5 @@ private: ...@@ -81,4 +85,5 @@ private:
int64_t nAritySample; int64_t nAritySample;
int64_t nDistanceSample; int64_t nDistanceSample;
int64_t nAccessibilitySample;
}; };
...@@ -11,8 +11,10 @@ Results::Results(int maxArity, int maxDistance) : ...@@ -11,8 +11,10 @@ Results::Results(int maxArity, int maxDistance) :
for(int i=0; i<=maxDistance; i++) for(int i=0; i<=maxDistance; i++)
distanceDistrib[i] = 0; distanceDistrib[i] = 0;
nAccessibilitySample = 0;
nAritySample = 0; nAritySample = 0;
nDistanceSample = 0; nDistanceSample = 0;
avgAccessibility = 0;
arityTooBig = 0; arityTooBig = 0;
distanceTooBig = 0; distanceTooBig = 0;
disconnected = 0; disconnected = 0;
...@@ -64,6 +66,12 @@ void Results::AddDistanceSample(int distance) ...@@ -64,6 +66,12 @@ void Results::AddDistanceSample(int distance)
maxDistanceReached = max(maxDistanceReached, distance); maxDistanceReached = max(maxDistanceReached, distance);
} }
void Results::AddAccessibilitySample(double accessibility)
{
avgAccessibility += accessibility;
nAccessibilitySample++;
}
void Results::Finalise() void Results::Finalise()
{ {
for(int i=0; i<=maxArity; i++) for(int i=0; i<=maxArity; i++)
...@@ -74,4 +82,5 @@ void Results::Finalise() ...@@ -74,4 +82,5 @@ void Results::Finalise()
distanceTooBig/= nDistanceSample; distanceTooBig/= nDistanceSample;
arityTooBig /= nAritySample; arityTooBig /= nAritySample;
avgDistance /= nDistanceSample - disconnected; avgDistance /= nDistanceSample - disconnected;
avgAccessibility /= nAccessibilitySample;
} }
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