-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.cpp
More file actions
75 lines (67 loc) · 2.4 KB
/
extension.cpp
File metadata and controls
75 lines (67 loc) · 2.4 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
73
74
75
/*
* Authors: Hasan Al Jamaly
* Date: 6/5/2017
* File name: extension.cpp
* Description:
* This is the driver program for the extension, which is responsible for
* producing different friend/follow suggestions in facebook or twitter
* depending on the current relationships between users. Input arguments
* are the input file of connections, output file to write suggestions,
* either facebook or twitter to determine what program to run, and if
* facebook is chosen then the node to be used as the source of the EgoNet
* has to be indicated as well.
*/
#include <string>
#include <chrono>
#include "FriendGraph.h"
#include "User.h"
#include "Friendship.h"
#define NUMARGS 4
#define USAGE "Wrong number of input arguments for ./extension.\n"
#define USAGE2 "Usage: ./extension input_file output_file [twitter|facebook] "
#define USAGE3 "[egoNetwork center only if facebook is chosen].\n";
using namespace std;
/*
* This is the driver program responsible for parsing the command line arguments
* and passing them to either the facebook program or the twitter program.
* Returns -1 for failure and 0 for success, and has argc (input argument
* count) and argv (array of input arguments) as input.
*/
int main (int argc, char * argv[]) {
/* Check for input arguments and the validity of their count */
if (argc < NUMARGS) {
cerr << USAGE;
cerr << USAGE2;
cerr << USAGE3;
return -1;
}
char * database = argv[1]; // the input file with graph information
char * outfile = argv[2]; // the output file to write suggestions
string option = argv [3]; // either facebook or twitter
/* if the facebook option is chosen, a node has to be provided */
if (option == "facebook" && argc == NUMARGS) {
cerr << "Choose a user as the center of the egoNetwork!\n";
cerr << USAGE2;
cerr << USAGE3;
return -1;
}
/* if option is neither facebook or twitter */
if (option != "facebook" && option != "twitter") {
cerr << USAGE2;
cerr << USAGE3;
return -1;
}
/* loading the graph from the input file */
FriendGraph graph;
graph.loadFromFile(database);
/* running the twitter program */
if (option == "twitter") {
graph.suggestFollows(outfile);
}
/* running the facebook program for the given node */
if (option == "facebook") {
int egoNetCenter = stoi(argv[4]);
graph.suggestFriends(outfile,egoNetCenter);
}
return 0; // SUCCESS!
}