Commit f8574d91 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

A few fixes in the simulator, preapring the simulation of major failure in the network

parent 1c0c9b54
// To compile with -std=c++0x
// The GET_BC option might not be working
//#define GET_BC // Uncomment this line to get the betweeness centrality
#include "main.h"
......@@ -14,18 +15,22 @@ Graph::Graph(int size, int k, int maxPeers, mt19937 rng) :
{
adjacency = new vector<int>[size];
for(int i=0; i<size; i++)
{
set<int> alreadyConnected;
alreadyConnected.insert(i);
for(int j=0; j<k; j++)
{
int otherNode;
// TODO : forbid to connect twice to the same node
// it can only improve the result
while((otherNode = distrib(rng)) == i
while(alreadyConnected.count(otherNode = distrib(rng)) == 1
|| otherNode > i && adjacency[otherNode].size() > maxPeers-10
|| adjacency[otherNode].size() > maxPeers)
{ }
adjacency[i].push_back(otherNode);
adjacency[otherNode].push_back(i);
}
}
}
void Graph::GetDistancesFrom(int node, int* distance)
......@@ -51,6 +56,12 @@ void Graph::GetDistancesFrom(int node, int* distance)
}
}
// kill the last proportion*size machines of the graph
void Graph::KillMachines(float proportion)
{
// TODO
}
int main()
{
mt19937 rng(time(NULL));
......@@ -79,6 +90,7 @@ int main()
for(int i=0; i<graph.size; i++)
{
int distance[graph.size];
// if(i%10==0) cout << "Computing distances from node " << i << endl;
graph.GetDistancesFrom(i, distance);
// retrieve the distance
......
......@@ -18,7 +18,7 @@ public:
~Graph() { delete[] adjacency; };
void GetDistancesFrom(int node, int* distance);
//void KillMachines(float portion, vector<int>* graph)
void KillMachines(float proportion);
vector<int>* adjacency;
int size;
......
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