forked from cmuparlay/parlaylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
le_list.cpp
60 lines (52 loc) · 1.75 KB
/
le_list.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
#include <iostream>
#include <string>
#include <parlay/primitives.h>
#include <parlay/sequence.h>
#include <parlay/internal/get_time.h>
using distance = int;
using vertex = int;
#include "le_list.h"
#include "helper/graph_utils.h"
// **************************************************************
// Driver
// **************************************************************
using result = parlay::sequence<parlay::sequence<std::pair<vertex, distance>>>;
using graph = parlay::sequence<parlay::sequence<vertex>>;
using utils = graph_utils<vertex>;
int main(int argc, char* argv[]) {
auto usage = "Usage: le_list <n> || le_list <filename>";
if (argc != 2) std::cout << usage << std::endl;
else {
long n = 0;
graph G, GT;
try { n = std::stol(argv[1]); }
catch (...) {}
if (n == 0) {
G = utils::read_symmetric_graph_from_file(argv[1]);
GT = G;
n = G.size();
} else {
G = utils::rmat_graph(n, 20*n);
GT = utils::transpose(G);
}
int seed = 15210;
parlay::random_generator gen(seed);
std::uniform_real_distribution<> dis(0.0,1.0);
// Psuedorandom priorities for the vertices
auto R = tabulate(n, [&] (vertex i) {
auto g = gen[i]; return dis(g); });
// generate ordering based on priorities
auto verts = tabulate(n, [&] (vertex i) { return i;});
auto order = stable_sort(verts, [&] (vertex u, vertex v) {
return R[u] < R[v];});
utils::print_graph_stats(G);
result result;
parlay::internal::timer t("Time");
for (int i=0; i < 5; i++) {
result = create_le_list(G, GT, order);
t.next("le_list");
}
long total = reduce(map(result, parlay::size_of()));
std::cout << "Average LE-list size: " << ((double) total / (double) n) << std::endl;
}
}