-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
83 lines (58 loc) · 2.41 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
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
#include <iostream>
#include <vector>
#include <utility>
#include <fstream>
#include "road.h"
int main(int argc, char** argv) {
// should be of the form:
// ./main datasmall.txt BFS[0] prim centrality
// ./main data.txt prim
// there has to be at least 2 arguments
if (argc < 2) {
return 0;
}
char* filename = argv[1];
// accessing the file
Roads graph(filename);
if (graph.getAdj().size() < 1) {
std::cout << "file does not exist" << std::endl;
return 0;
}
if (graph.isconnected() == false) {
std::cout << "graph is not connected" << std::endl;
return 0;
}
ofstream outputfile;
outputfile.open("output.txt");
for (int i = 2; i < argc; i++) {
if (strcmp(argv[i], "prim") == 0) {
std::vector<std::pair<int, int>> primed = graph.prim();
outputfile << "Prim's Algorithm:\n" << "This is the set of edges that make up the minimum spanning tree.\n";
for (int i = 0; i < (int) primed.size(); i++) {
outputfile << primed[i].first << " <-> " << primed[i].second << "\n";
}
outputfile << "\n";
} else if (strcmp(argv[i], "centrality") == 0) {
std::vector<int> central = graph.centrality();
outputfile << "Betweenness Centrality:\n" << "The following are the amount of times each node is appears in a shortest path. A higher score indicates a more central node.\n\n";
int maxIndex = graph.getMaxIndex(central);
outputfile << "The most central node is node " << maxIndex << " with a score of " << central[maxIndex] << ".\n\n";
for (int i = 0; i < (int) central.size(); i++) {
outputfile << "Node " << i << ": " << central[i] << "\n";
}
outputfile << "\n";
} else if (argv[i][0] == 'B' && argv[i][1] == 'F' && argv[i][2] == 'S') {
std::vector<int> bfs = graph.BFS((int) argv[i][4] - 48);
outputfile << "Breadth First Search:\n";
for (int i = 0; i < (int) bfs.size(); i++) {
outputfile << bfs[i] << " ";
if (i % 20 == 19) {
outputfile << "\n";
}
}
outputfile << "\n\n";
}
}
outputfile.close();
return 0;
}