Chris@16
|
1 // (C) Copyright 2007-2009 Andrew Sutton
|
Chris@16
|
2 //
|
Chris@16
|
3 // Use, modification and distribution are subject to the
|
Chris@16
|
4 // Boost Software License, Version 1.0 (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 #ifndef BOOST_GRAPH_UNDIRECTED_GRAPH_HPP
|
Chris@16
|
8 #define BOOST_GRAPH_UNDIRECTED_GRAPH_HPP
|
Chris@16
|
9
|
Chris@16
|
10 #include <boost/graph/adjacency_list.hpp>
|
Chris@16
|
11 #include <boost/graph/properties.hpp>
|
Chris@16
|
12 #include <boost/pending/property.hpp>
|
Chris@16
|
13 #include <boost/property_map/transform_value_property_map.hpp>
|
Chris@16
|
14 #include <boost/type_traits.hpp>
|
Chris@16
|
15 #include <boost/mpl/if.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost
|
Chris@16
|
18 {
|
Chris@16
|
19 struct undirected_graph_tag { };
|
Chris@16
|
20
|
Chris@16
|
21 /**
|
Chris@16
|
22 * The undirected_graph class template is a simplified version of the BGL
|
Chris@16
|
23 * adjacency list. This class is provided for ease of use, but may not
|
Chris@16
|
24 * perform as well as custom-defined adjacency list classes. Instances of
|
Chris@16
|
25 * this template model the VertexIndexGraph, and EdgeIndexGraph concepts. The
|
Chris@16
|
26 * graph is also fully mutable, supporting both insertions and removals of
|
Chris@16
|
27 * vertices and edges.
|
Chris@16
|
28 *
|
Chris@16
|
29 * @note Special care must be taken when removing vertices or edges since
|
Chris@16
|
30 * those operations can invalidate the numbering of vertices.
|
Chris@16
|
31 */
|
Chris@16
|
32 template <
|
Chris@16
|
33 typename VertexProp = no_property,
|
Chris@16
|
34 typename EdgeProp = no_property,
|
Chris@16
|
35 typename GraphProp = no_property>
|
Chris@16
|
36 class undirected_graph
|
Chris@16
|
37 {
|
Chris@16
|
38 public:
|
Chris@16
|
39 typedef GraphProp graph_property_type;
|
Chris@16
|
40 typedef VertexProp vertex_property_type;
|
Chris@16
|
41 typedef EdgeProp edge_property_type;
|
Chris@16
|
42 typedef typename lookup_one_property<GraphProp, graph_bundle_t>::type graph_bundled;
|
Chris@16
|
43 typedef typename lookup_one_property<VertexProp, vertex_bundle_t>::type vertex_bundled;
|
Chris@16
|
44 typedef typename lookup_one_property<EdgeProp, edge_bundle_t>::type edge_bundled;
|
Chris@16
|
45
|
Chris@16
|
46 public:
|
Chris@16
|
47 // Embed indices into the vertex type.
|
Chris@16
|
48 typedef property<vertex_index_t, unsigned, vertex_property_type> internal_vertex_property;
|
Chris@16
|
49 typedef property<edge_index_t, unsigned, edge_property_type> internal_edge_property;
|
Chris@16
|
50 public:
|
Chris@16
|
51 typedef adjacency_list<listS,
|
Chris@16
|
52 listS,
|
Chris@16
|
53 undirectedS,
|
Chris@16
|
54 internal_vertex_property,
|
Chris@16
|
55 internal_edge_property,
|
Chris@16
|
56 GraphProp,
|
Chris@16
|
57 listS> graph_type;
|
Chris@16
|
58 private:
|
Chris@16
|
59 // storage selectors
|
Chris@16
|
60 typedef typename graph_type::vertex_list_selector vertex_list_selector;
|
Chris@16
|
61 typedef typename graph_type::edge_list_selector edge_list_selector;
|
Chris@16
|
62 typedef typename graph_type::out_edge_list_selector out_edge_list_selector;
|
Chris@16
|
63 typedef typename graph_type::directed_selector directed_selector;
|
Chris@16
|
64
|
Chris@16
|
65 public:
|
Chris@16
|
66 // more commonly used graph types
|
Chris@16
|
67 typedef typename graph_type::stored_vertex stored_vertex;
|
Chris@16
|
68 typedef typename graph_type::vertices_size_type vertices_size_type;
|
Chris@16
|
69 typedef typename graph_type::edges_size_type edges_size_type;
|
Chris@16
|
70 typedef typename graph_type::degree_size_type degree_size_type;
|
Chris@16
|
71 typedef typename graph_type::vertex_descriptor vertex_descriptor;
|
Chris@16
|
72 typedef typename graph_type::edge_descriptor edge_descriptor;
|
Chris@16
|
73
|
Chris@16
|
74 // iterator types
|
Chris@16
|
75 typedef typename graph_type::vertex_iterator vertex_iterator;
|
Chris@16
|
76 typedef typename graph_type::edge_iterator edge_iterator;
|
Chris@16
|
77 typedef typename graph_type::out_edge_iterator out_edge_iterator;
|
Chris@16
|
78 typedef typename graph_type::in_edge_iterator in_edge_iterator;
|
Chris@16
|
79 typedef typename graph_type::adjacency_iterator adjacency_iterator;
|
Chris@16
|
80
|
Chris@16
|
81 // miscellaneous types
|
Chris@16
|
82 typedef undirected_graph_tag graph_tag;
|
Chris@16
|
83 typedef typename graph_type::directed_category directed_category;
|
Chris@16
|
84 typedef typename graph_type::edge_parallel_category edge_parallel_category;
|
Chris@16
|
85 typedef typename graph_type::traversal_category traversal_category;
|
Chris@16
|
86
|
Chris@16
|
87 typedef std::size_t vertex_index_type;
|
Chris@16
|
88 typedef std::size_t edge_index_type;
|
Chris@16
|
89
|
Chris@16
|
90 inline undirected_graph(GraphProp const& p = GraphProp())
|
Chris@16
|
91 : m_graph(p), m_num_vertices(0), m_num_edges(0), m_max_vertex_index(0)
|
Chris@16
|
92 , m_max_edge_index(0)
|
Chris@16
|
93 { }
|
Chris@16
|
94
|
Chris@16
|
95 inline undirected_graph(undirected_graph const& x)
|
Chris@16
|
96 : m_graph(x.m_graph), m_num_vertices(x.m_num_vertices), m_num_edges(x.m_num_edges)
|
Chris@16
|
97 , m_max_vertex_index(x.m_max_vertex_index), m_max_edge_index(x.m_max_edge_index)
|
Chris@16
|
98 { }
|
Chris@16
|
99
|
Chris@16
|
100 inline undirected_graph(vertices_size_type n,
|
Chris@16
|
101 GraphProp const& p = GraphProp())
|
Chris@16
|
102 : m_graph(n, p), m_num_vertices(n), m_num_edges(0), m_max_vertex_index(n)
|
Chris@16
|
103 , m_max_edge_index(0)
|
Chris@16
|
104 { renumber_vertex_indices(); }
|
Chris@16
|
105
|
Chris@16
|
106 template <typename EdgeIterator>
|
Chris@16
|
107 inline undirected_graph(EdgeIterator f,
|
Chris@16
|
108 EdgeIterator l,
|
Chris@16
|
109 vertices_size_type n,
|
Chris@16
|
110 edges_size_type m = 0,
|
Chris@16
|
111 GraphProp const& p = GraphProp())
|
Chris@16
|
112 : m_graph(f, l, n, m, p), m_num_vertices(n), m_num_edges(0)
|
Chris@16
|
113 , m_max_vertex_index(n), m_max_edge_index(0)
|
Chris@16
|
114 {
|
Chris@16
|
115 // Unfortunately, we have to renumber to ensure correct indexing.
|
Chris@16
|
116 renumber_indices();
|
Chris@16
|
117
|
Chris@16
|
118 // Can't always guarantee that the number of edges is actually
|
Chris@16
|
119 // m if distance(f, l) != m (or is undefined).
|
Chris@16
|
120 m_num_edges = m_max_edge_index = boost::num_edges(m_graph);
|
Chris@16
|
121 }
|
Chris@16
|
122
|
Chris@16
|
123 undirected_graph& operator =(undirected_graph const& g) {
|
Chris@16
|
124 if(&g != this) {
|
Chris@16
|
125 m_graph = g.m_graph;
|
Chris@16
|
126 m_num_vertices = g.m_num_vertices;
|
Chris@16
|
127 m_num_edges = g.m_num_edges;
|
Chris@16
|
128 m_max_vertex_index = g.m_max_vertex_index;
|
Chris@16
|
129 }
|
Chris@16
|
130 return *this;
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 // The impl_() methods are not part of the public interface.
|
Chris@16
|
134 graph_type& impl()
|
Chris@16
|
135 { return m_graph; }
|
Chris@16
|
136
|
Chris@16
|
137 graph_type const& impl() const
|
Chris@16
|
138 { return m_graph; }
|
Chris@16
|
139
|
Chris@16
|
140 // The following methods are not part of the public interface
|
Chris@16
|
141 vertices_size_type num_vertices() const
|
Chris@16
|
142 { return m_num_vertices; }
|
Chris@16
|
143
|
Chris@16
|
144
|
Chris@16
|
145 private:
|
Chris@16
|
146 // This helper function manages the attribution of vertex indices.
|
Chris@16
|
147 vertex_descriptor make_index(vertex_descriptor v) {
|
Chris@16
|
148 boost::put(vertex_index, m_graph, v, m_max_vertex_index);
|
Chris@16
|
149 m_num_vertices++;
|
Chris@16
|
150 m_max_vertex_index++;
|
Chris@16
|
151 return v;
|
Chris@16
|
152 }
|
Chris@16
|
153 public:
|
Chris@16
|
154 vertex_descriptor add_vertex()
|
Chris@16
|
155 { return make_index(boost::add_vertex(m_graph)); }
|
Chris@16
|
156
|
Chris@16
|
157 vertex_descriptor add_vertex(vertex_property_type const& p)
|
Chris@16
|
158 { return make_index(boost::add_vertex(internal_vertex_property(0u, p), m_graph)); }
|
Chris@16
|
159
|
Chris@16
|
160 void clear_vertex(vertex_descriptor v) {
|
Chris@16
|
161 std::pair<out_edge_iterator, out_edge_iterator>
|
Chris@16
|
162 p = boost::out_edges(v, m_graph);
|
Chris@16
|
163 m_num_edges -= std::distance(p.first, p.second);
|
Chris@16
|
164 boost::clear_vertex(v, m_graph);
|
Chris@16
|
165 }
|
Chris@16
|
166
|
Chris@16
|
167 void remove_vertex(vertex_descriptor v) {
|
Chris@16
|
168 boost::remove_vertex(v, m_graph);
|
Chris@16
|
169 --m_num_vertices;
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 edges_size_type num_edges() const
|
Chris@16
|
173 { return m_num_edges; }
|
Chris@16
|
174
|
Chris@16
|
175 private:
|
Chris@16
|
176 // A helper fucntion for managing edge index attributes.
|
Chris@16
|
177 std::pair<edge_descriptor, bool> const&
|
Chris@16
|
178 make_index(std::pair<edge_descriptor, bool> const& x)
|
Chris@16
|
179 {
|
Chris@16
|
180 if(x.second) {
|
Chris@16
|
181 boost::put(edge_index, m_graph, x.first, m_max_edge_index);
|
Chris@16
|
182 ++m_num_edges;
|
Chris@16
|
183 ++m_max_edge_index;
|
Chris@16
|
184 }
|
Chris@16
|
185 return x;
|
Chris@16
|
186 }
|
Chris@16
|
187 public:
|
Chris@16
|
188 std::pair<edge_descriptor, bool>
|
Chris@16
|
189 add_edge(vertex_descriptor u, vertex_descriptor v)
|
Chris@16
|
190 { return make_index(boost::add_edge(u, v, m_graph)); }
|
Chris@16
|
191
|
Chris@16
|
192 std::pair<edge_descriptor, bool>
|
Chris@16
|
193 add_edge(vertex_descriptor u, vertex_descriptor v,
|
Chris@16
|
194 edge_property_type const& p)
|
Chris@16
|
195 { return make_index(boost::add_edge(u, v, internal_edge_property(0u, p), m_graph)); }
|
Chris@16
|
196
|
Chris@16
|
197 void remove_edge(vertex_descriptor u, vertex_descriptor v) {
|
Chris@16
|
198 // find all edges, (u, v)
|
Chris@16
|
199 std::vector<edge_descriptor> edges;
|
Chris@16
|
200 out_edge_iterator i, i_end;
|
Chris@16
|
201 for(boost::tie(i, i_end) = boost::out_edges(u, m_graph); i != i_end; ++i) {
|
Chris@16
|
202 if(boost::target(*i, m_graph) == v) {
|
Chris@16
|
203 edges.push_back(*i);
|
Chris@16
|
204 }
|
Chris@16
|
205 }
|
Chris@16
|
206 // remove all edges, (u, v)
|
Chris@16
|
207 typename std::vector<edge_descriptor>::iterator
|
Chris@16
|
208 j = edges.begin(), j_end = edges.end();
|
Chris@16
|
209 for( ; j != j_end; ++j) {
|
Chris@16
|
210 remove_edge(*j);
|
Chris@16
|
211 }
|
Chris@16
|
212 }
|
Chris@16
|
213
|
Chris@16
|
214 void remove_edge(edge_iterator i) {
|
Chris@16
|
215 remove_edge(*i);
|
Chris@16
|
216 }
|
Chris@16
|
217
|
Chris@16
|
218 void remove_edge(edge_descriptor e) {
|
Chris@16
|
219 boost::remove_edge(e, m_graph);
|
Chris@16
|
220 --m_num_edges;
|
Chris@16
|
221 }
|
Chris@16
|
222
|
Chris@16
|
223 vertex_index_type max_vertex_index() const
|
Chris@16
|
224 { return m_max_vertex_index; }
|
Chris@16
|
225
|
Chris@16
|
226 void renumber_vertex_indices() {
|
Chris@16
|
227 vertex_iterator i, i_end;
|
Chris@16
|
228 boost::tie(i, i_end) = vertices(m_graph);
|
Chris@16
|
229 m_max_vertex_index = renumber_vertex_indices(i, i_end, 0);
|
Chris@16
|
230 }
|
Chris@16
|
231
|
Chris@16
|
232 void remove_vertex_and_renumber_indices(vertex_iterator i) {
|
Chris@16
|
233 vertex_iterator j = next(i), end = vertices(m_graph).second;
|
Chris@16
|
234 vertex_index_type n = get(vertex_index, m_graph, *i);
|
Chris@16
|
235
|
Chris@16
|
236 // remove the offending vertex and renumber everything after
|
Chris@16
|
237 remove_vertex(*i);
|
Chris@16
|
238 m_max_vertex_index = renumber_vertex_indices(j, end, n);
|
Chris@16
|
239 }
|
Chris@16
|
240
|
Chris@16
|
241
|
Chris@16
|
242 edge_index_type max_edge_index() const
|
Chris@16
|
243 { return m_max_edge_index; }
|
Chris@16
|
244
|
Chris@16
|
245 void renumber_edge_indices() {
|
Chris@16
|
246 edge_iterator i, end;
|
Chris@16
|
247 boost::tie(i, end) = edges(m_graph);
|
Chris@16
|
248 m_max_edge_index = renumber_edge_indices(i, end, 0);
|
Chris@16
|
249 }
|
Chris@16
|
250
|
Chris@16
|
251 void remove_edge_and_renumber_indices(edge_iterator i) {
|
Chris@16
|
252 edge_iterator j = next(i), end = edges(m_graph.second);
|
Chris@16
|
253 edge_index_type n = get(edge_index, m_graph, *i);
|
Chris@16
|
254
|
Chris@16
|
255 // remove the edge and renumber everything after it
|
Chris@16
|
256 remove_edge(*i);
|
Chris@16
|
257 m_max_edge_index = renumber_edge_indices(j, end, n);
|
Chris@16
|
258 }
|
Chris@16
|
259
|
Chris@16
|
260 void renumber_indices() {
|
Chris@16
|
261 renumber_vertex_indices();
|
Chris@16
|
262 renumber_edge_indices();
|
Chris@16
|
263 }
|
Chris@16
|
264
|
Chris@16
|
265 // bundled property support
|
Chris@16
|
266 #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES
|
Chris@16
|
267 vertex_bundled& operator[](vertex_descriptor v)
|
Chris@16
|
268 { return m_graph[v]; }
|
Chris@16
|
269
|
Chris@16
|
270 vertex_bundled const& operator[](vertex_descriptor v) const
|
Chris@16
|
271 { return m_graph[v]; }
|
Chris@16
|
272
|
Chris@16
|
273 edge_bundled& operator[](edge_descriptor e)
|
Chris@16
|
274 { return m_graph[e]; }
|
Chris@16
|
275
|
Chris@16
|
276 edge_bundled const& operator[](edge_descriptor e) const
|
Chris@16
|
277 { return m_graph[e]; }
|
Chris@16
|
278
|
Chris@16
|
279 graph_bundled& operator[](graph_bundle_t)
|
Chris@16
|
280 { return get_property(*this); }
|
Chris@16
|
281
|
Chris@16
|
282 graph_bundled const& operator[](graph_bundle_t) const
|
Chris@16
|
283 { return get_property(*this); }
|
Chris@16
|
284 #endif
|
Chris@16
|
285
|
Chris@16
|
286 // Graph concepts
|
Chris@16
|
287 static vertex_descriptor null_vertex()
|
Chris@16
|
288 { return graph_type::null_vertex(); }
|
Chris@16
|
289
|
Chris@16
|
290 void clear() {
|
Chris@16
|
291 m_graph.clear();
|
Chris@16
|
292 m_num_vertices = m_max_vertex_index = 0;
|
Chris@16
|
293 m_num_edges = m_max_edge_index = 0;
|
Chris@16
|
294 }
|
Chris@16
|
295
|
Chris@16
|
296 void swap(undirected_graph& g) {
|
Chris@101
|
297 m_graph.swap(g.m_graph);
|
Chris@16
|
298 std::swap(m_num_vertices, g.m_num_vertices);
|
Chris@16
|
299 std::swap(m_max_vertex_index, g.m_max_vertex_index);
|
Chris@16
|
300 std::swap(m_num_edges, g.m_num_edges);
|
Chris@16
|
301 std::swap(m_max_edge_index, g.m_max_edge_index);
|
Chris@16
|
302 }
|
Chris@16
|
303
|
Chris@16
|
304 private:
|
Chris@16
|
305 vertices_size_type renumber_vertex_indices(vertex_iterator i,
|
Chris@16
|
306 vertex_iterator end,
|
Chris@16
|
307 vertices_size_type n)
|
Chris@16
|
308 {
|
Chris@16
|
309 typedef typename property_map<graph_type, vertex_index_t>::type IndexMap;
|
Chris@16
|
310 IndexMap indices = get(vertex_index, m_graph);
|
Chris@16
|
311 for( ; i != end; ++i) {
|
Chris@16
|
312 indices[*i] = n++;
|
Chris@16
|
313 }
|
Chris@16
|
314 return n;
|
Chris@16
|
315 }
|
Chris@16
|
316
|
Chris@16
|
317 edges_size_type renumber_edge_indices(edge_iterator i,
|
Chris@16
|
318 edge_iterator end,
|
Chris@16
|
319 edges_size_type n)
|
Chris@16
|
320 {
|
Chris@16
|
321 typedef typename property_map<graph_type, edge_index_t>::type IndexMap;
|
Chris@16
|
322 IndexMap indices = get(edge_index, m_graph);
|
Chris@16
|
323 for( ; i != end; ++i) {
|
Chris@16
|
324 indices[*i] = n++;
|
Chris@16
|
325 }
|
Chris@16
|
326 return n;
|
Chris@16
|
327 }
|
Chris@16
|
328
|
Chris@16
|
329 graph_type m_graph;
|
Chris@16
|
330 vertices_size_type m_num_vertices;
|
Chris@16
|
331 edges_size_type m_num_edges;
|
Chris@16
|
332 vertex_index_type m_max_vertex_index;
|
Chris@16
|
333 edge_index_type m_max_edge_index;
|
Chris@16
|
334 };
|
Chris@16
|
335
|
Chris@16
|
336 #define UNDIRECTED_GRAPH_PARAMS typename VP, typename EP, typename GP
|
Chris@16
|
337 #define UNDIRECTED_GRAPH undirected_graph<VP,EP,GP>
|
Chris@16
|
338
|
Chris@16
|
339 // IncidenceGraph concepts
|
Chris@16
|
340 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
341 inline typename UNDIRECTED_GRAPH::vertex_descriptor
|
Chris@16
|
342 source(typename UNDIRECTED_GRAPH::edge_descriptor e,
|
Chris@16
|
343 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
344 { return source(e, g.impl()); }
|
Chris@16
|
345
|
Chris@16
|
346 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
347 inline typename UNDIRECTED_GRAPH::vertex_descriptor
|
Chris@16
|
348 target(typename UNDIRECTED_GRAPH::edge_descriptor e,
|
Chris@16
|
349 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
350 { return target(e, g.impl()); }
|
Chris@16
|
351
|
Chris@16
|
352 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
353 inline typename UNDIRECTED_GRAPH::degree_size_type
|
Chris@16
|
354 out_degree(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
355 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
356 { return out_degree(v, g.impl()); }
|
Chris@16
|
357
|
Chris@16
|
358 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
359 inline std::pair<
|
Chris@16
|
360 typename UNDIRECTED_GRAPH::out_edge_iterator,
|
Chris@16
|
361 typename UNDIRECTED_GRAPH::out_edge_iterator
|
Chris@16
|
362 >
|
Chris@16
|
363 out_edges(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
364 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
365 { return out_edges(v, g.impl()); }
|
Chris@16
|
366
|
Chris@16
|
367 // BidirectionalGraph concepts
|
Chris@16
|
368 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
369 inline typename UNDIRECTED_GRAPH::degree_size_type
|
Chris@16
|
370 in_degree(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
371 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
372 { return in_degree(v, g.impl()); }
|
Chris@16
|
373
|
Chris@16
|
374 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
375 inline std::pair<
|
Chris@16
|
376 typename UNDIRECTED_GRAPH::in_edge_iterator,
|
Chris@16
|
377 typename UNDIRECTED_GRAPH::in_edge_iterator
|
Chris@16
|
378 >
|
Chris@16
|
379 in_edges(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
380 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
381 { return in_edges(v, g.impl()); }
|
Chris@16
|
382
|
Chris@16
|
383 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
384 inline std::pair<
|
Chris@16
|
385 typename UNDIRECTED_GRAPH::out_edge_iterator,
|
Chris@16
|
386 typename UNDIRECTED_GRAPH::out_edge_iterator
|
Chris@16
|
387 >
|
Chris@16
|
388 incident_edges(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
389 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
390 { return out_edges(v, g.impl()); }
|
Chris@16
|
391
|
Chris@16
|
392 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
393 inline typename UNDIRECTED_GRAPH::degree_size_type
|
Chris@16
|
394 degree(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
395 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
396 { return degree(v, g.impl()); }
|
Chris@16
|
397
|
Chris@16
|
398 // AdjacencyGraph concepts
|
Chris@16
|
399 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
400 inline std::pair<
|
Chris@16
|
401 typename UNDIRECTED_GRAPH::adjacency_iterator,
|
Chris@16
|
402 typename UNDIRECTED_GRAPH::adjacency_iterator
|
Chris@16
|
403 >
|
Chris@16
|
404 adjacent_vertices(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
405 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
406 { return adjacent_vertices(v, g.impl()); }
|
Chris@16
|
407
|
Chris@16
|
408 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
409 typename UNDIRECTED_GRAPH::vertex_descriptor
|
Chris@16
|
410 vertex(typename UNDIRECTED_GRAPH::vertices_size_type n,
|
Chris@16
|
411 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
412 { return vertex(n, g.impl()); }
|
Chris@16
|
413
|
Chris@16
|
414 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
415 std::pair<typename UNDIRECTED_GRAPH::edge_descriptor, bool>
|
Chris@16
|
416 edge(typename UNDIRECTED_GRAPH::vertex_descriptor u,
|
Chris@16
|
417 typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
418 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
419 { return edge(u, v, g.impl()); }
|
Chris@16
|
420
|
Chris@16
|
421 // VertexListGraph concepts
|
Chris@16
|
422 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
423 inline typename UNDIRECTED_GRAPH::vertices_size_type
|
Chris@16
|
424 num_vertices(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
425 { return g.num_vertices(); }
|
Chris@16
|
426
|
Chris@16
|
427 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
428 inline std::pair<
|
Chris@16
|
429 typename UNDIRECTED_GRAPH::vertex_iterator,
|
Chris@16
|
430 typename UNDIRECTED_GRAPH::vertex_iterator
|
Chris@16
|
431 >
|
Chris@16
|
432 vertices(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
433 { return vertices(g.impl()); }
|
Chris@16
|
434
|
Chris@16
|
435 // EdgeListGraph concepts
|
Chris@16
|
436 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
437 inline typename UNDIRECTED_GRAPH::edges_size_type
|
Chris@16
|
438 num_edges(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
439 { return g.num_edges(); }
|
Chris@16
|
440
|
Chris@16
|
441 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
442 inline std::pair<
|
Chris@16
|
443 typename UNDIRECTED_GRAPH::edge_iterator,
|
Chris@16
|
444 typename UNDIRECTED_GRAPH::edge_iterator
|
Chris@16
|
445 >
|
Chris@16
|
446 edges(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
447 { return edges(g.impl()); }
|
Chris@16
|
448
|
Chris@16
|
449 // MutableGraph concepts
|
Chris@16
|
450 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
451 inline typename UNDIRECTED_GRAPH::vertex_descriptor
|
Chris@16
|
452 add_vertex(UNDIRECTED_GRAPH& g)
|
Chris@16
|
453 { return g.add_vertex(); }
|
Chris@16
|
454
|
Chris@16
|
455 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
456 inline typename UNDIRECTED_GRAPH::vertex_descriptor
|
Chris@16
|
457 add_vertex(typename UNDIRECTED_GRAPH::vertex_property_type const& p,
|
Chris@16
|
458 UNDIRECTED_GRAPH& g)
|
Chris@16
|
459 { return g.add_vertex(p); }
|
Chris@16
|
460
|
Chris@16
|
461 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
462 inline void
|
Chris@16
|
463 clear_vertex(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
464 UNDIRECTED_GRAPH& g)
|
Chris@16
|
465 { return g.clear_vertex(v); }
|
Chris@16
|
466
|
Chris@16
|
467 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
468 inline void
|
Chris@16
|
469 remove_vertex(typename UNDIRECTED_GRAPH::vertex_descriptor v, UNDIRECTED_GRAPH& g)
|
Chris@16
|
470 { return g.remove_vertex(v); }
|
Chris@16
|
471
|
Chris@16
|
472 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
473 inline std::pair<typename UNDIRECTED_GRAPH::edge_descriptor, bool>
|
Chris@16
|
474 add_edge(typename UNDIRECTED_GRAPH::vertex_descriptor u,
|
Chris@16
|
475 typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
476 UNDIRECTED_GRAPH& g)
|
Chris@16
|
477 { return g.add_edge(u, v); }
|
Chris@16
|
478
|
Chris@16
|
479 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
480 inline std::pair<typename UNDIRECTED_GRAPH::edge_descriptor, bool>
|
Chris@16
|
481 add_edge(typename UNDIRECTED_GRAPH::vertex_descriptor u,
|
Chris@16
|
482 typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
483 typename UNDIRECTED_GRAPH::edge_property_type const& p,
|
Chris@16
|
484 UNDIRECTED_GRAPH& g)
|
Chris@16
|
485 { return g.add_edge(u, v, p); }
|
Chris@16
|
486
|
Chris@16
|
487 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
488 inline void
|
Chris@16
|
489 remove_edge(typename UNDIRECTED_GRAPH::vertex_descriptor u,
|
Chris@16
|
490 typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
491 UNDIRECTED_GRAPH& g)
|
Chris@16
|
492 { return g.remove_edge(u, v); }
|
Chris@16
|
493
|
Chris@16
|
494 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
495 inline void
|
Chris@16
|
496 remove_edge(typename UNDIRECTED_GRAPH::edge_descriptor e, UNDIRECTED_GRAPH& g)
|
Chris@16
|
497 { return g.remove_edge(e); }
|
Chris@16
|
498
|
Chris@16
|
499 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
500 inline void
|
Chris@16
|
501 remove_edge(typename UNDIRECTED_GRAPH::edge_iterator i, UNDIRECTED_GRAPH& g)
|
Chris@16
|
502 { return g.remove_edge(i); }
|
Chris@16
|
503
|
Chris@16
|
504 template <UNDIRECTED_GRAPH_PARAMS, class Predicate>
|
Chris@16
|
505 inline void remove_edge_if(Predicate pred, UNDIRECTED_GRAPH& g)
|
Chris@16
|
506 { return remove_edge_if(pred, g.impl()); }
|
Chris@16
|
507
|
Chris@16
|
508 template <UNDIRECTED_GRAPH_PARAMS, class Predicate>
|
Chris@16
|
509 inline void
|
Chris@16
|
510 remove_incident_edge_if(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
511 Predicate pred,
|
Chris@16
|
512 UNDIRECTED_GRAPH& g)
|
Chris@16
|
513 { return remove_out_edge_if(v, pred, g.impl()); }
|
Chris@16
|
514
|
Chris@16
|
515 template <UNDIRECTED_GRAPH_PARAMS, class Predicate>
|
Chris@16
|
516 inline void
|
Chris@16
|
517 remove_out_edge_if(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
518 Predicate pred,
|
Chris@16
|
519 UNDIRECTED_GRAPH& g)
|
Chris@16
|
520 { return remove_out_edge_if(v, pred, g.impl()); }
|
Chris@16
|
521
|
Chris@16
|
522 template <UNDIRECTED_GRAPH_PARAMS, class Predicate>
|
Chris@16
|
523 inline void
|
Chris@16
|
524 remove_in_edge_if(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
525 Predicate pred,
|
Chris@16
|
526 UNDIRECTED_GRAPH& g)
|
Chris@16
|
527 { return remove_in_edge_if(v, pred, g.impl()); }
|
Chris@16
|
528
|
Chris@16
|
529 template <UNDIRECTED_GRAPH_PARAMS, typename Property>
|
Chris@16
|
530 struct property_map<UNDIRECTED_GRAPH, Property>: property_map<typename UNDIRECTED_GRAPH::graph_type, Property> {};
|
Chris@16
|
531
|
Chris@16
|
532 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
533 struct property_map<UNDIRECTED_GRAPH, vertex_all_t> {
|
Chris@16
|
534 typedef transform_value_property_map<
|
Chris@16
|
535 detail::remove_first_property,
|
Chris@16
|
536 typename property_map<typename UNDIRECTED_GRAPH::graph_type, vertex_all_t>::const_type>
|
Chris@16
|
537 const_type;
|
Chris@16
|
538 typedef transform_value_property_map<
|
Chris@16
|
539 detail::remove_first_property,
|
Chris@16
|
540 typename property_map<typename UNDIRECTED_GRAPH::graph_type, vertex_all_t>::type>
|
Chris@16
|
541 type;
|
Chris@16
|
542 };
|
Chris@16
|
543
|
Chris@16
|
544 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
545 struct property_map<UNDIRECTED_GRAPH, edge_all_t> {
|
Chris@16
|
546 typedef transform_value_property_map<
|
Chris@16
|
547 detail::remove_first_property,
|
Chris@16
|
548 typename property_map<typename UNDIRECTED_GRAPH::graph_type, edge_all_t>::const_type>
|
Chris@16
|
549 const_type;
|
Chris@16
|
550 typedef transform_value_property_map<
|
Chris@16
|
551 detail::remove_first_property,
|
Chris@16
|
552 typename property_map<typename UNDIRECTED_GRAPH::graph_type, edge_all_t>::type>
|
Chris@16
|
553 type;
|
Chris@16
|
554 };
|
Chris@16
|
555
|
Chris@16
|
556 // PropertyGraph concepts
|
Chris@16
|
557 template <UNDIRECTED_GRAPH_PARAMS, typename Property>
|
Chris@16
|
558 inline typename property_map<UNDIRECTED_GRAPH, Property>::type
|
Chris@16
|
559 get(Property p, UNDIRECTED_GRAPH& g)
|
Chris@16
|
560 { return get(p, g.impl()); }
|
Chris@16
|
561
|
Chris@16
|
562 template <UNDIRECTED_GRAPH_PARAMS, typename Property>
|
Chris@16
|
563 inline typename property_map<UNDIRECTED_GRAPH, Property>::const_type
|
Chris@16
|
564 get(Property p, UNDIRECTED_GRAPH const& g)
|
Chris@16
|
565 { return get(p, g.impl()); }
|
Chris@16
|
566
|
Chris@16
|
567 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
568 inline typename property_map<UNDIRECTED_GRAPH, vertex_all_t>::type
|
Chris@16
|
569 get(vertex_all_t, UNDIRECTED_GRAPH& g)
|
Chris@16
|
570 { return typename property_map<UNDIRECTED_GRAPH, vertex_all_t>::type(detail::remove_first_property(), get(vertex_all, g.impl())); }
|
Chris@16
|
571
|
Chris@16
|
572 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
573 inline typename property_map<UNDIRECTED_GRAPH, vertex_all_t>::const_type
|
Chris@16
|
574 get(vertex_all_t, UNDIRECTED_GRAPH const& g)
|
Chris@16
|
575 { return typename property_map<UNDIRECTED_GRAPH, vertex_all_t>::const_type(detail::remove_first_property(), get(vertex_all, g.impl())); }
|
Chris@16
|
576
|
Chris@16
|
577 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
578 inline typename property_map<UNDIRECTED_GRAPH, edge_all_t>::type
|
Chris@16
|
579 get(edge_all_t, UNDIRECTED_GRAPH& g)
|
Chris@16
|
580 { return typename property_map<UNDIRECTED_GRAPH, edge_all_t>::type(detail::remove_first_property(), get(edge_all, g.impl())); }
|
Chris@16
|
581
|
Chris@16
|
582 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
583 inline typename property_map<UNDIRECTED_GRAPH, edge_all_t>::const_type
|
Chris@16
|
584 get(edge_all_t, UNDIRECTED_GRAPH const& g)
|
Chris@16
|
585 { return typename property_map<UNDIRECTED_GRAPH, edge_all_t>::const_type(detail::remove_first_property(), get(edge_all, g.impl())); }
|
Chris@16
|
586
|
Chris@16
|
587 template <UNDIRECTED_GRAPH_PARAMS, typename Property, typename Key>
|
Chris@16
|
588 inline typename property_traits<
|
Chris@16
|
589 typename property_map<
|
Chris@16
|
590 typename UNDIRECTED_GRAPH::graph_type, Property
|
Chris@16
|
591 >::const_type
|
Chris@16
|
592 >::value_type
|
Chris@16
|
593 get(Property p, UNDIRECTED_GRAPH const& g, Key const& k)
|
Chris@16
|
594 { return get(p, g.impl(), k); }
|
Chris@16
|
595
|
Chris@16
|
596 template <UNDIRECTED_GRAPH_PARAMS, typename Key>
|
Chris@16
|
597 inline typename property_traits<
|
Chris@16
|
598 typename property_map<
|
Chris@16
|
599 typename UNDIRECTED_GRAPH::graph_type, vertex_all_t
|
Chris@16
|
600 >::const_type
|
Chris@16
|
601 >::value_type
|
Chris@16
|
602 get(vertex_all_t, UNDIRECTED_GRAPH const& g, Key const& k)
|
Chris@16
|
603 { return get(vertex_all, g.impl(), k).m_base; }
|
Chris@16
|
604
|
Chris@16
|
605 template <UNDIRECTED_GRAPH_PARAMS, typename Key>
|
Chris@16
|
606 inline typename property_traits<
|
Chris@16
|
607 typename property_map<
|
Chris@16
|
608 typename UNDIRECTED_GRAPH::graph_type, edge_all_t
|
Chris@16
|
609 >::const_type
|
Chris@16
|
610 >::value_type
|
Chris@16
|
611 get(edge_all_t, UNDIRECTED_GRAPH const& g, Key const& k)
|
Chris@16
|
612 { return get(edge_all, g.impl(), k).m_base; }
|
Chris@16
|
613
|
Chris@16
|
614 template <UNDIRECTED_GRAPH_PARAMS, typename Property, typename Key, typename Value>
|
Chris@16
|
615 inline void put(Property p, UNDIRECTED_GRAPH& g, Key const& k, Value const& v)
|
Chris@16
|
616 { put(p, g.impl(), k, v); }
|
Chris@16
|
617
|
Chris@16
|
618 template <UNDIRECTED_GRAPH_PARAMS, typename Key, typename Value>
|
Chris@16
|
619 inline void put(vertex_all_t, UNDIRECTED_GRAPH& g, Key const& k, Value const& v)
|
Chris@16
|
620 { put(vertex_all, g.impl(), k,
|
Chris@16
|
621 typename UNDIRECTED_GRAPH::internal_vertex_property(get(vertex_index, g.impl(), k), v));
|
Chris@16
|
622 }
|
Chris@16
|
623
|
Chris@16
|
624 template <UNDIRECTED_GRAPH_PARAMS, typename Key, typename Value>
|
Chris@16
|
625 inline void put(edge_all_t, UNDIRECTED_GRAPH& g, Key const& k, Value const& v)
|
Chris@16
|
626 { put(edge_all, g.impl(), k,
|
Chris@16
|
627 typename UNDIRECTED_GRAPH::internal_vertex_property(get(edge_index, g.impl(), k), v));
|
Chris@16
|
628 }
|
Chris@16
|
629
|
Chris@16
|
630 template <UNDIRECTED_GRAPH_PARAMS, class Property>
|
Chris@16
|
631 inline typename graph_property<UNDIRECTED_GRAPH, Property>::type&
|
Chris@16
|
632 get_property(UNDIRECTED_GRAPH& g, Property p)
|
Chris@16
|
633 { return get_property(g.impl(), p); }
|
Chris@16
|
634
|
Chris@16
|
635 template <UNDIRECTED_GRAPH_PARAMS, class Property>
|
Chris@16
|
636 inline typename graph_property<UNDIRECTED_GRAPH, Property>::type const&
|
Chris@16
|
637 get_property(UNDIRECTED_GRAPH const& g, Property p)
|
Chris@16
|
638 { return get_property(g.impl(), p); }
|
Chris@16
|
639
|
Chris@16
|
640 template <UNDIRECTED_GRAPH_PARAMS, class Property, class Value>
|
Chris@16
|
641 inline void set_property(UNDIRECTED_GRAPH& g, Property p, Value v)
|
Chris@16
|
642 { return set_property(g.impl(), p, v); }
|
Chris@16
|
643
|
Chris@16
|
644 // Indexed Vertex graph
|
Chris@16
|
645
|
Chris@16
|
646 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
647 inline typename UNDIRECTED_GRAPH::vertex_index_type
|
Chris@16
|
648 get_vertex_index(typename UNDIRECTED_GRAPH::vertex_descriptor v,
|
Chris@16
|
649 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
650 { return get(vertex_index, g, v); }
|
Chris@16
|
651
|
Chris@16
|
652 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
653 typename UNDIRECTED_GRAPH::vertex_index_type
|
Chris@16
|
654 max_vertex_index(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
655 { return g.max_vertex_index(); }
|
Chris@16
|
656
|
Chris@16
|
657 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
658 inline void
|
Chris@16
|
659 renumber_vertex_indices(UNDIRECTED_GRAPH& g)
|
Chris@16
|
660 { g.renumber_vertex_indices(); }
|
Chris@16
|
661
|
Chris@16
|
662 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
663 inline void
|
Chris@16
|
664 remove_vertex_and_renumber_indices(typename UNDIRECTED_GRAPH::vertex_iterator i,
|
Chris@16
|
665 UNDIRECTED_GRAPH& g)
|
Chris@16
|
666 { g.remove_vertex_and_renumber_indices(i); }
|
Chris@16
|
667
|
Chris@16
|
668
|
Chris@16
|
669 // Edge index management
|
Chris@16
|
670
|
Chris@16
|
671 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
672 inline typename UNDIRECTED_GRAPH::edge_index_type
|
Chris@16
|
673 get_edge_index(typename UNDIRECTED_GRAPH::edge_descriptor v,
|
Chris@16
|
674 UNDIRECTED_GRAPH const& g)
|
Chris@16
|
675 { return get(edge_index, g, v); }
|
Chris@16
|
676
|
Chris@16
|
677 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
678 typename UNDIRECTED_GRAPH::edge_index_type
|
Chris@16
|
679 max_edge_index(UNDIRECTED_GRAPH const& g)
|
Chris@16
|
680 { return g.max_edge_index(); }
|
Chris@16
|
681
|
Chris@16
|
682 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
683 inline void
|
Chris@16
|
684 renumber_edge_indices(UNDIRECTED_GRAPH& g)
|
Chris@16
|
685 { g.renumber_edge_indices(); }
|
Chris@16
|
686
|
Chris@16
|
687 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
688 inline void
|
Chris@16
|
689 remove_edge_and_renumber_indices(typename UNDIRECTED_GRAPH::edge_iterator i,
|
Chris@16
|
690 UNDIRECTED_GRAPH& g)
|
Chris@16
|
691 { g.remove_edge_and_renumber_indices(i); }
|
Chris@16
|
692
|
Chris@16
|
693 // Index management
|
Chris@16
|
694 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
695 inline void
|
Chris@16
|
696 renumber_indices(UNDIRECTED_GRAPH& g)
|
Chris@16
|
697 { g.renumber_indices(); }
|
Chris@16
|
698
|
Chris@16
|
699 // Mutability Traits
|
Chris@16
|
700 template <UNDIRECTED_GRAPH_PARAMS>
|
Chris@16
|
701 struct graph_mutability_traits<UNDIRECTED_GRAPH> {
|
Chris@16
|
702 typedef mutable_property_graph_tag category;
|
Chris@16
|
703 };
|
Chris@16
|
704
|
Chris@16
|
705 #undef UNDIRECTED_GRAPH_PARAMS
|
Chris@16
|
706 #undef UNDIRECTED_GRAPH
|
Chris@16
|
707
|
Chris@16
|
708 } /* namespace boost */
|
Chris@16
|
709
|
Chris@16
|
710 #endif
|