-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.cpp
More file actions
72 lines (66 loc) · 2.11 KB
/
Parser.cpp
File metadata and controls
72 lines (66 loc) · 2.11 KB
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
#include "Parser.h"
using std::string;
using std::ifstream;
using std::stoul;
using std::getline;
using std::vector;
using std::ofstream;
using std::stringstream;
void readData(TwitterGraph& g, string filename){
ifstream file(filename);
string line;
stringstream ss;
if (file.is_open()){
while (getline(file,line) ){
unsigned long idOne;
unsigned long idTwo;
ss<<line;
ss>>idOne>>idTwo;
//Now turning strings into unsigned long and creating User objects
g.addUser(idOne);
g.addUser(idTwo);
g.addConnection(idOne, idTwo);
}
}
}
void outputBFS(TwitterGraph& g, string filename){
vector<vector<unsigned long>> nodes = g.BFS();
ofstream myfile;
myfile.open(filename);
int i = 1;
myfile<<"The following is an output of a BFS traversal of twitter users and is seperated in components:\n\n";
for(vector<unsigned long>& component: nodes){
myfile<<"Component "<<i<<" has users: ";
for(unsigned long& user: component){
myfile<<user<<" ";
}
myfile<<"\n\n";
i++;
}
myfile.close();
}
void outputDistances(TwitterGraph& g, string filename){
g.calculateDistances();
int d;
ofstream myfile;
myfile.open(filename);
myfile<<"The following is a list of distances between two nodes in the graph with positive distance:\n\n";
for(auto it = g.users.begin(); it != g.users.end(); it++){
for(auto it2 = g.users.begin(); it2 != g.users.end(); it2++){
d = g.findDistance(it->first,it2->first);
if(d>0)
myfile<<it->first<<" -> "<<it2->first<<" : "<<d<<"\n";
}
}
myfile.close();
}
void outputC(TwitterGraph& g, std::string filename){
g.calculateCentrality();
ofstream myfile;
myfile.open(filename);
myfile<<"The following is a list of how central each of the nodes are in the graph:\n\n";
for(auto it = g.users.begin(); it != g.users.end(); it++){
myfile<<it->first<<" : "<<it->second->betweenessCentralValue<<"\n";
}
myfile.close();
}