BidirectionalGraph.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <HTML>
  2. <!--
  3. Copyright (c) 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>Bidirectional</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. <H2>
  16. <A NAME="concept:BidirectionalGraph"></A>
  17. BidirectionalGraph
  18. </H2>
  19. <P>
  20. The BidirectionalGraph concept refines <a
  21. href="./IncidenceGraph.html">IncidenceGraph</a> and adds the
  22. requirement for efficient access to the in-edges of each vertex. This
  23. concept is separated from <a
  24. href="./IncidenceGraph.html">IncidenceGraph</a> because for directed
  25. graphs efficient access to in-edges typically requires more storage
  26. space, and many algorithms do not require access to in-edges. For
  27. undirected graphs this is not an issue, since the <TT>in_edges()</TT>
  28. and <TT>out_edges()</TT> functions are the same, they both return the
  29. edges incident to the vertex.
  30. <H3>Refinement of</H3>
  31. <a href="./IncidenceGraph.html">IncidenceGraph</a>
  32. <h3>Notation</h3>
  33. <Table>
  34. <TR>
  35. <TD><tt>G</tt></TD>
  36. <TD>A type that is a model of Graph.</TD>
  37. </TR>
  38. <TR>
  39. <TD><tt>g</tt></TD>
  40. <TD>An object of type <tt>G</tt>.</TD>
  41. </TR>
  42. <TR>
  43. <TD><tt>v</tt></TD>
  44. <TD>An object of type <tt>boost::graph_traits&lt;G&gt;::vertex_descriptor</tt>.</TD>
  45. </TR>
  46. </table>
  47. <H3>Associated Types</H3>
  48. <Table border>
  49. <tr>
  50. <td><tt>boost::graph_traits&lt;G&gt;::traversal_category</tt><br><br>
  51. This tag type must be convertible to <tt>bidirectional_graph_tag</tt>.
  52. </td>
  53. </tr>
  54. <TR>
  55. <TD><pre>boost::graph_traits&lt;G&gt;::in_edge_iterator</pre>
  56. An in-edge iterator for a vertex <i>v</i> provides access to the
  57. in-edges of <i>v</i>. As such, the value type of an in-edge iterator
  58. is the edge descriptor type of its graph. An in-edge iterator must
  59. meet the requirements of <a href="../../utility/MultiPassInputIterator.html">MultiPassInputIterator</a>.
  60. </TD>
  61. </TR>
  62. </Table>
  63. <h3>Valid Expressions</h3>
  64. <Table border>
  65. <tr>
  66. <td><a name="sec:in-edges"><TT>in_edges(v, g)</TT></a></TD>
  67. <TD>
  68. Returns an iterator-range providing access to the
  69. in-edges (for directed graphs) or incident edges (for
  70. undirected graphs) of vertex <TT>v</TT> in graph <TT>g</TT>.
  71. For both directed and undirected graphs, the target of
  72. an out-edge is required to be vertex <tt>v</tt> and the
  73. source is required to be a vertex that is adjacent to <tt>v</tt>.
  74. <br>
  75. Return type: <TT>std::pair&lt;in_edge_iterator, in_edge_iterator&gt;</TT>
  76. </TD>
  77. </TR>
  78. <tr>
  79. <TD><TT>in_degree(v, g)</TT></TD>
  80. <TD>
  81. Returns the number of in-edges (for directed graphs) or the
  82. number of incident edges (for undirected graphs) of vertex <TT>v</TT>
  83. in graph <TT>g</TT>.<br>
  84. Return type: <TT>degree_size_type</TT>
  85. </TD>
  86. </TR>
  87. <tr>
  88. <TD><TT>degree(v, g)</TT></TD>
  89. <TD>Returns the number of in-edges plus out-edges (for directed graphs) or the
  90. number of incident edges (for undirected graphs) of vertex <TT>v</TT>
  91. in graph <TT>g</TT>.<br>
  92. Return type: <TT>degree_size_type</TT>
  93. </TD>
  94. </TR>
  95. </Table>
  96. <H3>Models</H3>
  97. <ul>
  98. <li><a href="./adjacency_list.html"><tt>adjacency_list</tt></a> with <tt>Directed=bidirectionalS</tt></li>
  99. <li><a href="./adjacency_list.html"><tt>adjacency_list</tt></a> with <tt>Directed=undirectedS</tt></li>
  100. </ul>
  101. <H3>Complexity guarantees</H3>
  102. The <TT>in_edges()</TT> function is required to be constant time. The
  103. <tt>in_degree()</tt> and <tt>degree()</tt> functions must be linear in
  104. the number of in-edges (for directed graphs) or incident edges (for
  105. undirected graphs).
  106. <H3>See Also</H3>
  107. <a href="./graph_concepts.html">Graph concepts</a>
  108. <H3>Concept Checking Class</H3>
  109. <PRE>
  110. template &lt;class G&gt;
  111. struct BidirectionalGraphConcept
  112. {
  113. typedef typename boost::graph_traits&lt;G&gt;::in_edge_iterator
  114. in_edge_iterator;
  115. void constraints() {
  116. BOOST_CONCEPT_ASSERT(( IncidenceGraphConcept&lt;G&gt; ));
  117. BOOST_CONCEPT_ASSERT(( MultiPassInputIteratorConcept&lt;in_edge_iterator&gt; ));
  118. p = in_edges(v, g);
  119. n = in_degree(v, g);
  120. n = degree(v, g);
  121. e = *p.first;
  122. const_constraints(g);
  123. }
  124. void const_constraints(const G&amp; g) {
  125. p = in_edges(v, g);
  126. n = in_degree(v, g);
  127. n = degree(v, g);
  128. e = *p.first;
  129. }
  130. std::pair&lt;in_edge_iterator, in_edge_iterator&gt; p;
  131. typename boost::graph_traits&lt;G&gt;::vertex_descriptor v;
  132. typename boost::graph_traits&lt;G&gt;::edge_descriptor e;
  133. typename boost::graph_traits&lt;G&gt;::degree_size_type n;
  134. G g;
  135. };
  136. </PRE>
  137. <br>
  138. <HR>
  139. <TABLE>
  140. <TR valign=top>
  141. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  142. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)
  143. </TD></TR></TABLE>
  144. </BODY>
  145. </HTML>