directed_graph.hpp 24 KB

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