edge_list.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 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: Edge List Class</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:edge-list-class"></A>
  16. <PRE>
  17. edge_list&lt;EdgeIterator, ValueType, DiffType&gt;
  18. </PRE>
  19. </H1>
  20. <P>
  21. The <TT>edge_list</TT> class is an adaptor that turns a pair of edge
  22. iterators into a class that models <TT>EdgeListGraph</TT>. The
  23. <TT>value_type</TT> of the edge iterator must be a <TT>std::pair</TT> (or
  24. at least have <TT>first</TT> and <TT>second</TT> members). The
  25. <TT>first_type</TT> and <TT>second_type</TT> of the pair must be the
  26. same and they will be used for the graph's <TT>vertex_descriptor</TT>.
  27. The <TT>ValueType</TT> and <TT>DiffType</TT> template parameters are only
  28. needed if your compiler does not support partial
  29. specialization. Otherwise they default to the correct types.
  30. <P>
  31. <H3>Example</H3>
  32. <P>
  33. Applying the Bellman-Ford shortest paths algorithm to an
  34. <TT>edge_list</TT>.
  35. <P>
  36. <PRE>
  37. enum { u, v, x, y, z, N };
  38. char name[] = { 'u', 'v', 'x', 'y', 'z' };
  39. typedef std::pair&lt;int,int&gt; E;
  40. E edges[] = { E(u,y), E(u,x), E(u,v),
  41. E(v,u),
  42. E(x,y), E(x,v),
  43. E(y,v), E(y,z),
  44. E(z,u), E(z,x) };
  45. int weight[] = { -4, 8, 5,
  46. -2,
  47. 9, -3,
  48. 7, 2,
  49. 6, 7 };
  50. typedef boost::edge_list&lt;E*&gt; Graph;
  51. Graph g(edges, edges + sizeof(edges) / sizeof(E));
  52. std::vector&lt;int&gt; distance(N, std::numeric_limits&lt;short&gt;::max());
  53. std::vector&lt;int&gt; parent(N,-1);
  54. distance[z] = 0;
  55. parent[z] = z;
  56. bool r = boost::bellman_ford_shortest_paths(g, int(N), weight,
  57. distance.begin(),
  58. parent.begin());
  59. if (r)
  60. for (int i = 0; i &lt; N; ++i)
  61. std::cout &lt;&lt; name[i] &lt;&lt; ": " &lt;&lt; distance[i]
  62. &lt;&lt; " " &lt;&lt; name[parent[i]] &lt;&lt; std::endl;
  63. else
  64. std::cout &lt;&lt; "negative cycle" &lt;&lt; std::endl;
  65. </PRE>
  66. The output is the distance from the root and the parent
  67. of each vertex in the shortest paths tree.
  68. <PRE>
  69. u: 2 v
  70. v: 4 x
  71. x: 7 z
  72. y: -2 u
  73. z: 0 z
  74. </PRE>
  75. <P>
  76. <p>
  77. <H3>Where Defined</H3>
  78. <a href="../../../boost/graph/edge_list.hpp"><TT>boost/graph/edge_list.hpp</TT></a>
  79. <P>
  80. <H3>Template Parameters</H3>
  81. <P>
  82. <TABLE border>
  83. <TR>
  84. <th>Parameter</th><th>Description</th>
  85. </tr>
  86. <TR><TD><TT>EdgeIterator</TT></TD> <TD>Must be model of <a
  87. href="http://www.boost.org/sgi/stl/InputIterator.html">InputIterator</a>
  88. who's <TT>value_type</TT> must be a pair of vertex descriptors.</TD>
  89. </TR>
  90. <TR><TD><TT>ValueType</TT></TD>
  91. <TD>The <TT>value_type</TT> of the <TT>EdgeIterator</TT>.<br>
  92. Default: <TT>std::iterator_traits&lt;EdgeIterator&gt;::value_type</TT></TD>
  93. </TR>
  94. <TR><TD><TT>DiffType</TT></TD>
  95. <TD>The <TT>difference_type</TT> of the <TT>EdgeIterator</TT>.<br>
  96. Default: <TT>std::iterator_traits&lt;EdgeIterator&gt;::difference_type</TT></TD>
  97. </TR>
  98. </TABLE>
  99. <P>
  100. <H3>Model of</H3>
  101. <a href="./EdgeListGraph.html">EdgeListGraph</a>
  102. <P>
  103. <H3>Associated Types</H3>
  104. <hr>
  105. <tt>boost::graph_traits&lt;edge_list&gt;::vertex_descriptor</tt>
  106. <br><br>
  107. The type for the vertex descriptors associated with the
  108. <TT>edge_list</TT>. This will be the same type as
  109. <TT>std::iterator_traits&lt;EdgeIterator&gt;::value_type::first_type</TT>.
  110. <hr>
  111. <tt>
  112. boost::graph_traits&lt;edge_list&gt;::edge_descriptor
  113. </tt>
  114. <br><br>
  115. The type for the edge descriptors associated with the
  116. <TT>edge_list</TT>.
  117. <hr>
  118. <tt>
  119. boost::graph_traits&lt;edge_list&gt;::edge_iterator
  120. </tt>
  121. <br><br>
  122. The type for the iterators returned by <TT>edges()</TT>. The iterator
  123. category of the <TT>edge_iterator</TT> will be the same as that of the
  124. <TT>EdgeIterator</TT>.
  125. <hr>
  126. <h3>Member Functions</h3>
  127. <hr>
  128. <tt>
  129. edge_list(EdgeIterator first, EdgeIterator last)
  130. </tt>
  131. <br><br>
  132. Creates a graph object with <TT>n</TT> vertices and with the
  133. edges specified in the edge list given by the range <TT>[first,last)</TT>.
  134. <hr>
  135. <H3>Non-Member Functions</H3>
  136. <hr>
  137. <tt>
  138. std::pair&lt;edge_iterator, edge_iterator&gt;<br>
  139. edges(const edge_list&amp; g)
  140. </tt>
  141. <br><br>
  142. Returns an iterator-range providing access to the edge set of graph <TT>g</TT>.
  143. <hr>
  144. <tt>
  145. vertex_descriptor<br>
  146. source(edge_descriptor e, const edge_list&amp; g)
  147. </tt>
  148. <br><br>
  149. Returns the source vertex of edge <TT>e</TT>.
  150. <hr>
  151. <tt>
  152. vertex_descriptor<br>
  153. target(edge_descriptor e, const edge_list&amp; g)
  154. </tt>
  155. <br><br>
  156. Returns the target vertex of edge <TT>e</TT>.
  157. <hr>
  158. <br>
  159. <HR>
  160. <TABLE>
  161. <TR valign=top>
  162. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  163. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
  164. Indiana University (<A
  165. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  166. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br>
  167. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  168. Indiana University (<A
  169. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  170. </TD></TR></TABLE>
  171. </BODY>
  172. </HTML>