reverse_graph.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <HTML>
  2. <!--
  3. (C) Copyright David Abrahams and Jeremy Siek 2000.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Boost Graph Library: Reverse Graph Adaptor</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H1><A NAME="sec:reverse-graph-adaptor"></A>
  16. </h1>
  17. <pre>
  18. reverse_graph&lt;<a href="./BidirectionalGraph.html">BidirectionalGraph</a>, GraphReference&gt;
  19. </pre>
  20. The <tt>reverse_graph</tt> adaptor flips the in-edges and out-edges of
  21. a <a href="./BidirectionalGraph.html">BidirectionalGraph</a>,
  22. effectively transposing the graph. The construction of the
  23. <tt>reverse_graph</tt> is constant time, providing a highly efficient
  24. way to obtain a transposed view of a graph.
  25. <H3>Example</H3>
  26. The example from <a
  27. href="../example/reverse-graph-eg.cpp"><tt>examples/reverse-graph-eg.cpp</tt></a>.
  28. <pre>
  29. int
  30. main()
  31. {
  32. typedef boost::adjacency_list&lt;
  33. boost::vecS, boost::vecS, boost::bidirectionalS,
  34. &gt; Graph;
  35. Graph G(5);
  36. boost::add_edge(0, 2, G);
  37. boost::add_edge(1, 1, G);
  38. boost::add_edge(1, 3, G);
  39. boost::add_edge(1, 4, G);
  40. boost::add_edge(2, 1, G);
  41. boost::add_edge(2, 3, G);
  42. boost::add_edge(2, 4, G);
  43. boost::add_edge(3, 1, G);
  44. boost::add_edge(3, 4, G);
  45. boost::add_edge(4, 0, G);
  46. boost::add_edge(4, 1, G);
  47. std::cout &lt;&lt; &quot;original graph:&quot; &lt;&lt; std::endl;
  48. boost::print_graph(G, boost::get(boost::vertex_index, G));
  49. std::cout &lt;&lt; std::endl &lt;&lt; &quot;reversed graph:&quot; &lt;&lt; std::endl;
  50. boost::print_graph(boost::make_reverse_graph(G),
  51. boost::get(boost::vertex_index, G));
  52. return 0;
  53. }
  54. </pre>
  55. The output is:
  56. <pre>
  57. original graph:
  58. 0 --&gt; 2
  59. 1 --&gt; 1 3 4
  60. 2 --&gt; 1 3 4
  61. 3 --&gt; 1 4
  62. 4 --&gt; 0 1
  63. reversed graph:
  64. 0 --&gt; 4
  65. 1 --&gt; 1 2 3 4
  66. 2 --&gt; 0
  67. 3 --&gt; 1 2
  68. 4 --&gt; 1 2 3
  69. </pre>
  70. <H3>Template Parameters</H3>
  71. <P>
  72. <TABLE border>
  73. <TR>
  74. <th>Parameter</th><th>Description</th><th>Default</th>
  75. </tr>
  76. <TR><TD><TT>BidirectionalGraph</TT></TD>
  77. <TD>The graph type to be adapted.</TD>
  78. <TD>&nbsp;</TD>
  79. </TR>
  80. <TR><TD><TT>GraphReference</TT></TD>
  81. <TD>This type should be <tt>const&nbsp;BidirectionalGraph&amp;</tt>
  82. if you want to create a const reverse graph, or <tt>BidirectionalGraph&amp;</tt> if you want to create a non-const reverse graph.</TD>
  83. <TD><tt>const&nbsp;BidirectionalGraph&amp;</tt></TD>
  84. </TR>
  85. </table>
  86. <H3>Model of</H3>
  87. <P>
  88. <a href="./BidirectionalGraph.html">BidirectionalGraph</a>
  89. and optionally
  90. <a href="./VertexListGraph.html">VertexListGraph</a>
  91. and <a href="./PropertyGraph.html">PropertyGraph</a>
  92. <H3>Where Defined</H3>
  93. <P>
  94. <a href="../../../boost/graph/reverse_graph.hpp"><TT>boost/graph/reverse_graph.hpp</TT></a>
  95. <H2>Associated Types</H2>
  96. <hr>
  97. <tt>graph_traits&lt;reverse_graph&gt;::vertex_descriptor</tt>
  98. <br><br>
  99. The type for the vertex descriptors associated with the
  100. <TT>reverse_graph</TT>.
  101. <hr>
  102. <tt>graph_traits&lt;reverse_graph&gt;::edge_descriptor</tt>
  103. <br><br>
  104. The type for the edge descriptors associated with the
  105. <TT>reverse_graph</TT>.
  106. <hr>
  107. <tt>graph_traits&lt;reverse_graph&gt;::vertex_iterator</tt>
  108. <br><br>
  109. The type for the iterators returned by <TT>vertices()</TT>.
  110. <hr>
  111. <tt>graph_traits&lt;reverse_graph&gt;::edge_iterator</tt>
  112. <br><br>
  113. The type for the iterators returned by <TT>edges()</TT>.
  114. <hr>
  115. <tt>graph_traits&lt;reverse_graph&gt;::out_edge_iterator</tt>
  116. <br><br>
  117. The type for the iterators returned by <TT>out_edges()</TT>.
  118. <hr>
  119. <tt>graph_traits&lt;reverse_graph&gt;::adjacency_iterator</tt>
  120. <br><br>
  121. The type for the iterators returned by <TT>adjacent_vertices()</TT>.
  122. <hr>
  123. <tt>graph_traits&lt;reverse_graph&gt;::directed_category</tt>
  124. <br><br>
  125. Provides information about whether the graph is
  126. directed (<TT>directed_tag</TT>) or undirected
  127. (<TT>undirected_tag</TT>).
  128. <hr>
  129. <tt>graph_traits&lt;reverse_graph&gt;::edge_parallel_category</tt>
  130. <br><br>
  131. This describes whether the graph class allows the insertion of
  132. parallel edges (edges with the same source and target). The two tags
  133. are <TT>allow_parallel_edge-_tag</TT> and
  134. <TT>disallow_parallel_edge_tag</TT>. The
  135. <TT>setS</TT> and <TT>hash_setS</TT> variants disallow
  136. parallel edges while the others allow parallel edges.
  137. <hr>
  138. <tt>graph_traits&lt;reverse_graph&gt;::vertices_size_type</tt>
  139. <br><br>
  140. The type used for dealing with the number of vertices in the graph.
  141. <hr>
  142. <tt>graph_traits&lt;reverse_graph&gt;::edges_size_type</tt>
  143. <br><br>
  144. The type used for dealing with the number of edges in the graph.
  145. <hr>
  146. <tt>graph_traits&lt;reverse_graph&gt;::degree_size_type</tt>
  147. <br><br>
  148. The type used for dealing with the number of edges incident to a vertex
  149. in the graph.
  150. <hr>
  151. <tt>property_map&lt;reverse_graph, PropertyTag&gt;::type</tt><br>
  152. and<br>
  153. <tt>property_map&lt;reverse_graph, PropertyTag&gt;::const_type</tt>
  154. <br><br>
  155. The property map type for vertex or edge properties in the graph. The
  156. specific property is specified by the <TT>PropertyTag</TT> template argument,
  157. and must match one of the properties specified in the
  158. <TT>VertexProperty</TT> or <TT>EdgeProperty</TT> for the graph.
  159. <hr>
  160. <tt>property_map&lt;reverse_graph, edge_underlying_t&gt;::type</tt><br>
  161. and<br>
  162. <tt>property_map&lt;reverse_graph, edge_underlying_t&gt;::const_type</tt>
  163. <br><br>
  164. An edge property type mapping from edge descriptors in the <tt>reverse_graph</tt> to
  165. edge descriptors in the underlying <tt>BidirectionalGraph</tt> object.
  166. <hr>
  167. <H2>Member Functions</H2>
  168. <hr>
  169. <pre>
  170. reverse_graph(BidirectionalGraph&amp;&nbsp;g)
  171. </pre>
  172. Constructor. Create a reversed (transposed) view of the graph <tt>g</tt>.
  173. <hr>
  174. <H2>Non-Member Functions</H2>
  175. <hr>
  176. <pre>
  177. template &lt;class BidirectionalGraph&gt;
  178. reverse_graph&lt;BidirectionalGraph, BidirectionalGraph&amp;&gt;
  179. make_reverse_graph(BidirectionalGraph&amp; g);
  180. template &lt;class BidirectionalGraph&gt;
  181. reverse_graph&lt;BidirectionalGraph, const BidirectionalGraph&amp;&gt;
  182. make_reverse_graph(const BidirectionalGraph&amp; g)
  183. </pre>
  184. Helper function for creating a <tt>reverse_graph</tt>.
  185. <hr>
  186. <pre>
  187. std::pair&lt;vertex_iterator,&nbsp;vertex_iterator&gt;
  188. vertices(const reverse_graph&amp; g)
  189. </pre>
  190. Returns an iterator-range providing access to the vertex set of graph
  191. <tt>g</tt>.
  192. <hr>
  193. <pre>
  194. std::pair&lt;out_edge_iterator,&nbsp;out_edge_iterator&gt;
  195. out_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
  196. </pre>
  197. Returns an iterator-range providing access to the out-edges of vertex
  198. <tt>v</tt> in graph <tt>g</tt>. These out-edges correspond to the
  199. in-edges of the adapted graph.
  200. <hr>
  201. <pre>
  202. std::pair&lt;in_edge_iterator,&nbsp;in_edge_iterator&gt;
  203. in_edges(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
  204. </pre>
  205. Returns an iterator-range providing access to the in-edges of vertex
  206. <tt>v</tt> in graph <tt>g</tt>. These in-edges correspond to the
  207. out edges of the adapted graph.
  208. <hr>
  209. <pre>
  210. std::pair&lt;adjacency_iterator,&nbsp;adjacency__iterator&gt;
  211. adjacent_vertices(vertex_descriptor&nbsp;v, const&nbsp;reverse_graph&amp;&nbsp;g)
  212. </pre>
  213. Returns an iterator-range providing access to the adjacent vertices of vertex
  214. <tt>v</tt> in graph <tt>g</tt>.
  215. <hr>
  216. <pre>
  217. vertex_descriptor
  218. source(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
  219. </pre>
  220. Returns the source vertex of edge <tt>e</tt>.
  221. <hr>
  222. <pre>
  223. vertex_descriptor
  224. target(edge_descriptor&nbsp;e, const&nbsp;reverse_graph&amp;&nbsp;g)
  225. </pre>
  226. Returns the target vertex of edge <tt>e</tt>.
  227. <hr>
  228. <pre>
  229. degree_size_type
  230. out_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
  231. </pre>
  232. Returns the number of edges leaving vertex <tt>u</tt>.
  233. <hr>
  234. <pre>
  235. degree_size_type
  236. in_degree(vertex_descriptor&nbsp;u, const&nbsp;reverse_graph&amp;&nbsp;g)
  237. </pre>
  238. Returns the number of edges entering vertex <tt>u</tt>. This operation
  239. is only available if <TT>bidirectionalS</TT> was specified for
  240. the <TT>Directed</TT> template parameter.
  241. <hr>
  242. <pre>
  243. vertices_size_type
  244. num_vertices(const reverse_graph&amp; g)
  245. </pre>
  246. Returns the number of vertices in the graph <tt>g</tt>.
  247. <hr>
  248. <pre>
  249. vertex_descriptor
  250. vertex(vertices_size_type&nbsp;n, const&nbsp;reverse_graph&amp;&nbsp;g)
  251. </pre>
  252. Returns the nth vertex in the graph's vertex list.
  253. <hr>
  254. <pre>
  255. std::pair&lt;edge_descriptor, bool&gt;
  256. edge(vertex_descriptor&nbsp;u, vertex_descriptor&nbsp;v,
  257. const&nbsp;reverse_graph&amp;&nbsp;g)
  258. </pre>
  259. Returns the edge connecting vertex <tt>u</tt> to vertex <tt>v</tt> in
  260. graph <tt>g</tt>.
  261. <hr>
  262. <pre>
  263. template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
  264. property_map&lt;reverse_graph, PropertyTag&gt;::type
  265. get(PropertyTag, reverse_graph&amp; g)
  266. template &lt;class <a href="./PropertyTag.html">PropertyTag</a>&gt;
  267. property_map&lt;reverse_graph, Tag&gt;::const_type
  268. get(PropertyTag, const reverse_graph&amp; g)
  269. </pre>
  270. Returns the property map object for the vertex property specified by
  271. <TT>PropertyTag</TT>. The <TT>PropertyTag</TT> must match one of the
  272. properties specified in the graph's <TT>VertexProperty</TT> template
  273. argument.
  274. <hr>
  275. <pre>
  276. property_map&lt;reverse_graph, edge_underlying_t&gt;::const_type
  277. get(PropertyTag, const reverse_graph&amp; g)
  278. </pre>
  279. Returns a property map object that converts from edge descriptors in the
  280. <tt>reverse_graph</tt> to edge descriptors in the underlying
  281. <tt>BidirectionalGraph</tt> object.
  282. <hr>
  283. <pre>
  284. template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X&gt;
  285. typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::const_type&gt;::value_type
  286. get(PropertyTag, const reverse_graph&amp; g, X x)
  287. </pre>
  288. This returns the property value for <tt>x</tt>, which is either
  289. a vertex or edge descriptor.
  290. <hr>
  291. <pre>
  292. typename graph_traits&lt;BidirectionalGraph&gt;::edge_descriptor
  293. get(edge_underlying_t, const reverse_graph&amp; g, edge_descriptor e)
  294. </pre>
  295. This returns the underlying edge descriptor for the edge <tt>e</tt> in the <tt>reverse_graph</tt>.
  296. <hr>
  297. <pre>
  298. template &lt;class <a href="./PropertyTag.html">PropertyTag</a>, class X, class Value&gt;
  299. void
  300. put(PropertyTag, const reverse_graph&amp; g, X x, const Value&amp; value)
  301. </pre>
  302. This sets the property value for <tt>x</tt> to
  303. <tt>value</tt>. <tt>x</tt> is either a vertex or edge descriptor.
  304. <tt>Value</tt> must be convertible to
  305. <tt>typename property_traits&lt;property_map&lt;reverse_graph, PropertyTag&gt;::type&gt::value_type</tt>
  306. <hr>
  307. <pre>
  308. template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
  309. typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
  310. get_property(reverse_graph&amp; g, GraphPropertyTag);
  311. </pre>
  312. Return the property specified by <tt>GraphPropertyTag</tt> that is
  313. attached to the graph object <tt>g</tt>. The <tt>property_value</tt>
  314. traits class is defined in <a
  315. href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.
  316. <hr>
  317. <pre>
  318. template &lt;class GraphProperties, class <a href="./PropertyTag.html#GraphPropertyTag">GraphPropertyTag</a>&gt;
  319. const typename property_value&lt;GraphProperties, GraphPropertyTag&gt;::type&amp;
  320. get_property(const reverse_graph&amp; g, GraphPropertyTag);
  321. </pre>
  322. Return the property specified by <tt>GraphPropertyTag</tt> that is
  323. attached to the graph object <tt>g</tt>. The <tt>property_value</tt>
  324. traits class is defined in <a
  325. href="../../../boost/pending/property.hpp"><tt>boost/pending/property.hpp</tt></a>.
  326. <hr>
  327. <br>
  328. <HR>
  329. <TABLE>
  330. <TR valign=top>
  331. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  332. <a HREF="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>
  333. (<A HREF="mailto:david.abrahams@rcn.com">david.abrahams@rcn.com</A>)<br>
  334. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
  335. Indiana University (<A
  336. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  337. </TD></TR></TABLE>
  338. </BODY>
  339. </HTML>