-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_seq_shortest_path.cpp
96 lines (79 loc) · 3.1 KB
/
test_seq_shortest_path.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
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by Kevin on 18/05/2023.
//
#include <chrono>
#include "src/graph_gen.h"
#include "src/deltastep_seq.h"
#include "src/seq_shortest_path.h"
#include <cstring>
int main(const int argc, char* argv[]) {
if (argc < 4) {
std::cerr << "Usage: ./seq_shortest_path <path_to_graph_file> <source_vertex> <destination_vertex>" << std::endl;
return -1;
}
bool is_verbose = false;
if (argc == 5)
{
if (strcmp(argv[4], "-v") == 0)
{
is_verbose = true;
}
}
// Get the arguments
const std::string path = argv[1];
const int source_vertex = strtol(argv[2], nullptr, 10);
const int destination_vertex = strtol(argv[3], nullptr, 10);
Graph graph = GraphGenerator::loadGraphs(path)[0];
if (is_verbose)
{
graph.printGraph();
graph.printAdjList();
}
std::cout << "--------------------------------------------------" << std::endl;
if (source_vertex < 0 || source_vertex >= graph.getGraphNbVertices())
{
std::cerr << "[ERROR] Source vertex is out of bounds" << std::endl;
return -1;
}
//auto delta_step_seq = DeltaStepSequential(graph, source_vertex, is_verbose);
//auto start = std::chrono::high_resolution_clock::now();
//delta_step_seq.solve();
//auto end = std::chrono::high_resolution_clock::now();
//auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
//std::cout << std::endl << "Basic Delta Step solution: " << std::endl;
//delta_step_seq.print_solution();
//std::cout << "Solving time for Basic Delta Step Sequential: " << duration.count() << " microseconds" << std::endl;
auto delta_step_seq_lh = DeltaStepSequential(graph, source_vertex);
auto start = std::chrono::high_resolution_clock::now();
delta_step_seq_lh.solve_light_heavy();
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
//std::cout << std::endl << "Light Heavy Delta Step solution: " << std::endl;
//delta_step_seq_lh.print_solution();
std::cout << "Solving time for Light Heavy Delta Step Sequential: " << duration.count() << " microseconds" << std::endl;
start = std::chrono::high_resolution_clock::now();
const std::vector<double> dijkstra_sol = DijkstraFibonacciHeap::dijkstra(graph, source_vertex, destination_vertex);
end = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "Solving time for DijkstraFibonacciHeap: " << duration.count() << " microseconds" << std::endl;
// Check the correctness of the solution:
int is_correct_counter = 0;
for (int i = 0; i < graph.getGraphNbVertices(); i++)
{
if (delta_step_seq_lh.get_dist(i) != dijkstra_sol[i])
{
++is_correct_counter;
std::cout << "Delta Step solution is not correct" << std::endl;
std::cout << "Vertex " << i << " has distance " << delta_step_seq_lh.get_dist(i) << " instead of " << dijkstra_sol[i] << std::endl;
}
}
if (is_correct_counter == 0)
{
std::cout << "Delta Step solution is correct!" << std::endl;
}
else
{
std::cout << "Delta Step solution is not correct for " << is_correct_counter << " value(s)." << std::endl;
}
return 0;
}