Ticket #4737: Example.cpp

File Example.cpp, 1.2 KB (added by nicoe@…, 12 years ago)
Line 
1#include <cassert>
2#include <iostream>
3#include <boost/config.hpp>
4#include <boost/graph/adjacency_list.hpp>
5#include <boost/graph/prim_minimum_spanning_tree.hpp>
6
7using namespace std;
8using namespace boost;
9
10typedef adjacency_list<vecS, vecS, undirectedS, 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{
17 bool success;
18 Graph g(3);
19 weightMap weights = get(edge_weight, g);
20 Edge e;
21 tie(e, success) = add_edge(0, 1, g);
22 assert (success);
23 weights[e] = 2;
24 tie(e, success) = add_edge(0, 2, g);
25 assert (success);
26 weights[e] = 3;
27 tie(e, success) = add_edge(1, 2, g);
28 assert (success);
29 weights[e] = 4;
30
31 std::vector<Vertex> predecessors(num_vertices(g));
32 std::vector<int> distances(num_vertices(g));
33
34 prim_minimum_spanning_tree(g, &predecessors[0], root_vertex(1).distance_map(&distances[0]));
35
36 for (int i = 0; i < 3; ++ i) {
37 cout << distances[i] << endl;
38 }
39
40 //Expected output 2,0,5, but is 2,0,3
41
42 return 0;
43}
44