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