-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
53 lines (45 loc) · 1.61 KB
/
Copy pathmain.cpp
File metadata and controls
53 lines (45 loc) · 1.61 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
#include <chrono>
#include "cmath"
#include "Graph.h"
using namespace std::chrono;
using namespace std;
int main() {
int line_count = 0;
//get a line count(number of rows) of a dataset
std::string filename = "dataset/cal.cedge.txt";
std::ifstream File(filename);
std::string line;
while (std::getline(File, line)) {
line_count++;
}
// Create an object called graph.
Graph graph;
int startNode;
int destinationNode;
// BFS
std::cout << "\n\n----------- BFS -----------\n";
std::cout << "Start Node for BFS: ";
std::cin >> startNode;
std::cout << "End Node for BFS: ";
std::cin >> destinationNode;
graph.addEdgeBFS(filename);
auto start = high_resolution_clock::now();
int result = graph.BFS(startNode, destinationNode, line_count);
auto stop = high_resolution_clock::now();
// Dijkstra's
std::cout << "\n\n----------- Dijkstra -----------\n";
std::cout << "Start Node for Dijkstra: ";
std::cin >> startNode;
std::cout << "End Node for Dijkstra: ";
std::cin >> destinationNode;
graph.addEdgeDijkstra(filename, line_count);
auto start_d = high_resolution_clock::now();
graph.Dijkstra(filename, startNode, destinationNode);
auto stop_d = high_resolution_clock::now();
std::cout << "\n\n\n----------- End Results -----------\n";
auto duration = duration_cast<microseconds>(stop - start);
std::cout << "Time taken by BFS function: " << duration.count() << " microseconds" << std::endl;
auto duration_d = duration_cast<microseconds>(stop_d - start_d);
std::cout << "Time taken by Dijkstra's function: " << duration_d.count() << " microseconds" << std::endl;
return 0;
}