1
//=======================================================================
2
// Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
4
// Distributed under the Boost Software License, Version 1.0. (See
5
// accompanying file LICENSE_1_0.txt or copy at
6
// http://www.boost.org/LICENSE_1_0.txt)
7
//=======================================================================
8
#include <boost/config.hpp>
10
#include <boost/graph/adjacency_list.hpp>
11
#include <boost/graph/prim_minimum_spanning_tree.hpp>
16
using namespace boost;
17
typedef adjacency_list < vecS, vecS, undirectedS,
18
property<vertex_distance_t, int>, property < edge_weight_t, int > > Graph;
19
typedef std::pair < int, int >E;
20
const int num_nodes = 5;
21
E edges[] = { E(0, 2), E(1, 3), E(1, 4), E(2, 1), E(2, 3),
24
int weights[] = { 1, 1, 2, 7, 3, 1, 1 };
25
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
27
property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, g);
28
for (std::size_t j = 0; j < sizeof(edges) / sizeof(E); ++j) {
29
graph_traits<Graph>::edge_descriptor e; bool inserted;
30
boost::tie(e, inserted) = add_edge(edges[j].first, edges[j].second, g);
31
weightmap[e] = weights[j];
34
Graph g(edges, edges + sizeof(edges) / sizeof(E), weights, num_nodes);
35
property_map<Graph, edge_weight_t>::type weightmap = get(edge_weight, g);
37
std::vector < graph_traits < Graph >::vertex_descriptor >
40
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
41
property_map<Graph, vertex_distance_t>::type distance = get(vertex_distance, g);
42
property_map<Graph, vertex_index_t>::type indexmap = get(vertex_index, g);
43
prim_minimum_spanning_tree
44
(g, *vertices(g).first, &p[0], distance, weightmap, indexmap,
45
default_dijkstra_visitor());
47
prim_minimum_spanning_tree(g, &p[0]);
50
for (std::size_t i = 0; i != p.size(); ++i)
52
std::cout << "parent[" << i << "] = " << p[i] << std::endl;
54
std::cout << "parent[" << i << "] = no parent" << std::endl;