forked from gunrock/essentials-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsssp.cpp
63 lines (49 loc) · 1.38 KB
/
sssp.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
/**
* @file sssp.cpp
* @author Muhammad Osama ([email protected])
* @brief Test driver for SSSP implementation.
* @see include/sssp.hxx
*
* @version 0.1
*
* @copyright Copyright (c) 2022
*
*/
#include <vector>
#include <string>
#include <iostream>
#include <load.hxx>
#include <validate.hxx>
#include <sssp.hxx>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "usage: ./bin/<program-name> filename.mtx" << std::endl;
exit(1);
}
// --
// Define types
using vertex_t = int;
using edge_t = int;
using weight_t = float;
// --
// Build graph
std::string filename = argv[1];
essentials::matrix_market_t<vertex_t, edge_t, weight_t> mm(filename);
essentials::graph_t<vertex_t, edge_t, weight_t> graph(
mm.num_rows, mm.num_columns, mm.num_nonzeros, mm.Ap, mm.Aj, mm.Ax);
// --
// Params and memory allocation
vertex_t n_vertices = graph.get_num_vertices();
vertex_t single_source = 0;
std::vector<weight_t> distances = essentials::sssp(graph, single_source);
// --
// Validate
int n_errors =
essentials::validate(n_vertices, graph.row_offsets, graph.column_indices,
graph.values, single_source, distances);
std::cout << "Distances : ";
for (const auto& d : distances)
std::cout << d << ' ';
std::cout << std::endl;
std::cout << "Number of errors : " << n_errors << std::endl;
}