-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (50 loc) · 2.15 KB
/
main.cpp
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
#include "origin.h"
#include "GrahamScans.h"
#include "Andrews.h"
#include "JarvisMarch.h"
int main(int argc, char *argv[]) {
vector<pair<double , double> > points;
if ( argc < 2 ) // argc should be 2 for correct execution
// We print argv[0] assuming it is the program name
cout << "usage: " << argv[0] << " <algorithm> <filename>\n";
else {
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
cout << "\nusage: " << argv[0] << " <algorithm> <filename>\n";
printf("\t-g\t--grahamscan\tEvaluate by Graham Scan\n");
printf("\t-a\t--andrew\tEvaluate by Andrew's algorithm\n");
printf("\t-j\t--jarvismarch\tEvaluate by Jarvis March\n\n");
}
else {
if (argv[2])
points = getData(argv[2]);
else
points = getData("./tests/sampleInput.txt");
if (argv[1][1] == 'g' || strcmp(argv[1], "--grahamscan") == 0) {
double ret = execGrahamScans(points);
//cout << "Time taken : " << ret << endl;
}
else if (argv[1][1] == 'a' || strcmp(argv[1], "--andrew") == 0) {
//clock_t t_taken;
//t_taken = clock();
set<pair<double, double> > andrews_res = execAndrews(points);
ull andrews_len = andrews_res.size();
cout << andrews_len << endl;
set<pair<double, double> >::iterator iter;
for (iter = andrews_res.begin(); iter != andrews_res.end(); ++iter) {
cout << (*iter).first << " " << (*iter).second << endl;
}
//t_taken = clock() - t_taken;
//cout << "Time taken : " << ((double) (t_taken))/CLOCKS_PER_SEC << endl;
}
else if (argv[1][1] == 'j' || strcmp(argv[1], "--jarvismarch") == 0) {
execJarvisMarch(points);
cout<<"-----End of JarvisMarch-----"<<endl;
//cout << "Time taken : " << time_jarvis << endl;
}
else {
printf("Illegal flag");
}
}
}
return 0;
}