Chris@16
|
1 //=======================================================================
|
Chris@16
|
2 // Copyright 1997-2001 University of Notre Dame.
|
Chris@16
|
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //=======================================================================
|
Chris@16
|
9 #ifndef BOOST_GRAPH_SGB_GRAPH_HPP
|
Chris@16
|
10 #define BOOST_GRAPH_SGB_GRAPH_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/config.hpp>
|
Chris@16
|
13 #include <boost/iterator.hpp>
|
Chris@16
|
14 #include <boost/operators.hpp>
|
Chris@16
|
15 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
16 #include <boost/graph/graph_traits.hpp>
|
Chris@16
|
17 #include <boost/graph/properties.hpp>
|
Chris@16
|
18
|
Chris@16
|
19 // Thanks to Andreas Scherer for numerous suggestions and fixes!
|
Chris@16
|
20
|
Chris@16
|
21 // This file adapts a Stanford GraphBase (SGB) Graph pointer into a
|
Chris@16
|
22 // VertexListGraph. Note that a graph adaptor class is not needed,
|
Chris@16
|
23 // SGB's Graph* is used as is. The VertexListGraph concept is fulfilled by
|
Chris@16
|
24 // defining the appropriate non-member functions for Graph*.
|
Chris@16
|
25 //
|
Chris@16
|
26 // The PROTOTYPES change file extensions to SGB must be applied so
|
Chris@16
|
27 // that the SGB functions have real prototypes which are necessary for
|
Chris@16
|
28 // the C++ compiler. To apply the PROTOTYPES extensions, before you do
|
Chris@16
|
29 // "make tests install" for SGB do "ln -s PROTOTYPES/* ." to the SGB
|
Chris@16
|
30 // root directory (or just copy all the files from the PROTOTYPES
|
Chris@16
|
31 // directory to the SGB root directory).
|
Chris@16
|
32 //
|
Chris@16
|
33 extern "C" {
|
Chris@16
|
34 // We include all global definitions for the general stuff
|
Chris@16
|
35 // of The Stanford GraphBase and its various graph generator
|
Chris@16
|
36 // functions by reading all SGB headerfiles as in section 2 of
|
Chris@16
|
37 // the "test_sample" program.
|
Chris@16
|
38 #include <gb_graph.h> /* SGB data structures */
|
Chris@16
|
39 #include <gb_io.h> /* SGB input/output routines */
|
Chris@16
|
40 #include <gb_flip.h> /* random number generator */
|
Chris@16
|
41 #include <gb_dijk.h> /* routines for shortest paths */
|
Chris@16
|
42 #include <gb_basic.h> /* the basic graph operations */
|
Chris@16
|
43 #undef empty /* avoid name clash with C++ standard library */
|
Chris@16
|
44 inline Graph* empty( long n ) /* and provide workaround */
|
Chris@16
|
45 { return board(n,0L,0L,0L,2L,0L,0L); }
|
Chris@16
|
46 #include <gb_books.h> /* graphs based on literature */
|
Chris@16
|
47 #include <gb_econ.h> /* graphs based on economic data */
|
Chris@16
|
48 #include <gb_games.h> /* graphs based on football scores */
|
Chris@16
|
49 #include <gb_gates.h> /* graphs based on logic circuits */
|
Chris@16
|
50 #undef val /* avoid name clash with g++ headerfile stl_tempbuf.h */
|
Chris@16
|
51 // val ==> Vertex::x.I
|
Chris@16
|
52 #include <gb_lisa.h> /* graphs based on Mona Lisa */
|
Chris@16
|
53 #include <gb_miles.h> /* graphs based on mileage data */
|
Chris@16
|
54 #include <gb_plane.h> /* planar graphs */
|
Chris@16
|
55 #include <gb_raman.h> /* Ramanujan graphs */
|
Chris@16
|
56 #include <gb_rand.h> /* random graphs */
|
Chris@16
|
57 #include <gb_roget.h> /* graphs based on Roget's Thesaurus */
|
Chris@16
|
58 #include <gb_save.h> /* we save results in ASCII format */
|
Chris@16
|
59 #include <gb_words.h> /* five-letter-word graphs */
|
Chris@16
|
60 #undef weight /* avoid name clash with BGL parameter */
|
Chris@16
|
61 // weight ==> Vertex::u.I
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 namespace boost {
|
Chris@16
|
65 class sgb_edge;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 class sgb_out_edge_iterator;
|
Chris@16
|
69 class sgb_adj_iterator;
|
Chris@16
|
70 class sgb_vertex_iterator;
|
Chris@16
|
71
|
Chris@16
|
72 namespace boost {
|
Chris@16
|
73 typedef Graph* sgb_graph_ptr;
|
Chris@16
|
74 typedef const Graph* sgb_const_graph_ptr;
|
Chris@16
|
75
|
Chris@16
|
76 struct sgb_traversal_tag :
|
Chris@16
|
77 public virtual vertex_list_graph_tag,
|
Chris@16
|
78 public virtual incidence_graph_tag,
|
Chris@16
|
79 public virtual adjacency_graph_tag { };
|
Chris@16
|
80
|
Chris@16
|
81 template <> struct graph_traits<sgb_graph_ptr> {
|
Chris@16
|
82 typedef Vertex* vertex_descriptor;
|
Chris@16
|
83 typedef boost::sgb_edge edge_descriptor;
|
Chris@16
|
84 typedef sgb_out_edge_iterator out_edge_iterator;
|
Chris@16
|
85 typedef void in_edge_iterator;
|
Chris@16
|
86 typedef sgb_adj_iterator adjacency_iterator;
|
Chris@16
|
87 typedef sgb_vertex_iterator vertex_iterator;
|
Chris@16
|
88 typedef void edge_iterator;
|
Chris@16
|
89 typedef long vertices_size_type;
|
Chris@16
|
90 typedef long edge_size_type;
|
Chris@16
|
91 typedef long degree_size_type;
|
Chris@16
|
92 typedef directed_tag directed_category;
|
Chris@16
|
93 typedef sgb_traversal_tag traversal_category;
|
Chris@16
|
94 typedef allow_parallel_edge_tag edge_parallel_category;
|
Chris@16
|
95 };
|
Chris@16
|
96 template <> struct graph_traits<sgb_const_graph_ptr> {
|
Chris@16
|
97 typedef Vertex* vertex_descriptor;
|
Chris@16
|
98 typedef boost::sgb_edge edge_descriptor;
|
Chris@16
|
99 typedef sgb_out_edge_iterator out_edge_iterator;
|
Chris@16
|
100 typedef void in_edge_iterator;
|
Chris@16
|
101 typedef sgb_adj_iterator adjacency_iterator;
|
Chris@16
|
102 typedef sgb_vertex_iterator vertex_iterator;
|
Chris@16
|
103 typedef void edge_iterator;
|
Chris@16
|
104 typedef long vertices_size_type;
|
Chris@16
|
105 typedef long edge_size_type;
|
Chris@16
|
106 typedef long degree_size_type;
|
Chris@16
|
107 typedef directed_tag directed_category;
|
Chris@16
|
108 typedef sgb_traversal_tag traversal_category;
|
Chris@16
|
109 typedef allow_parallel_edge_tag edge_parallel_category;
|
Chris@16
|
110 };
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 namespace boost {
|
Chris@16
|
114
|
Chris@16
|
115 struct edge_length_t {
|
Chris@16
|
116 typedef edge_property_tag kind;
|
Chris@16
|
117 };
|
Chris@16
|
118
|
Chris@16
|
119 // We could just use Arc* as the edge descriptor type, but
|
Chris@16
|
120 // we want to add the source(e,g) function which requires
|
Chris@16
|
121 // that we carry along a pointer to the source vertex.
|
Chris@16
|
122 class sgb_edge {
|
Chris@16
|
123 typedef sgb_edge self;
|
Chris@16
|
124 public:
|
Chris@16
|
125 sgb_edge() : _arc(0), _src(0) { }
|
Chris@16
|
126 sgb_edge(Arc* a, Vertex* s) : _arc(a), _src(s) { }
|
Chris@16
|
127 friend Vertex* source(self e, sgb_const_graph_ptr) { return e._src; }
|
Chris@16
|
128 friend Vertex* target(self e, sgb_const_graph_ptr) { return e._arc->tip; }
|
Chris@16
|
129 friend bool operator==(const self& a, const self& b) {
|
Chris@16
|
130 return a._arc == b._arc; }
|
Chris@16
|
131 friend bool operator!=(const self& a, const self& b) {
|
Chris@16
|
132 return a._arc != b._arc; }
|
Chris@16
|
133 #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
Chris@16
|
134 template <class Ref> friend class sgb_edge_length_map;
|
Chris@16
|
135 template <class Tag, class Ref> friend class sgb_edge_util_map;
|
Chris@16
|
136 friend long get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key);
|
Chris@16
|
137 friend long get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key);
|
Chris@16
|
138 friend void put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value);
|
Chris@16
|
139 protected:
|
Chris@16
|
140 #endif
|
Chris@16
|
141 Arc* _arc;
|
Chris@16
|
142 Vertex* _src;
|
Chris@16
|
143 };
|
Chris@16
|
144 } // namespace boost
|
Chris@16
|
145
|
Chris@16
|
146 class sgb_out_edge_iterator
|
Chris@16
|
147 : public boost::forward_iterator_helper<
|
Chris@16
|
148 sgb_out_edge_iterator, boost::sgb_edge,
|
Chris@16
|
149 std::ptrdiff_t, boost::sgb_edge*, boost::sgb_edge>
|
Chris@16
|
150 {
|
Chris@16
|
151 typedef sgb_out_edge_iterator self;
|
Chris@16
|
152 public:
|
Chris@16
|
153 sgb_out_edge_iterator() : _src(0), _arc(0) {}
|
Chris@16
|
154 sgb_out_edge_iterator(Vertex* s, Arc* d) : _src(s), _arc(d) {}
|
Chris@16
|
155 boost::sgb_edge operator*() { return boost::sgb_edge(_arc, _src); }
|
Chris@16
|
156 self& operator++() { _arc = _arc->next; return *this; }
|
Chris@16
|
157 friend bool operator==(const self& x, const self& y) {
|
Chris@16
|
158 return x._arc == y._arc; }
|
Chris@16
|
159 protected:
|
Chris@16
|
160 Vertex* _src;
|
Chris@16
|
161 Arc* _arc;
|
Chris@16
|
162 };
|
Chris@16
|
163
|
Chris@16
|
164 class sgb_adj_iterator
|
Chris@16
|
165 : public boost::forward_iterator_helper<
|
Chris@16
|
166 sgb_adj_iterator, Vertex*, std::ptrdiff_t, Vertex**,Vertex*>
|
Chris@16
|
167 {
|
Chris@16
|
168 typedef sgb_adj_iterator self;
|
Chris@16
|
169 public:
|
Chris@16
|
170 sgb_adj_iterator() : _arc(0) {}
|
Chris@16
|
171 sgb_adj_iterator(Arc* d) : _arc(d) {}
|
Chris@16
|
172 Vertex* operator*() { return _arc->tip; }
|
Chris@16
|
173 self& operator++() { _arc = _arc->next; return *this; }
|
Chris@16
|
174 friend bool operator==(const self& x, const self& y) {
|
Chris@16
|
175 return x._arc == y._arc; }
|
Chris@16
|
176 protected:
|
Chris@16
|
177 Arc* _arc;
|
Chris@16
|
178 };
|
Chris@16
|
179
|
Chris@16
|
180 // The reason we have this instead of just using Vertex* is that we
|
Chris@16
|
181 // want to use Vertex* as the vertex_descriptor instead of just
|
Chris@16
|
182 // Vertex, which avoids problems with boost passing vertex descriptors
|
Chris@16
|
183 // by value and how that interacts with the sgb_vertex_id_map.
|
Chris@16
|
184 class sgb_vertex_iterator
|
Chris@16
|
185 : public boost::forward_iterator_helper<
|
Chris@16
|
186 sgb_vertex_iterator, Vertex*, std::ptrdiff_t, Vertex**, Vertex*>
|
Chris@16
|
187 {
|
Chris@16
|
188 typedef sgb_vertex_iterator self;
|
Chris@16
|
189 public:
|
Chris@16
|
190 sgb_vertex_iterator() : _v(0) { }
|
Chris@16
|
191 sgb_vertex_iterator(Vertex* v) : _v(v) { }
|
Chris@16
|
192 Vertex* operator*() { return _v; }
|
Chris@16
|
193 self& operator++() { ++_v; return *this; }
|
Chris@16
|
194 friend bool operator==(const self& x, const self& y) {
|
Chris@16
|
195 return x._v == y._v; }
|
Chris@16
|
196 protected:
|
Chris@16
|
197 Vertex* _v;
|
Chris@16
|
198 };
|
Chris@16
|
199
|
Chris@16
|
200 namespace boost {
|
Chris@16
|
201
|
Chris@16
|
202 inline std::pair<sgb_vertex_iterator,sgb_vertex_iterator>
|
Chris@16
|
203 vertices(sgb_const_graph_ptr g)
|
Chris@16
|
204 {
|
Chris@16
|
205 return std::make_pair(sgb_vertex_iterator(g->vertices),
|
Chris@16
|
206 sgb_vertex_iterator(g->vertices + g->n));
|
Chris@16
|
207 }
|
Chris@16
|
208
|
Chris@16
|
209 inline std::pair<sgb_out_edge_iterator,sgb_out_edge_iterator>
|
Chris@16
|
210 out_edges(Vertex* u, sgb_const_graph_ptr)
|
Chris@16
|
211 {
|
Chris@16
|
212 return std::make_pair( sgb_out_edge_iterator(u, u->arcs),
|
Chris@16
|
213 sgb_out_edge_iterator(u, 0) );
|
Chris@16
|
214 }
|
Chris@16
|
215
|
Chris@16
|
216 inline boost::graph_traits<sgb_graph_ptr>::degree_size_type
|
Chris@16
|
217 out_degree(Vertex* u, sgb_const_graph_ptr g)
|
Chris@16
|
218 {
|
Chris@16
|
219 boost::graph_traits<sgb_graph_ptr>::out_edge_iterator i, i_end;
|
Chris@16
|
220 boost::tie(i, i_end) = out_edges(u, g);
|
Chris@16
|
221 return std::distance(i, i_end);
|
Chris@16
|
222 }
|
Chris@16
|
223
|
Chris@16
|
224 // in_edges?
|
Chris@16
|
225
|
Chris@16
|
226 inline std::pair<sgb_adj_iterator,sgb_adj_iterator>
|
Chris@16
|
227 adjacent_vertices(Vertex* u, sgb_const_graph_ptr)
|
Chris@16
|
228 {
|
Chris@16
|
229 return std::make_pair( sgb_adj_iterator(u->arcs),
|
Chris@16
|
230 sgb_adj_iterator(0) );
|
Chris@16
|
231 }
|
Chris@16
|
232
|
Chris@16
|
233 inline long num_vertices(sgb_const_graph_ptr g) { return g->n; }
|
Chris@16
|
234 inline long num_edges(sgb_const_graph_ptr g) { return g->m; }
|
Chris@16
|
235
|
Chris@16
|
236 inline Vertex* vertex(long v, sgb_const_graph_ptr g)
|
Chris@16
|
237 { return g->vertices + v; }
|
Chris@16
|
238
|
Chris@16
|
239 // Various Property Maps
|
Chris@16
|
240
|
Chris@16
|
241 // Vertex ID
|
Chris@16
|
242 class sgb_vertex_id_map
|
Chris@16
|
243 : public boost::put_get_helper<long, sgb_vertex_id_map>
|
Chris@16
|
244 {
|
Chris@16
|
245 public:
|
Chris@16
|
246 typedef boost::readable_property_map_tag category;
|
Chris@16
|
247 typedef long value_type;
|
Chris@16
|
248 typedef long reference;
|
Chris@16
|
249 typedef Vertex* key_type;
|
Chris@16
|
250 sgb_vertex_id_map() : _g(0) { }
|
Chris@16
|
251 sgb_vertex_id_map(sgb_graph_ptr g) : _g(g) { }
|
Chris@16
|
252 long operator[](Vertex* v) const { return v - _g->vertices; }
|
Chris@16
|
253 protected:
|
Chris@16
|
254 sgb_graph_ptr _g;
|
Chris@16
|
255 };
|
Chris@16
|
256 inline sgb_vertex_id_map get(vertex_index_t, sgb_graph_ptr g) {
|
Chris@16
|
257 return sgb_vertex_id_map(g);
|
Chris@16
|
258 }
|
Chris@16
|
259
|
Chris@16
|
260 // Vertex Name
|
Chris@16
|
261 class sgb_vertex_name_map
|
Chris@16
|
262 : public boost::put_get_helper<char*, sgb_vertex_name_map>
|
Chris@16
|
263 {
|
Chris@16
|
264 public:
|
Chris@16
|
265 typedef boost::readable_property_map_tag category;
|
Chris@16
|
266 typedef char* value_type;
|
Chris@16
|
267 typedef char* reference;
|
Chris@16
|
268 typedef Vertex* key_type;
|
Chris@16
|
269 char* operator[](Vertex* v) const { return v->name; }
|
Chris@16
|
270 };
|
Chris@16
|
271 inline sgb_vertex_name_map get(vertex_name_t, sgb_graph_ptr) {
|
Chris@16
|
272 return sgb_vertex_name_map();
|
Chris@16
|
273 }
|
Chris@16
|
274
|
Chris@16
|
275 // Vertex Property Tags
|
Chris@16
|
276 #define SGB_PROPERTY_TAG(KIND,TAG) \
|
Chris@16
|
277 template <class T> struct TAG##_property { \
|
Chris@16
|
278 typedef KIND##_property_tag kind; \
|
Chris@16
|
279 typedef T type; \
|
Chris@16
|
280 };
|
Chris@16
|
281 SGB_PROPERTY_TAG(vertex, u)
|
Chris@16
|
282 SGB_PROPERTY_TAG(vertex, v)
|
Chris@16
|
283 SGB_PROPERTY_TAG(vertex, w)
|
Chris@16
|
284 SGB_PROPERTY_TAG(vertex, x)
|
Chris@16
|
285 SGB_PROPERTY_TAG(vertex, y)
|
Chris@16
|
286 SGB_PROPERTY_TAG(vertex, z)
|
Chris@16
|
287
|
Chris@16
|
288 // Edge Property Tags
|
Chris@16
|
289 SGB_PROPERTY_TAG(edge, a)
|
Chris@16
|
290 SGB_PROPERTY_TAG(edge, b)
|
Chris@16
|
291
|
Chris@16
|
292 // Various Utility Maps
|
Chris@16
|
293
|
Chris@16
|
294 // helpers
|
Chris@16
|
295 inline Vertex*& get_util(util& u, Vertex*) { return u.V; }
|
Chris@16
|
296 inline Arc*& get_util(util& u, Arc*) { return u.A; }
|
Chris@16
|
297 inline sgb_graph_ptr& get_util(util& u, sgb_graph_ptr) { return u.G; }
|
Chris@16
|
298 inline char*& get_util(util& u, char*) { return u.S; }
|
Chris@16
|
299 inline long& get_util(util& u, long) { return u.I; }
|
Chris@16
|
300
|
Chris@16
|
301 #define SGB_GET_UTIL_FIELD(KIND,X) \
|
Chris@16
|
302 template <class T> \
|
Chris@16
|
303 inline T& get_util_field(KIND* k, X##_property<T>) { \
|
Chris@16
|
304 return get_util(k->X, T()); }
|
Chris@16
|
305
|
Chris@16
|
306 SGB_GET_UTIL_FIELD(Vertex, u)
|
Chris@16
|
307 SGB_GET_UTIL_FIELD(Vertex, v)
|
Chris@16
|
308 SGB_GET_UTIL_FIELD(Vertex, w)
|
Chris@16
|
309 SGB_GET_UTIL_FIELD(Vertex, x)
|
Chris@16
|
310 SGB_GET_UTIL_FIELD(Vertex, y)
|
Chris@16
|
311 SGB_GET_UTIL_FIELD(Vertex, z)
|
Chris@16
|
312
|
Chris@16
|
313 SGB_GET_UTIL_FIELD(Arc, a)
|
Chris@16
|
314 SGB_GET_UTIL_FIELD(Arc, b)
|
Chris@16
|
315
|
Chris@16
|
316 // Vertex Utility Map
|
Chris@16
|
317 template <class Tag, class Ref>
|
Chris@16
|
318 class sgb_vertex_util_map
|
Chris@16
|
319 : public boost::put_get_helper<Ref, sgb_vertex_util_map<Tag, Ref> >
|
Chris@16
|
320 {
|
Chris@16
|
321 Tag tag;
|
Chris@16
|
322 public:
|
Chris@16
|
323 explicit sgb_vertex_util_map(Tag tag = Tag()): tag(tag) {}
|
Chris@16
|
324 typedef boost::lvalue_property_map_tag category;
|
Chris@16
|
325 typedef typename Tag::type value_type;
|
Chris@16
|
326 typedef Vertex* key_type;
|
Chris@16
|
327 typedef Ref reference;
|
Chris@16
|
328 reference operator[](Vertex* v) const {
|
Chris@16
|
329 return get_util_field(v, tag);
|
Chris@16
|
330 }
|
Chris@16
|
331 };
|
Chris@16
|
332
|
Chris@16
|
333 // Edge Utility Map
|
Chris@16
|
334 template <class Tag, class Ref>
|
Chris@16
|
335 class sgb_edge_util_map
|
Chris@16
|
336 : public boost::put_get_helper<Ref, sgb_edge_util_map<Tag, Ref> >
|
Chris@16
|
337 {
|
Chris@16
|
338 Tag tag;
|
Chris@16
|
339 public:
|
Chris@16
|
340 explicit sgb_edge_util_map(Tag tag = Tag()): tag(tag) {}
|
Chris@16
|
341 typedef boost::lvalue_property_map_tag category;
|
Chris@16
|
342 typedef typename Tag::type value_type;
|
Chris@16
|
343 typedef Vertex* key_type;
|
Chris@16
|
344 typedef Ref reference;
|
Chris@16
|
345 reference operator[](const sgb_edge& e) const {
|
Chris@16
|
346 return get_util_field(e._arc, tag);
|
Chris@16
|
347 }
|
Chris@16
|
348 };
|
Chris@16
|
349
|
Chris@16
|
350
|
Chris@16
|
351 template <class Tag>
|
Chris@16
|
352 inline sgb_vertex_util_map<Tag, const typename Tag::type&>
|
Chris@16
|
353 get_property_map(Tag, const sgb_graph_ptr& g, vertex_property_tag) {
|
Chris@16
|
354 return sgb_vertex_util_map<Tag, const typename Tag::type&>();
|
Chris@16
|
355 }
|
Chris@16
|
356 template <class Tag>
|
Chris@16
|
357 inline sgb_vertex_util_map<Tag, typename Tag::type&>
|
Chris@16
|
358 get_property_map(Tag, sgb_graph_ptr& g, vertex_property_tag) {
|
Chris@16
|
359 return sgb_vertex_util_map<Tag, typename Tag::type&>();
|
Chris@16
|
360 }
|
Chris@16
|
361
|
Chris@16
|
362 template <class Tag>
|
Chris@16
|
363 inline sgb_edge_util_map<Tag, const typename Tag::type&>
|
Chris@16
|
364 get_property_map(Tag, const sgb_graph_ptr& g, edge_property_tag) {
|
Chris@16
|
365 return sgb_edge_util_map<Tag, const typename Tag::type&>();
|
Chris@16
|
366 }
|
Chris@16
|
367 template <class Tag>
|
Chris@16
|
368 inline sgb_edge_util_map<Tag, typename Tag::type&>
|
Chris@16
|
369 get_property_map(Tag, sgb_graph_ptr& g, edge_property_tag) {
|
Chris@16
|
370 return sgb_edge_util_map<Tag, typename Tag::type&>();
|
Chris@16
|
371 }
|
Chris@16
|
372
|
Chris@16
|
373
|
Chris@16
|
374 // Edge Length Access
|
Chris@16
|
375 template <class Ref>
|
Chris@16
|
376 class sgb_edge_length_map
|
Chris@16
|
377 : public boost::put_get_helper<Ref, sgb_edge_length_map<Ref> >
|
Chris@16
|
378 {
|
Chris@16
|
379 public:
|
Chris@16
|
380 typedef boost::lvalue_property_map_tag category;
|
Chris@16
|
381 typedef long value_type;
|
Chris@16
|
382 typedef sgb_edge key_type;
|
Chris@16
|
383 typedef Ref reference;
|
Chris@16
|
384 reference operator[](const sgb_edge& e) const {
|
Chris@16
|
385 return e._arc->len;
|
Chris@16
|
386 }
|
Chris@16
|
387 };
|
Chris@16
|
388
|
Chris@16
|
389 inline sgb_edge_length_map<const long&>
|
Chris@16
|
390 get(edge_length_t, const sgb_graph_ptr&) {
|
Chris@16
|
391 return sgb_edge_length_map<const long&>();
|
Chris@16
|
392 }
|
Chris@16
|
393 inline sgb_edge_length_map<const long&>
|
Chris@16
|
394 get(edge_length_t, const sgb_const_graph_ptr&) {
|
Chris@16
|
395 return sgb_edge_length_map<const long&>();
|
Chris@16
|
396 }
|
Chris@16
|
397 inline sgb_edge_length_map<long&>
|
Chris@16
|
398 get(edge_length_t, sgb_graph_ptr&) {
|
Chris@16
|
399 return sgb_edge_length_map<long&>();
|
Chris@16
|
400 }
|
Chris@16
|
401 inline long
|
Chris@16
|
402 get(edge_length_t, const sgb_graph_ptr&, const sgb_edge& key) {
|
Chris@16
|
403 return key._arc->len;
|
Chris@16
|
404 }
|
Chris@16
|
405 inline long
|
Chris@16
|
406 get(edge_length_t, const sgb_const_graph_ptr&, const sgb_edge& key) {
|
Chris@16
|
407 return key._arc->len;
|
Chris@16
|
408 }
|
Chris@16
|
409 inline void
|
Chris@16
|
410 put(edge_length_t, sgb_graph_ptr&, const sgb_edge& key, long value)
|
Chris@16
|
411 {
|
Chris@16
|
412 key._arc->len = value;
|
Chris@16
|
413 }
|
Chris@16
|
414
|
Chris@16
|
415 // Property Map Traits Classes
|
Chris@16
|
416 template <>
|
Chris@16
|
417 struct property_map<sgb_graph_ptr, edge_length_t> {
|
Chris@16
|
418 typedef sgb_edge_length_map<long&> type;
|
Chris@16
|
419 typedef sgb_edge_length_map<const long&> const_type;
|
Chris@16
|
420 };
|
Chris@16
|
421 template <>
|
Chris@16
|
422 struct property_map<sgb_graph_ptr, vertex_index_t> {
|
Chris@16
|
423 typedef sgb_vertex_id_map type;
|
Chris@16
|
424 typedef sgb_vertex_id_map const_type;
|
Chris@16
|
425 };
|
Chris@16
|
426 template <>
|
Chris@16
|
427 struct property_map<sgb_graph_ptr, vertex_name_t> {
|
Chris@16
|
428 typedef sgb_vertex_name_map type;
|
Chris@16
|
429 typedef sgb_vertex_name_map const_type;
|
Chris@16
|
430 };
|
Chris@16
|
431
|
Chris@16
|
432 template <>
|
Chris@16
|
433 struct property_map<sgb_const_graph_ptr, edge_length_t> {
|
Chris@16
|
434 typedef sgb_edge_length_map<const long&> const_type;
|
Chris@16
|
435 };
|
Chris@16
|
436 template <>
|
Chris@16
|
437 struct property_map<sgb_const_graph_ptr, vertex_index_t> {
|
Chris@16
|
438 typedef sgb_vertex_id_map const_type;
|
Chris@16
|
439 };
|
Chris@16
|
440 template <>
|
Chris@16
|
441 struct property_map<sgb_const_graph_ptr, vertex_name_t> {
|
Chris@16
|
442 typedef sgb_vertex_name_map const_type;
|
Chris@16
|
443 };
|
Chris@16
|
444
|
Chris@16
|
445
|
Chris@16
|
446 namespace detail {
|
Chris@16
|
447 template <class Kind, class PropertyTag>
|
Chris@16
|
448 struct sgb_choose_property_map { };
|
Chris@16
|
449 template <class PropertyTag>
|
Chris@16
|
450 struct sgb_choose_property_map<vertex_property_tag, PropertyTag> {
|
Chris@16
|
451 typedef typename PropertyTag::type value_type;
|
Chris@16
|
452 typedef sgb_vertex_util_map<PropertyTag, value_type&> type;
|
Chris@16
|
453 typedef sgb_vertex_util_map<PropertyTag, const value_type&> const_type;
|
Chris@16
|
454 };
|
Chris@16
|
455 template <class PropertyTag>
|
Chris@16
|
456 struct sgb_choose_property_map<edge_property_tag, PropertyTag> {
|
Chris@16
|
457 typedef typename PropertyTag::type value_type;
|
Chris@16
|
458 typedef sgb_edge_util_map<PropertyTag, value_type&> type;
|
Chris@16
|
459 typedef sgb_edge_util_map<PropertyTag, const value_type&> const_type;
|
Chris@16
|
460 };
|
Chris@16
|
461 } // namespace detail
|
Chris@16
|
462 template <class PropertyTag>
|
Chris@16
|
463 struct property_map<sgb_graph_ptr, PropertyTag> {
|
Chris@16
|
464 typedef typename property_kind<PropertyTag>::type Kind;
|
Chris@16
|
465 typedef detail::sgb_choose_property_map<Kind, PropertyTag> Choice;
|
Chris@16
|
466 typedef typename Choice::type type;
|
Chris@16
|
467 typedef typename Choice::const_type const_type;
|
Chris@16
|
468 };
|
Chris@16
|
469 template <class PropertyTag>
|
Chris@16
|
470 struct property_map<sgb_const_graph_ptr, PropertyTag> {
|
Chris@16
|
471 typedef typename property_kind<PropertyTag>::type Kind;
|
Chris@16
|
472 typedef detail::sgb_choose_property_map<Kind, PropertyTag> Choice;
|
Chris@16
|
473 typedef typename Choice::const_type const_type;
|
Chris@16
|
474 };
|
Chris@16
|
475
|
Chris@16
|
476 #define SGB_UTIL_ACCESSOR(KIND,X) \
|
Chris@16
|
477 template <class T> \
|
Chris@16
|
478 inline sgb_##KIND##_util_map< X##_property<T>, T&> \
|
Chris@16
|
479 get(X##_property<T>, sgb_graph_ptr&) { \
|
Chris@16
|
480 return sgb_##KIND##_util_map< X##_property<T>, T&>(); \
|
Chris@16
|
481 } \
|
Chris@16
|
482 template <class T> \
|
Chris@16
|
483 inline sgb_##KIND##_util_map< X##_property<T>, const T&> \
|
Chris@16
|
484 get(X##_property<T>, const sgb_graph_ptr&) { \
|
Chris@16
|
485 return sgb_##KIND##_util_map< X##_property<T>, const T&>(); \
|
Chris@16
|
486 } \
|
Chris@16
|
487 template <class T> \
|
Chris@16
|
488 inline sgb_##KIND##_util_map< X##_property<T>, const T&> \
|
Chris@16
|
489 get(X##_property<T>, const sgb_const_graph_ptr&) { \
|
Chris@16
|
490 return sgb_##KIND##_util_map< X##_property<T>, const T&>(); \
|
Chris@16
|
491 } \
|
Chris@16
|
492 template <class T, class Key> \
|
Chris@16
|
493 inline typename \
|
Chris@16
|
494 sgb_##KIND##_util_map< X##_property<T>, const T&>::value_type \
|
Chris@16
|
495 get(X##_property<T>, const sgb_graph_ptr&, const Key& key) { \
|
Chris@16
|
496 return sgb_##KIND##_util_map< X##_property<T>, const T&>()[key]; \
|
Chris@16
|
497 } \
|
Chris@16
|
498 template <class T, class Key> \
|
Chris@16
|
499 inline typename \
|
Chris@16
|
500 sgb_##KIND##_util_map< X##_property<T>, const T&>::value_type \
|
Chris@16
|
501 get(X##_property<T>, const sgb_const_graph_ptr&, const Key& key) { \
|
Chris@16
|
502 return sgb_##KIND##_util_map< X##_property<T>, const T&>()[key]; \
|
Chris@16
|
503 } \
|
Chris@16
|
504 template <class T, class Key, class Value> \
|
Chris@16
|
505 inline void \
|
Chris@16
|
506 put(X##_property<T>, sgb_graph_ptr&, const Key& key, const Value& value) { \
|
Chris@16
|
507 sgb_##KIND##_util_map< X##_property<T>, T&>()[key] = value; \
|
Chris@16
|
508 }
|
Chris@16
|
509
|
Chris@16
|
510
|
Chris@16
|
511 SGB_UTIL_ACCESSOR(vertex, u)
|
Chris@16
|
512 SGB_UTIL_ACCESSOR(vertex, v)
|
Chris@16
|
513 SGB_UTIL_ACCESSOR(vertex, w)
|
Chris@16
|
514 SGB_UTIL_ACCESSOR(vertex, x)
|
Chris@16
|
515 SGB_UTIL_ACCESSOR(vertex, y)
|
Chris@16
|
516 SGB_UTIL_ACCESSOR(vertex, z)
|
Chris@16
|
517
|
Chris@16
|
518 SGB_UTIL_ACCESSOR(edge, a)
|
Chris@16
|
519 SGB_UTIL_ACCESSOR(edge, b)
|
Chris@16
|
520
|
Chris@16
|
521 } // namespace boost
|
Chris@16
|
522
|
Chris@16
|
523 #endif // BOOST_GRAPH_SGB_GRAPH_HPP
|