1 | //======================================================================= |
---|
2 | // Copyright 2002 Indiana University. |
---|
3 | // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek |
---|
4 | // |
---|
5 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
6 | // accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | //======================================================================= |
---|
9 | |
---|
10 | #include <boost/config.hpp> |
---|
11 | #include <boost/concept_archetype.hpp> |
---|
12 | #include <boost/graph/dijkstra_shortest_paths.hpp> |
---|
13 | #include <boost/graph/graph_archetypes.hpp> |
---|
14 | |
---|
15 | typedef boost::default_constructible_archetype< |
---|
16 | boost::sgi_assignable_archetype<> > dist_value; |
---|
17 | |
---|
18 | // So generate_infinity works... |
---|
19 | namespace std { |
---|
20 | template <> |
---|
21 | class numeric_limits<dist_value> { |
---|
22 | public: |
---|
23 | static dist_value max BOOST_PREVENT_MACRO_SUBSTITUTION () { |
---|
24 | return boost::static_object<dist_value>::get(); |
---|
25 | } |
---|
26 | }; |
---|
27 | } |
---|
28 | |
---|
29 | dist_value abs(const dist_value& x) { return x; } |
---|
30 | std::size_t abs(std::size_t x) { return x; } |
---|
31 | |
---|
32 | int main() |
---|
33 | { |
---|
34 | using namespace boost; |
---|
35 | typedef default_constructible_archetype< |
---|
36 | sgi_assignable_archetype< |
---|
37 | equality_comparable_archetype<> > > vertex_t; |
---|
38 | { |
---|
39 | typedef incidence_graph_archetype<vertex_t, directed_tag, |
---|
40 | allow_parallel_edge_tag> IncidenceGraph; |
---|
41 | typedef vertex_list_graph_archetype<vertex_t, directed_tag, |
---|
42 | allow_parallel_edge_tag, IncidenceGraph> graph_t; |
---|
43 | graph_t& g = static_object<graph_t>::get(); |
---|
44 | vertex_t s; |
---|
45 | typedef graph_traits<graph_t>::edge_descriptor edge_t; |
---|
46 | readable_property_map_archetype<edge_t, std::size_t> weight; |
---|
47 | readable_property_map_archetype<vertex_t, int> index; |
---|
48 | read_write_property_map_archetype<vertex_t, std::size_t> distance; |
---|
49 | dijkstra_shortest_paths(g, s, |
---|
50 | vertex_index_map(index). |
---|
51 | weight_map(weight). |
---|
52 | distance_map(distance)); |
---|
53 | } |
---|
54 | { |
---|
55 | typedef incidence_graph_archetype<vertex_t, directed_tag, |
---|
56 | allow_parallel_edge_tag> IncidenceGraph; |
---|
57 | typedef vertex_list_graph_archetype<vertex_t, directed_tag, |
---|
58 | allow_parallel_edge_tag, IncidenceGraph> Graph; |
---|
59 | vertex_t s; |
---|
60 | typedef graph_traits<Graph>::edge_descriptor edge_t; |
---|
61 | readable_property_map_archetype<edge_t, std::size_t> weight; |
---|
62 | typedef property_graph_archetype<Graph, vertex_index_t, std::size_t> |
---|
63 | graph_t; |
---|
64 | graph_t& g = static_object<graph_t>::get(); |
---|
65 | read_write_property_map_archetype<vertex_t, vertex_t> pred; |
---|
66 | dijkstra_shortest_paths(g, s, |
---|
67 | predecessor_map(pred). |
---|
68 | weight_map(weight)); |
---|
69 | } |
---|
70 | { |
---|
71 | typedef incidence_graph_archetype<vertex_t, directed_tag, |
---|
72 | allow_parallel_edge_tag> IncidenceGraph; |
---|
73 | typedef vertex_list_graph_archetype<vertex_t, directed_tag, |
---|
74 | allow_parallel_edge_tag, IncidenceGraph> Graph; |
---|
75 | vertex_t s; |
---|
76 | typedef property_graph_archetype<Graph, edge_weight_t, std::size_t> |
---|
77 | graph_t; |
---|
78 | graph_t& g = static_object<graph_t>::get(); |
---|
79 | read_write_property_map_archetype<vertex_t, vertex_t> pred; |
---|
80 | readable_property_map_archetype<vertex_t, int> index; |
---|
81 | dijkstra_shortest_paths(g, s, |
---|
82 | predecessor_map(pred). |
---|
83 | vertex_index_map(index)); |
---|
84 | } |
---|
85 | { |
---|
86 | typedef incidence_graph_archetype<vertex_t, directed_tag, |
---|
87 | allow_parallel_edge_tag> IncidenceGraph; |
---|
88 | typedef vertex_list_graph_archetype<vertex_t, directed_tag, |
---|
89 | allow_parallel_edge_tag, IncidenceGraph> graph_t; |
---|
90 | graph_t& g = static_object<graph_t>::get(); |
---|
91 | vertex_t s; |
---|
92 | typedef graph_traits<graph_t>::edge_descriptor edge_t; |
---|
93 | readable_property_map_archetype<edge_t, dist_value> weight; |
---|
94 | readable_property_map_archetype<vertex_t, int> index; |
---|
95 | read_write_property_map_archetype<vertex_t, color_value_archetype> color; |
---|
96 | read_write_property_map_archetype<vertex_t, dist_value> distance; |
---|
97 | typedef binary_function_archetype<dist_value, dist_value, dist_value> |
---|
98 | Combine; |
---|
99 | Combine combine = static_object<Combine>::get(); |
---|
100 | typedef binary_predicate_archetype<dist_value, dist_value> |
---|
101 | Compare; |
---|
102 | Compare compare = static_object<Compare>::get(); |
---|
103 | dijkstra_visitor<> vis; |
---|
104 | |
---|
105 | dijkstra_shortest_paths(g, s, color_map(color). |
---|
106 | vertex_index_map(index). |
---|
107 | weight_map(weight). |
---|
108 | distance_map(distance). |
---|
109 | distance_combine(combine). |
---|
110 | distance_compare(compare). |
---|
111 | visitor(vis)); |
---|
112 | } |
---|
113 | return 0; |
---|
114 | } |
---|