-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfs.cpp
More file actions
52 lines (44 loc) · 1.08 KB
/
bfs.cpp
File metadata and controls
52 lines (44 loc) · 1.08 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
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <set>
#include "graph.h"
#include "example_util_gettime.h"
void readEdges(Graph &g) {
std::set <std::string> edgeTupleSet;
std::string edgeTuple;
int a, b;
int numEdges = 0;
while (scanf("%i %i", &a, &b) == 2) {
if (a == b) continue;
g.addEdge(a, b);
numEdges++;
}
}
int main(int argc, char **argv) {
if (argc < 3) {
std::cerr << "Correct Usage: ./bfs <algorithm_choice> <num_vertices> <edges_filename>" << std::endl;
exit(1);
}
int algorithm_choice = atoi(argv[1]);
if (algorithm_choice < 0 || algorithm_choice > 3) {
std::cerr << "algorithm_choice must be in { 0, 1, 2 }" << std::endl;
exit(1);
}
Graph g(atoi(argv[2]));
readEdges(g);
double t1 = example_get_time();
switch (algorithm_choice) {
case 0: g.BFS(1);
break;
case 1: g.PBFS(1);
break;
case 2: g.BAGPBFS(1);
break;
}
double t2 = example_get_time();
std::cout << "BFS time: " << t2 - t1 << "ms" << std::endl;
}