1 | //======================================================================= |
2 | // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, |
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 | //======================================================================= |
8 | |
9 | #include <boost/config.hpp> |
10 | #include <iostream> |
11 | #include <fstream> |
12 | #include <boost/graph/adjacency_list.hpp> |
13 | |
14 | using namespace boost; |
15 | |
16 | template < typename VertexDescriptor, typename VertexNameMap > |
17 | void print_vertex_name(VertexDescriptor v, VertexNameMap name_map) |
18 | { |
19 | std::cout << get(name_map, v); |
20 | } |
21 | |
22 | template < typename Graph, typename TransDelayMap, typename VertexNameMap > |
23 | void print_trans_delay(typename graph_traits< Graph >::edge_descriptor e, |
24 | const Graph& g, TransDelayMap delay_map, VertexNameMap name_map) |
25 | { |
26 | std::cout << "trans-delay(" << get(name_map, source(e, g)) << "," |
27 | << get(name_map, target(e, g)) << ") = " << get(delay_map, e); |
28 | } |
29 | |
30 | template < typename Graph, typename VertexNameMap > |
31 | void print_vertex_names(const Graph& g, VertexNameMap name_map) |
32 | { |
33 | std::cout << "vertices(g) = { " ; |
34 | typedef typename graph_traits< Graph >::vertex_iterator iter_t; |
35 | for (std::pair< iter_t, iter_t > p = vertices(g); p.first != p.second; |
36 | ++p.first) |
37 | { |
38 | print_vertex_name(*p.first, name_map); |
39 | std::cout << ' '; |
40 | } |
41 | std::cout << "}" << std::endl; |
42 | } |
43 | |
44 | template < typename Graph, typename TransDelayMap, typename VertexNameMap > |
45 | void print_trans_delays( |
46 | const Graph& g, TransDelayMap trans_delay_map, VertexNameMap name_map) |
47 | { |
48 | typename graph_traits< Graph >::edge_iterator first, last; |
49 | for (boost::tie(first, last) = edges(g); first != last; ++first) |
50 | { |
51 | print_trans_delay(*first, g, trans_delay_map, name_map); |
52 | std::cout << std::endl; |
53 | } |
54 | } |
55 | |
56 | template < typename Graph, typename VertexNameMap, typename TransDelayMap > |
57 | void build_router_network( |
58 | Graph& g, VertexNameMap name_map, TransDelayMap delay_map) |
59 | { |
60 | typename graph_traits< Graph >::vertex_descriptor a, b, c, d, e; |
61 | a = add_vertex(g); |
62 | name_map[a] = 'a'; |
63 | b = add_vertex(g); |
64 | name_map[b] = 'b'; |
65 | c = add_vertex(g); |
66 | name_map[c] = 'c'; |
67 | d = add_vertex(g); |
68 | name_map[d] = 'd'; |
69 | e = add_vertex(g); |
70 | name_map[e] = 'e'; |
71 | |
72 | typename graph_traits< Graph >::edge_descriptor ed; |
73 | bool inserted; |
74 | |
75 | boost::tie(ed, inserted) = add_edge(a, b, g); |
76 | delay_map[ed] = 1.2; |
77 | boost::tie(ed, inserted) = add_edge(a, d, g); |
78 | delay_map[ed] = 4.5; |
79 | boost::tie(ed, inserted) = add_edge(b, d, g); |
80 | delay_map[ed] = 1.8; |
81 | boost::tie(ed, inserted) = add_edge(c, a, g); |
82 | delay_map[ed] = 2.6; |
83 | boost::tie(ed, inserted) = add_edge(c, e, g); |
84 | delay_map[ed] = 5.2; |
85 | boost::tie(ed, inserted) = add_edge(d, c, g); |
86 | delay_map[ed] = 0.4; |
87 | boost::tie(ed, inserted) = add_edge(d, e, g); |
88 | delay_map[ed] = 3.3; |
89 | } |
90 | |
91 | int main() |
92 | { |
93 | typedef adjacency_list< listS, listS, directedS, |
94 | property< vertex_name_t, char >, property< edge_weight_t, double > > |
95 | graph_t; |
96 | graph_t g; |
97 | |
98 | property_map< graph_t, vertex_name_t >::type name_map = get(p: vertex_name, g); |
99 | property_map< graph_t, edge_weight_t >::type delay_map |
100 | = get(p: edge_weight, g); |
101 | |
102 | build_router_network(g, name_map, delay_map); |
103 | print_vertex_names(g, name_map); |
104 | print_trans_delays(g, trans_delay_map: delay_map, name_map); |
105 | } |
106 | |