Ticket #4731: bug.cpp

File bug.cpp, 1.1 KB (added by Markus Pilman <mpilman@…>, 12 years ago)

Implementation of the example described in the bug report

Line 
1#include <iostream>
2#include <boost/graph/adjacency_list.hpp>
3#include <boost/graph/dijkstra_shortest_paths.hpp>
4#include <boost/graph/prim_minimum_spanning_tree.hpp>
5
6using namespace std;
7using namespace boost;
8
9typedef adjacency_list<vecS, vecS, undirectedS,
10 no_property, property<edge_weight_t, int> > Graph;
11typedef graph_traits<Graph>::vertex_descriptor Vertex;
12typedef graph_traits<Graph>::edge_descriptor Edge;
13typedef property_map<Graph, edge_weight_t>::type WeightMap;
14
15int main() {
16 Graph g(3);
17 WeightMap m = get(edge_weight, g);
18 bool success;
19 Edge e;
20 tie(e, success) = add_edge(0, 1, g);
21 m[e] = 2;
22 tie(e, success) = add_edge(0, 2, g);
23 m[e] = 3;
24 tie(e, success) = add_edge(1, 2, g);
25 m[e] = 4;
26
27 int startPoint = 2;
28 vector<Vertex> p(3);
29 dijkstra_shortest_paths(g, startPoint, predecessor_map(&p[0]));
30
31 cout << "Dijkstra:" << endl;
32 cout << p[0] << " " << p[1] << " " << p[2] << endl;
33 prim_minimum_spanning_tree(g, &p[0], root_vertex(startPoint));
34 cout << "Prim:" << endl;
35 cout << p[0] << " " << p[1] << " " << p[2] << endl;
36}