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