-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemon_dijkstra_path.cpp
69 lines (62 loc) · 1.63 KB
/
lemon_dijkstra_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
#include <iostream>
#include <lemon/list_graph.h>
#include <lemon/dijkstra.h>
using namespace lemon;
using namespace std;
enum family {
Jeanie,
Debbie,
Rick,
John,
Amanda,
Margaret,
Benjamin,
N
};
int main() {
ListGraph g;
for (int i = 0; i < N; i++)
g.addNode();
ListGraph::NodeMap<family> families(g);
ListGraph::NodeIt it(g);
families[it] = Jeanie;
ListGraph::NodeIt jeanie = it;
++it;
families[it] = Debbie;
ListGraph::NodeIt debbie = it;
++it;
g.addEdge(jeanie, debbie);
families[it] = Amanda;
ListGraph::NodeIt amanda = it;
++it;
g.addEdge(debbie, amanda);
families[it] = Rick;
ListGraph::NodeIt rick = it;
++it;
g.addEdge(jeanie, rick);
families[it] = Margaret;
ListGraph::NodeIt margaret = it;
++it;
g.addEdge(margaret, rick);
families[it] = John;
ListGraph::NodeIt john = it;
++it;
g.addEdge(jeanie, john);
families[it] = Benjamin;
ListGraph::NodeIt benjamin = it;
g.addEdge(benjamin, john);
//arcs are necessary to use
ListGraph::ArcMap<int> lengthMap(g);
for (ListGraph::ArcIt it(g); it != INVALID; ++it)
lengthMap[it] = 1;
ListGraph::NodeMap<int> distMapo(g);
ListGraph::NodeMap<ListGraph::Arc> predMapo(g);
Dijkstra<ListGraph, ListGraph::ArcMap<int>> d(g, lengthMap);
d.init();
d.addSource(jeanie);
d.start();
Dijkstra<ListGraph, ListGraph::ArcMap<int>>::Path p = d.path(amanda);
for (Dijkstra<ListGraph, ListGraph::ArcMap<int>>::Path::RevArcIt it(p); it != INVALID; ++it)
std::cout << families[g.source(it)];
return 0;
}