undirected_graph.hpp 24 KB

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