-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-dijkstra.cpp
67 lines (54 loc) · 1.48 KB
/
demo-dijkstra.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
#include <iostream>
#include <vector>
#include <boost/progress.hpp>
#include <egraph/Graph.h>
#include <egraph/routing/PathTreeBuilder.h>
#include <boost/timer.hpp>
using namespace egraph;
using namespace egraph::routing;
int main(int argc, char *argv[])
{
using graph_type = Graph<int, double>;
using vertex_descriptor = graph_type::vertex_descriptor;
using edge_descriptor = graph_type::edge_descriptor;
graph_type g;
std::vector<vertex_descriptor> vertices;
const int N = 1000000;
boost::progress_display display(N);
for (int i = 0; i < N; i++)
{
vertices.push_back(boost::add_vertex(i, g));
if (i != 0)
{
boost::add_edge(vertices[i - 1], vertices[i], 2.5 * i, g);
}
++display;
}
std::cout << "building tree..." << std::endl;
vertex_descriptor origin = vertices[1];
PathTree<graph_type> pathTree(g);
pathTree.setRoot(origin);
PathTreeBuilder<graph_type> builder(pathTree);
builder.build();
/* retreive path */
vertex_descriptor destination = vertices[20];
std::vector<edge_descriptor> path = pathTree.path(destination);
/* display path */
{
vertex_descriptor last = origin;
for (const edge_descriptor &e : path)
{
if (last == boost::source(e, g))
{
std::cout << "(" << boost::source(e, g) << " -> " << boost::target(e, g) << ")" << std::endl;
last = boost::target(e, g);
}
else
{
std::cout << "(" << boost::target(e, g) << " -> " << boost::source(e, g) << ")" << std::endl;
last = boost::source(e, g);
}
}
}
return 0;
}