Added a tool to simulate on real data
[re6stnet.git] / simulation / realistic_dataset / main.cpp
1 // To compile : g++ -std=c++0x results.cpp graph.cpp main.cpp -lpthread
2 #include "main.h"
3
4 void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, const char* outName)
5 {
6 FILE* output = fopen(outName, "wt");
7 int fno = fileno(output);
8 fprintf(output, "round,avgdistance,unreachable,arity 0..30\n");
9
10 mt19937 rng(seed);
11 Graph graph(size, k, maxPeer, rng, latency);
12
13 cout << "\r" << 0 << "/" << 2000;
14 cout.flush();
15
16 for(int i=0; i<2000; i++)
17 {
18 double avgDistance, unreachable;
19 double arityDistrib[maxPeer+1];
20 graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib);
21
22 fprintf(output, "%d,%f,%f", i , avgDistance, unreachable);
23 for(int j=0; j<=maxPeer; j++)
24 fprintf(output, ",%f", arityDistrib[j]);
25 fprintf(output, "\n");
26 fflush(output);
27 fsync(fno);
28
29 cout << "\r" << i+1 << "/" << 2000;
30 cout.flush();
31 }
32
33 cout << endl;
34 fclose(output);
35 }
36
37 int main(int argc, char** argv)
38 {
39 mt19937 rng(time(NULL));
40 //Latency latency("latency/pw-1715/pw-1715-latencies", 1715);
41 //latency.Rewrite(20);
42 Latency latency("latency/pw-1715/rewrite", 1556);
43
44 vector<future<void>> threads;
45
46 for(int i=0; i<8; i++)
47 {
48 int seed = rng();
49 char* out = new char[20];
50 sprintf(out, "out_%d.csv", i);
51 threads.push_back(async(launch::async, [seed, out, &latency]()
52 { simulate(1555, 10, 30, seed, latency, out); delete[] out; }));
53 }
54
55 for(int i=0; i<8; i++)
56 threads[i].get();
57
58 return 0;
59 }