Commit 01f450fd authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Simulation update

parent 4f9f9c37
......@@ -81,7 +81,7 @@ def getConfig():
# Openvpn options
_('openvpn_args', nargs=argparse.REMAINDER,
help="Common OpenVPN options (e.g. certificates)")
help="Common OpenVPN options")
return parser.parse_args()
......
......@@ -40,7 +40,7 @@ bool Graph::AddEdge(int from)
if( to != from
&& latency.values[from][to] > 0
&& adjacency[from].count(to) == 0
&& adjacency[to].size() + generated[to].size() <= maxPeers + k)
&& adjacency[to].size() + k < maxPeers + generated[to].size())
{
generated[from].insert(to);
adjacency[from].insert(to);
......@@ -112,22 +112,45 @@ void Graph::GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances)
}
void Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib, int refreshCount)
int Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib,
double* bcArity, int nRefresh, int round)
{
int nUpdated = 0;
routesResult results[size];
double bc[size];
for(int i=0; i<size; i++)
bc[i] = 0;
avgDistance = 0;
double avgDistanceWeight = 0;
unreachable = 0;
for(int i=0; i<=maxPeers; i++)
{
bcArity[i] = 0;
arityDistrib[i] = 0;
}
for(int i=0; i<size; i++)
{
// Compute the routes
int nRoutes[size], prevs[size], distances[size];
GetRoutesFrom(i, nRoutes, prevs, distances);
for(int j=0; j<size; j++)
bc[j] += nRoutes[j];
// Get the values
routesResult r;
r.toDelete = -1;
for(int k=0; k<nRefresh; k++)
{
int mini = -1;
for(int j : generated[i])
if(r.toDelete == -1 || nRoutes[r.toDelete] > nRoutes[j])
r.toDelete = j;
if(mini == -1 || nRoutes[mini] > nRoutes[j])
mini = j;
if(mini != -1)
r.toDelete.push(mini);
}
r.arity = adjacency[i].size();
......@@ -146,17 +169,18 @@ void Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* ari
results[i] = r;
}
avgDistance = 0;
double avgDistanceWeight = 0;
unreachable = 0;
for(int i=0; i<=maxPeers; i++)
arityDistrib[i] = 0;
for(int i = 0; i<size; i++)
{
routesResult r = results[i];
if(r.toDelete >= 0)
RemoveEdge(i, r.toDelete);
if((adjacency[i].size() > 16 && adjacency[i].size() < 26) || round % 4 == 0)
{
nUpdated++;
while(!r.toDelete.empty())
{
RemoveEdge(i, r.toDelete.top());
r.toDelete.pop();
}
}
SaturateNode(i);
......@@ -164,12 +188,18 @@ void Graph::UpdateLowRoutes(double& avgDistance, double unreachable, double* ari
avgDistanceWeight += size-r.unreachable;
unreachable += r.unreachable;
arityDistrib[adjacency[i].size()]++;
bcArity[adjacency[i].size()] += bc[i] - 2*size + 1;
}
avgDistance /= avgDistanceWeight;
for(int i=0; i<=maxPeers; i++)
{
bcArity[i] = arityDistrib[i]>0 ? bcArity[i] / arityDistrib[i]:0;
arityDistrib[i] /= size;
}
return nUpdated;
}
int Graph::CountUnreachableFrom(int node)
......
......@@ -4,18 +4,26 @@ Latency::Latency(const char* filePath, int size) : size(size)
{
values = new int*[size];
for(int i=0; i<size; i++)
{
values[i] = new int[size];
for(int j=0; j<size; j++)
values[i][j] = -1;
}
FILE* file = NULL;
file = fopen(filePath, "r");
int a, b, latency;
int a, b;
double latency;
while(!feof(file))
{
fscanf(file, "%d %d %d", &a, &b, &latency);
values[b][a] = latency;
values[a][b] = latency;
fscanf(file, "%d %d %lf", &a, &b, &latency);
if(latency < 100)
latency = -1;
values[b-1][a-1] = latency;
values[a-1][b-1] = latency;
}
fclose(file);
......@@ -89,3 +97,18 @@ double Latency::GetAverageDistance()
return avg / (size*size);
}
double Latency::GetAveragePing()
{
double out = 0;
double nPing = 0;
for(int i=0; i<size; i++)
for(int j=0; j<size; j++)
if(values[i][j] > 0)
{
nPing++;
out += values[i][j];
}
return out/nPing;
}
\ No newline at end of file
// To compile : g++ -std=c++0x latency.cpp graph.cpp main.cpp -lpthread
// The best distance : 66.9239 with a full graph
// The best distance for latency : 66.9239 with a full graph
// other dataset : http://pdos.csail.mit.edu/p2psim/kingdata/
// for latency_2 :
// Optimal distance : 16085.3
// Average ping : 75809.4
#include "main.h"
......@@ -10,35 +13,38 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
FILE* output = fopen(outName, "wt");
int fno = fileno(output);
fprintf(output, "round,alive,unreachable\n");
Graph graph(size, k, maxPeer, rng, latency);
cout << "\r" << 0 << "/" << 300;
cout.flush();
long long int nUpdates = 0;
for(int i=0; i<300; i++)
{
for(float a=0.05; a<1; a+=0.05)
/*for(float a=0.05; a<1; a+=0.05)
{
Graph copy(graph);
copy.KillMachines(a);
fprintf(output, "%d,%f,%f\n",i , a , copy.GetUnAvalaibility());
fflush(output);
fsync(fno);
}
}*/
double avgDistance, unreachable;
double arityDistrib[31];
graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib);
double arityDistrib[31], bcArity[31];
nUpdates += graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib, bcArity, 1, i);
/*fprintf(output, "%d,%f", i, avgDistance);
fprintf(output, "%d,%f, %lld", i, avgDistance, nUpdates);
for(int j=0; j<=30; j++)
fprintf(output, ",%f", arityDistrib[j]);
for(int j=0; j<=30; j++)
fprintf(output, ",%f", bcArity[j]);
fprintf(output, "\n");
fflush(output);
fsync(fno);*/
fsync(fno);
cout << "\r" << i+1 << "/" << 300;
cout.flush();
......@@ -51,19 +57,21 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
int main(int argc, char** argv)
{
mt19937 rng(time(NULL));
Latency latencyR("latency/pw-1715/pw-1715-latencies", 1715);
latencyR.Rewrite(20);
Latency latency("latency/pw-1715/rewrite", 1555);
//Latency latencyR("latency/pw-1715/pw-1715-latencies", 1715);
//latencyR.Rewrite(20);
Latency latency("datasets/latency_2_2500", 2500);
//cout << "Optimal distance : " << latency.GetAverageDistance() << endl;
//cout << "Average ping : " << latency.GetAveragePing() << endl;
vector<future<void>> threads;
for(int i=0; i<20; i++)
for(int i=0; i<1; i++)
{
int seed = rng();
char* out = new char[20];
sprintf(out, "out_%d.csv", i);
threads.push_back(async(launch::async, [seed, out, &latency]()
{ simulate(1555, 10, 30, seed, latency, out); delete[] out; }));
{ simulate(2500, 10, 30, seed, latency, out); delete[] out; }));
}
for(int i=0; i<1; i++)
......
......@@ -19,6 +19,7 @@ public:
void Rewrite(int n);
~Latency();
double GetAverageDistance();
double GetAveragePing();
int** values;
private:
......@@ -31,7 +32,7 @@ public:
Graph(int size, int k, int maxPeers, mt19937& generator, const Latency& latency);
Graph(const Graph& g);
~Graph() { delete[] adjacency; delete[] generated; };
void UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib);
int UpdateLowRoutes(double& avgDistance, double unreachable, double* arityDistrib, double* bcArity, int nRefresh, int round);
double GetUnAvalaibility();
void KillMachines(float proportion);
......@@ -58,5 +59,5 @@ struct routesResult
double avgDistance;
int arity;
int unreachable;
int toDelete;
stack<int> toDelete;
};
\ No newline at end of file
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