AdjacencyGraph.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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>AdjacencyGraph</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><A NAME="concept:AdjacencyGraph"></A>
  16. AdjacencyGraph
  17. </H2>
  18. The AdjacencyGraph concept provides and interface for efficient access
  19. of the adjacent vertices to a vertex in a graph. This is quite similar
  20. to the <a href="./IncidenceGraph.html">IncidenceGraph</a> concept (the
  21. target of an out-edge is an adjacent vertex). Both concepts are
  22. provided because in some contexts there is only concern for the
  23. vertices, whereas in other contexts the edges are also important.
  24. <H3>Refinement of</H3>
  25. <a href="Graph.html">Graph</a>
  26. <h3>Notation</h3>
  27. <Table>
  28. <TR>
  29. <TD><tt>G</tt></TD>
  30. <TD>A type that is a model of Graph.</TD>
  31. </TR>
  32. <TR>
  33. <TD><tt>g</tt></TD>
  34. <TD>An object of type <tt>G</tt>.</TD>
  35. </TR>
  36. <TR>
  37. <TD><tt>v</tt></TD>
  38. <TD>An object of type <tt>boost::graph_traits&lt;G&gt;::vertex_descriptor</tt>.</TD>
  39. </TR>
  40. </table>
  41. <H3>Associated Types</H3>
  42. <Table border>
  43. <tr>
  44. <td><tt>boost::graph_traits&lt;G&gt;::traversal_category</tt><br><br>
  45. This tag type must be convertible to <tt>adjacency_graph_tag</tt>.
  46. </td>
  47. </tr>
  48. <TR>
  49. <TD><pre>boost::graph_traits&lt;G&gt;::adjacency_iterator</pre>
  50. An adjacency iterator for a vertex <i>v</i> provides access to the
  51. vertices adjacent to <i>v</i>. As such, the value type of an
  52. adjacency iterator is the vertex descriptor type of its graph. An
  53. adjacency iterator must meet the requirements of <a
  54. href="../../utility/MultiPassInputIterator.html">MultiPassInputIterator</a>.
  55. </TD>
  56. </TR>
  57. </table>
  58. <h3>Valid Expressions</h3>
  59. <table border>
  60. <tr>
  61. <td><a name="sec:adjacent-vertices"><TT>adjacent_vertices(v,&nbsp;g)</TT></a></TD>
  62. <TD>
  63. Returns an iterator-range providing access to the vertices adjacent to
  64. vertex <TT>v</TT> in graph <TT>g</TT>.<a
  65. href="#1">[1]</a>
  66. <br> Return type:
  67. <TT>std::pair&lt;adjacency_iterator,&nbsp;adjacency_iterator&gt;</TT>
  68. </TD>
  69. </TR>
  70. </table>
  71. <H3>Complexity guarantees</H3>
  72. The <TT>adjacent_vertices()</TT> function must return in constant time.
  73. <H3>See Also</H3>
  74. <a href="./graph_concepts.html">Graph concepts</a>,
  75. <a href="./adjacency_iterator.html"><tt>adjacency_iterator</tt></a>
  76. <H3>Concept Checking Class</H3>
  77. <PRE>
  78. template &lt;class G&gt;
  79. struct AdjacencyGraphConcept
  80. {
  81. typedef typename boost::graph_traits&lt;G&gt;::adjacency_iterator
  82. adjacency_iterator;
  83. void constraints() {
  84. BOOST_CONCEPT_ASSERT(( MultiPassInputIteratorConcept&lt;adjacency_iterator&gt; ));
  85. p = adjacent_vertices(v, g);
  86. v = *p.first;
  87. const_constraints(g);
  88. }
  89. void const_constraints(const G&amp; g) {
  90. p = adjacent_vertices(v, g);
  91. }
  92. std::pair&lt;adjacency_iterator,adjacency_iterator&gt; p;
  93. typename boost::graph_traits&lt;G&gt;::vertex_descriptor v;
  94. G g;
  95. };
  96. </PRE>
  97. <h3>Design Rationale</h3>
  98. The AdjacencyGraph concept is somewhat frivolous since <a
  99. href="./IncidenceGraph.html">IncidenceGraph</a> really covers the same
  100. functionality (and more). The AdjacencyGraph concept exists because
  101. there are situations when <tt>adjacent_vertices()</tt> is more
  102. convenient to use than <tt>out_edges()</tt>. If you are constructing a
  103. graph class and do not want to put in the extra work of creating an
  104. adjacency iterator, have no fear. There is an adaptor class named <a
  105. href="./adjacency_iterator.html"> <tt>adjacency_iterator</tt></a> that
  106. you can use to create an adjacency iterator out of an out-edge
  107. iterator.
  108. <h3>Notes</h3>
  109. <a name="1">[1]</a> The case of a
  110. <I>multigraph</I> (where multiple edges can connect the same two
  111. vertices) brings up an issue as to whether the iterators returned by
  112. the <TT>adjacent_vertices()</TT> function access a range that
  113. includes each adjacent vertex once, or whether it should match the
  114. behavior of the <TT>out_edges()</TT> function, and access a
  115. range that may include an adjacent vertex more than once. For now the
  116. behavior is defined to match that of <TT>out_edges()</TT>,
  117. though this decision may need to be reviewed in light of more
  118. experience with graph algorithm implementations.
  119. <br>
  120. <HR>
  121. <TABLE>
  122. <TR valign=top>
  123. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  124. <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>)
  125. </TD></TR></TABLE>
  126. </BODY>
  127. </HTML>