-
Notifications
You must be signed in to change notification settings - Fork 0
/
blogel_sim_vorPart.h
78 lines (71 loc) · 2.13 KB
/
blogel_sim_vorPart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "blogel/Voronoi.h"
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "blogel/BGlobal.h"
using namespace std;
const int mod = 10;
class vorPart : public BPartWorker {
char buf[1000];
public:
virtual BPartVertex* toVertex(char* line) {
char *pch;
BPartVertex *v = new BPartVertex;
v->value().content = line; //first set content!!! line will change later due to "strtok"
pch = strtok(line, " ");
v->id = atoi(pch);
pch = strtok(NULL, " ");
int num = atoi(pch);
while (num--) {
pch = strtok(NULL, " ");
int nb = atoi(pch);
v->value().neighbors.push_back(nb);
}
return v;
}
virtual void toline(BPartVertex* v, BufferedWriter& writer) //key: "vertexID blockID slaveID"
{ //val: list of "vid block slave "
sprintf(buf, "%d %d %d %d ", v->id, v->id % mod, v->value().color, _my_rank);
writer.write(buf);
vector<triplet>& vec = v->value().nbsInfo;
hash_map<int, triplet> map;
for (int i = 0; i < vec.size(); i++) {
map[vec[i].vid] = vec[i];
}
////////
stringstream ss(v->value().content);
string token;
ss >> token; //vid
ss >> token; //number for webbase
int num = v->value().neighbors.size();
sprintf(buf, "%d ", num);
writer.write(buf);
for (int i = 0; i < num; i++) {
ss >> token;
int vid = atoi(token.c_str());
triplet trip = map[vid];
sprintf(buf, "%d %d %d ", vid, trip.bid, trip.wid);
writer.write(buf);
}
writer.write("\n");
}
};
int blogel_sim_vorPart(string in_path, string out_path)
{
WorkerParams param;
param.input_path = in_path;
param.output_path = out_path;
param.force_write = true;
param.native_dispatcher = false;
bool to_undirected = false;
//////
set_sampRate(0.01);
set_maxHop(50);
set_maxVCSize(1000000000);
set_factor(2);
set_stopRatio(0.9);
set_maxRate(0.1);
//////
vorPart worker;
worker.run(param, to_undirected);
}