Commit eb453702 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Todo update

parent 82df1543
...@@ -6,5 +6,8 @@ To be done : ...@@ -6,5 +6,8 @@ To be done :
Write docstrings for all class/methods/functions Write docstrings for all class/methods/functions
We should replace dead connection much more often than we refresh tunnels otherwise, it brings instability
If we do this, we must protect some tunnels
To be discussed: To be discussed:
Project name ? Resinet/resnet/rsnet Project name ? Resinet/resnet/rsnet
...@@ -11,6 +11,20 @@ Graph::Graph(int size, int k, int maxPeers, mt19937& generator, const Latency& ...@@ -11,6 +11,20 @@ Graph::Graph(int size, int k, int maxPeers, mt19937& generator, const Latency&
SaturateNode(i); SaturateNode(i);
} }
Graph::Graph(const Graph& g) :
generator(g.generator), size(g.size), k(g.k), maxPeers(g.maxPeers), latency(latency),
distrib(g.distrib)
{
adjacency = new unordered_set<int>[size];
generated = new unordered_set<int>[size];
for(int i=0; i<size; i++)
{
adjacency[i] = unordered_set<int>(g.adjacency[i]);
generated[i] = unordered_set<int>(g.generated[i]);
}
}
void Graph::SaturateNode(int node) void Graph::SaturateNode(int node)
{ {
while(generated[node].size() < k && AddEdge(node)) { } while(generated[node].size() < k && AddEdge(node)) { }
...@@ -86,11 +100,12 @@ void Graph::GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances) ...@@ -86,11 +100,12 @@ void Graph::GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances)
} }
// get the BC // get the BC
// The error is here
while(!order.empty()) while(!order.empty())
{ {
int node = order.top(); int node = order.top();
order.pop(); order.pop();
if(distances[node] != -1) if(distances[node] != -1 && node != from)
nRoutes[prevs[node]] += nRoutes[node]; nRoutes[prevs[node]] += nRoutes[node];
} }
} }
...@@ -138,21 +153,82 @@ void Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* ari ...@@ -138,21 +153,82 @@ void Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* ari
for(int i = 0; i<size; i++) for(int i = 0; i<size; i++)
{ {
//cout << "["; cout.flush();
routesResult r = results[i]; routesResult r = results[i];
if(r.toDelete >= 0) if(r.toDelete >= 0)
RemoveEdge(i, r.toDelete); RemoveEdge(i, r.toDelete);
//cout << "#"; cout.flush();
SaturateNode(i); SaturateNode(i);
//cout << "]"; cout.flush();
avgDistance += r.avgDistance*(size-r.unreachable); avgDistance += r.avgDistance*(size-r.unreachable);
avgDistanceWeight += size-r.unreachable; avgDistanceWeight += size-r.unreachable;
unreachable += r.unreachable; unreachable += r.unreachable;
arityDistrib[adjacency[i].size()]++; arityDistrib[adjacency[i].size()]++;
} }
avgDistance /= avgDistanceWeight; avgDistance /= avgDistanceWeight;
for(int i=0; i<=maxPeers; i++) for(int i=0; i<=maxPeers; i++)
arityDistrib[i] /= size; arityDistrib[i] /= size;
}
int Graph::CountUnreachableFrom(int node)
{
bool accessibility[size];
for(int i=0; i<size; i++)
accessibility[i] = false;
accessibility[node] = true;
int unreachable = 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;
}
}
unreachable--;
toVisit.pop();
}
return unreachable;
}
double Graph::GetUnAvalaibility()
{
double moy = 0;
for(int i=0; i<size; i++)
moy += CountUnreachableFrom(i);
return moy / (size*size);
}
void Graph::KillMachines(float proportion)
{
size = proportion*size;
for(int i=0; i<size; i++)
{
vector<int> toBeRemoved;
for(int j : adjacency[i])
if(j >= size)
toBeRemoved.push_back(j);
for(int j : toBeRemoved)
{
generated[i].erase(j);
adjacency[i].erase(j);
}
}
} }
\ No newline at end of file
...@@ -5,28 +5,30 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co ...@@ -5,28 +5,30 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
{ {
FILE* output = fopen(outName, "wt"); FILE* output = fopen(outName, "wt");
int fno = fileno(output); int fno = fileno(output);
fprintf(output, "round,avgdistance,unreachable,arity 0..30\n"); fprintf(output, "round,alive,unreachable\n");
mt19937 rng(seed); mt19937 rng(seed);
Graph graph(size, k, maxPeer, rng, latency); Graph graph(size, k, maxPeer, rng, latency);
cout << "\r" << 0 << "/" << 2000; cout << "\r" << 0 << "/" << 300;
cout.flush(); cout.flush();
for(int i=0; i<2000; i++) for(int i=0; i<300; i++)
{ {
double avgDistance, unreachable; for(float a=0.05; a<1; a+=0.05)
double arityDistrib[maxPeer+1]; {
graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib); Graph copy(graph);
copy.KillMachines(a);
fprintf(output, "%d,%f,%f", i , avgDistance, unreachable); fprintf(output, "%d,%f,%f\n",i, a , copy.GetUnAvalaibility());
for(int j=0; j<=maxPeer; j++)
fprintf(output, ",%f", arityDistrib[j]);
fprintf(output, "\n");
fflush(output); fflush(output);
fsync(fno); fsync(fno);
}
cout << "\r" << i+1 << "/" << 2000; double avgDistance, unreachable;
double arityDistrib[31];
graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib);
cout << "\r" << i+1 << "/" << 300;
cout.flush(); cout.flush();
} }
...@@ -39,7 +41,7 @@ int main(int argc, char** argv) ...@@ -39,7 +41,7 @@ int main(int argc, char** argv)
mt19937 rng(time(NULL)); mt19937 rng(time(NULL));
//Latency latency("latency/pw-1715/pw-1715-latencies", 1715); //Latency latency("latency/pw-1715/pw-1715-latencies", 1715);
//latency.Rewrite(20); //latency.Rewrite(20);
Latency latency("latency/pw-1715/rewrite", 1556); Latency latency("latency/pw-1715/rewrite", 1555);
vector<future<void>> threads; vector<future<void>> threads;
......
...@@ -27,14 +27,18 @@ class Graph ...@@ -27,14 +27,18 @@ class Graph
{ {
public: public:
Graph(int size, int k, int maxPeers, mt19937& generator, const Latency& latency); Graph(int size, int k, int maxPeers, mt19937& generator, const Latency& latency);
Graph(const Graph& g);
~Graph() { delete[] adjacency; delete[] generated; }; ~Graph() { delete[] adjacency; delete[] generated; };
void UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib); void UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib);
double GetUnAvalaibility();
void KillMachines(float proportion);
private: private:
void SaturateNode(int node); void SaturateNode(int node);
bool AddEdge(int from); bool AddEdge(int from);
void RemoveEdge(int from, int to); void RemoveEdge(int from, int to);
void GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances); void GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances);
int CountUnreachableFrom(int node);
mt19937& generator; mt19937& generator;
uniform_int_distribution<int> distrib; uniform_int_distribution<int> distrib;
......
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