]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | //======================================================================= |
f67539c2 | 2 | // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, |
7c673cae FG |
3 | // |
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 | //======================================================================= | |
92f5a8d4 TL |
8 | |
9 | /* | |
10 | IMPORTANT!!! | |
11 | ~~~~~~~~~~~~ | |
f67539c2 TL |
12 | This example uses interfaces that have been deprecated and removed from |
13 | Boost.Grpah. Someone needs to update it, as it does NOT compile. | |
92f5a8d4 TL |
14 | */ |
15 | ||
7c673cae FG |
16 | #include <boost/config.hpp> |
17 | #include <iostream> | |
18 | #include <fstream> | |
19 | #include <boost/lexical_cast.hpp> | |
20 | #include <boost/graph/graphviz.hpp> | |
21 | #include <boost/graph/kruskal_min_spanning_tree.hpp> | |
22 | ||
f67539c2 | 23 | int main() |
7c673cae | 24 | { |
f67539c2 TL |
25 | using namespace boost; |
26 | GraphvizGraph g_dot; | |
27 | read_graphviz("figs/telephone-network.dot", g_dot); | |
7c673cae | 28 | |
f67539c2 TL |
29 | typedef adjacency_list< vecS, vecS, undirectedS, no_property, |
30 | property< edge_weight_t, int > > | |
31 | Graph; | |
32 | Graph g(num_vertices(g_dot)); | |
33 | property_map< GraphvizGraph, edge_attribute_t >::type edge_attr_map | |
34 | = get(edge_attribute, g_dot); | |
35 | graph_traits< GraphvizGraph >::edge_iterator ei, ei_end; | |
36 | for (boost::tie(ei, ei_end) = edges(g_dot); ei != ei_end; ++ei) | |
37 | { | |
38 | int weight = lexical_cast< int >(edge_attr_map[*ei]["label"]); | |
39 | property< edge_weight_t, int > edge_property(weight); | |
40 | add_edge(source(*ei, g_dot), target(*ei, g_dot), edge_property, g); | |
41 | } | |
7c673cae | 42 | |
f67539c2 TL |
43 | std::vector< graph_traits< Graph >::edge_descriptor > mst; |
44 | typedef std::vector< graph_traits< Graph >::edge_descriptor >::size_type | |
45 | size_type; | |
46 | kruskal_minimum_spanning_tree(g, std::back_inserter(mst)); | |
7c673cae | 47 | |
f67539c2 TL |
48 | property_map< Graph, edge_weight_t >::type weight = get(edge_weight, g); |
49 | int total_weight = 0; | |
50 | for (size_type e = 0; e < mst.size(); ++e) | |
51 | total_weight += get(weight, mst[e]); | |
52 | std::cout << "total weight: " << total_weight << std::endl; | |
7c673cae | 53 | |
f67539c2 TL |
54 | typedef graph_traits< Graph >::vertex_descriptor Vertex; |
55 | for (size_type i = 0; i < mst.size(); ++i) | |
56 | { | |
57 | Vertex u = source(mst[i], g), v = target(mst[i], g); | |
58 | edge_attr_map[edge(u, v, g_dot).first]["color"] = "black"; | |
59 | } | |
60 | std::ofstream out("figs/telephone-mst-kruskal.dot"); | |
61 | graph_property< GraphvizGraph, graph_edge_attribute_t >::type& | |
62 | graph_edge_attr_map | |
63 | = get_property(g_dot, graph_edge_attribute); | |
64 | graph_edge_attr_map["color"] = "gray"; | |
65 | graph_edge_attr_map["style"] = "bold"; | |
66 | write_graphviz(out, g_dot); | |
7c673cae | 67 | |
f67539c2 | 68 | return EXIT_SUCCESS; |
7c673cae | 69 | } |