-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartitionssim.cc
91 lines (73 loc) · 2.26 KB
/
partitionssim.cc
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
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "partitionssim.h"
using namespace std;
using std::cout;
using std::cin;
using std::endl;
unsigned stou(char *s){
return strtoul(s,(char **)NULL,10);
}
// Call: trade <seed> <Ntries>
int main(int argc,char *argv[]){
cout << "Version: February 17, 2017." << endl;
cout << "Command: ";
cout << argv[0];
for(int i=1;i<argc; i++)
cout << " " << argv[i];
cout << endl;
// Parse command input
const string CALL_SYNTAX = "Call: ./partitionssim partitionsfile outfile [--skiplines N] [-h]\n";
if( argc == 1 ){
cout << CALL_SYNTAX;
exit(-1);
}
int argNr = 1;
string partitionsFileName = "noname";
string outFileName = "noname";
int Nskiplines = 0;
while(argNr < argc){
if(to_string(argv[argNr]) == "-h"){
cout << CALL_SYNTAX;
cout << "partitionmatrix: Each column corresponds to a partition and each row corresponds to a node id." << endl;
cout << "outfile: partitionID1 partitionID2 similarity" << endl;
cout << "--skiplines N: Skip N lines in partitionmatrix before reading data in" << endl;
cout << "-h: This help" << endl;
exit(-1);
}
else if(to_string(argv[argNr]) == "--skiplines"){
argNr++;
Nskiplines = atoi(argv[argNr]);
argNr++;
}
else{
if(argv[argNr][0] == '-'){
cout << "Unknown command: " << to_string(argv[argNr]) << endl;
cout << CALL_SYNTAX;
exit(-1);
}
if(partitionsFileName == "noname")
partitionsFileName = string(argv[argNr]);
else
outFileName = string(argv[argNr]);
argNr++;
}
}
if(partitionsFileName != "noname" && outFileName != "noname"){
cout << "Will read data from " << partitionsFileName;
if(Nskiplines > 0)
cout << ", skipping " << Nskiplines << " lines";
cout << ", and write results to " << outFileName << endl;
}
else{
if(partitionsFileName == "noname")
cout << "Missing partitionmatrix" << endl;
if(outFileName == "noname")
cout << "Missing outfile" << endl;
cout << CALL_SYNTAX;
exit(-1);
}
vector<vector<int > > partitions;
int Nnodes = 0;
int Npartitions = 0;
readPartitionsFile(partitions,partitionsFileName,Nnodes,Npartitions,Nskiplines);
calcWJaccard(partitions,outFileName,Nnodes,Npartitions);
}