topology.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <HTML>
  2. <!--
  3. Copyright (c) 2004, 2010 Trustees of Indiana University
  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: Topologies for Graph Drawing</Title>
  10. <script language="JavaScript" type="text/JavaScript">
  11. <!--
  12. function address(host, user) {
  13. var atchar = '@';
  14. var thingy = user+atchar+host;
  15. thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
  16. document.write(thingy);
  17. }
  18. //-->
  19. </script>
  20. </head>
  21. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  22. ALINK="#ff0000">
  23. <IMG SRC="../../../boost.png"
  24. ALT="C++ Boost" width="277" height="86">
  25. <BR Clear>
  26. <H1>
  27. Topologies for Graph Drawing
  28. </H1>
  29. <P>
  30. <h3>Synopsis</h3>
  31. <pre>
  32. template&lt;std::size_t Dims&gt; class <a href="#convex_topology">convex_topology</a>;
  33. template&lt;std::size_t Dims, typename RandomNumberGenerator = minstd_rand&gt; class <a href="#hypercube_topology">hypercube_topology</a>;
  34. template&lt;typename RandomNumberGenerator = minstd_rand&gt; class <a href="#square_topology">square_topology</a>;
  35. template&lt;typename RandomNumberGenerator = minstd_rand&gt; class <a href="#cube_topology">cube_topology</a>;
  36. template&lt;std::size_t Dims, typename RandomNumberGenerator = minstd_rand&gt; class <a href="#ball_topology">ball_topology</a>;
  37. template&lt;typename RandomNumberGenerator = minstd_rand&gt; class <a href="#circle_topology">circle_topology</a>;
  38. template&lt;typename RandomNumberGenerator = minstd_rand&gt; class <a href="#sphere_topology">sphere_topology</a>;
  39. template&lt;typename RandomNumberGenerator = minstd_rand&gt; class <a href="#heart_topology">heart_topology</a>;
  40. </pre>
  41. <h3>Summary</h3>
  42. <p> <a href="#topologies">Various topologies</a> are provided that
  43. produce different, interesting results for graph layout algorithms. The <a
  44. href="#square_topology">square topology</a> can be used for normal
  45. display of graphs or distributing vertices for parallel computation on
  46. a process array, for instance. Other topologies, such as the <a
  47. href="#sphere_topology">sphere topology</a> (or N-dimensional <a
  48. href="#ball_topology">ball topology</a>) make sense for different
  49. problems, whereas the <a href="#heart_topology">heart topology</a> is
  50. just plain fun. One can also <a href="#topology-concept">define a
  51. topology</a> to suit other particular needs. <br>
  52. <a name="topologies"><h3>Topologies</h3></a>
  53. A topology is a description of a space on which layout can be
  54. performed. Some common two, three, and multidimensional topologies
  55. are provided, or you may create your own so long as it meets the
  56. requirements of the <a href="#topology-concept">Topology concept</a>.
  57. <a name="topology-concept"><h4>Topology Concept</h4></a> Let
  58. <tt>Topology</tt> be a model of the Topology concept and let
  59. <tt>space</tt> be an object of type <tt>Topology</tt>. <tt>p1</tt> and
  60. <tt>p2</tt> are objects of associated type <tt>point_type</tt> (see
  61. below). The following expressions must be valid:
  62. <table border="1">
  63. <tr>
  64. <th>Expression</th>
  65. <th>Type</th>
  66. <th>Description</th>
  67. </tr>
  68. <tr>
  69. <td><tt>Topology::point_type</tt></td>
  70. <td>type</td>
  71. <td>The type of points in the space.</td>
  72. </tr>
  73. <tr>
  74. <td><tt>space.random_point()</tt></td>
  75. <td>point_type</td>
  76. <td>Returns a random point (usually uniformly distributed) within
  77. the space.</td>
  78. </tr>
  79. <tr>
  80. <td><tt>space.distance(p1, p2)</tt></td>
  81. <td>double</td>
  82. <td>Get a quantity representing the distance between <tt>p1</tt>
  83. and <tt>p2</tt> using a path going completely inside the space.
  84. This only needs to have the same &lt; relation as actual
  85. distances, and does not need to satisfy the other properties of a
  86. norm in a Banach space.</td>
  87. </tr>
  88. <tr>
  89. <td><tt>space.move_position_toward(p1, fraction, p2)</tt></td>
  90. <td>point_type</td>
  91. <td>Returns a point that is a fraction of the way from <tt>p1</tt>
  92. to <tt>p2</tt>, moving along a "line" in the space according to
  93. the distance measure. <tt>fraction</tt> is a <tt>double</tt>
  94. between 0 and 1, inclusive.</td>
  95. </tr>
  96. </table>
  97. <a name="convex_topology"><h3>Class template <tt>convex_topology</tt></h3></a>
  98. <p>Class template <tt>convex_topology</tt> implements the basic
  99. distance and point movement functions for any convex topology in
  100. <tt>Dims</tt> dimensions. It is not itself a topology, but is intended
  101. as a base class that any convex topology can derive from. The derived
  102. topology need only provide a suitable <tt>random_point</tt> function
  103. that returns a random point within the space.
  104. <pre>
  105. template&lt;std::size_t Dims&gt;
  106. class convex_topology
  107. {
  108. struct point
  109. {
  110. point() { }
  111. double&amp; operator[](std::size_t i) {return values[i];}
  112. const double&amp; operator[](std::size_t i) const {return values[i];}
  113. private:
  114. double values[Dims];
  115. };
  116. public:
  117. typedef point point_type;
  118. double distance(point a, point b) const;
  119. point move_position_toward(point a, double fraction, point b) const;
  120. };
  121. </pre>
  122. <a name="hypercube_topology"><h3>Class template <tt>hypercube_topology</tt></h3></a>
  123. <p>Class template <tt>hypercube_topology</tt> implements a
  124. <tt>Dims</tt>-dimensional hypercube. It is a convex topology whose
  125. points are drawn from a random number generator of type
  126. <tt>RandomNumberGenerator</tt>. The <tt>hypercube_topology</tt> can
  127. be constructed with a given random number generator; if omitted, a
  128. new, default-constructed random number generator will be used. The
  129. resulting layout will be contained within the hypercube, whose sides
  130. measure 2*<tt>scaling</tt> long (points will fall in the range
  131. [-<tt>scaling</tt>, <tt>scaling</tt>] in each dimension).
  132. <pre>
  133. template&lt;std::size_t Dims, typename RandomNumberGenerator = minstd_rand&gt;
  134. class hypercube_topology : public <a href="#convex_topology">convex_topology</a>&lt;Dims&gt;
  135. {
  136. public:
  137. explicit hypercube_topology(double scaling = 1.0);
  138. hypercube_topology(RandomNumberGenerator&amp; gen, double scaling = 1.0);
  139. point_type random_point() const;
  140. };
  141. </pre>
  142. <a name="square_topology"><h3>Class template <tt>square_topology</tt></h3></a>
  143. <p>Class template <tt>square_topology</tt> is a two-dimensional
  144. hypercube topology.
  145. <pre>
  146. template&lt;typename RandomNumberGenerator = minstd_rand&gt;
  147. class square_topology : public <a href="#hypercube_topology">hypercube_topology</a>&lt;2, RandomNumberGenerator&gt;
  148. {
  149. public:
  150. explicit square_topology(double scaling = 1.0);
  151. square_topology(RandomNumberGenerator&amp; gen, double scaling = 1.0);
  152. };
  153. </pre>
  154. <a name="cube_topology"><h3>Class template <tt>cube_topology</tt></h3></a>
  155. <p>Class template <tt>cube_topology</tt> is a three-dimensional
  156. hypercube topology.
  157. <pre>
  158. template&lt;typename RandomNumberGenerator = minstd_rand&gt;
  159. class cube_topology : public <a href="#hypercube_topology">hypercube_topology</a>&lt;3, RandomNumberGenerator&gt;
  160. {
  161. public:
  162. explicit cube_topology(double scaling = 1.0);
  163. cube_topology(RandomNumberGenerator&amp; gen, double scaling = 1.0);
  164. };
  165. </pre>
  166. <a name="ball_topology"><h3>Class template <tt>ball_topology</tt></h3></a>
  167. <p>Class template <tt>ball_topology</tt> implements a
  168. <tt>Dims</tt>-dimensional ball. It is a convex topology whose points
  169. are drawn from a random number generator of type
  170. <tt>RandomNumberGenerator</tt> but reside inside the ball. The
  171. <tt>ball_topology</tt> can be constructed with a given random number
  172. generator; if omitted, a new, default-constructed random number
  173. generator will be used. The resulting layout will be contained within
  174. the ball with the given <tt>radius</tt>.
  175. <pre>
  176. template&lt;std::size_t Dims, typename RandomNumberGenerator = minstd_rand&gt;
  177. class ball_topology : public <a href="#convex_topology">convex_topology</a>&lt;Dims&gt;
  178. {
  179. public:
  180. explicit ball_topology(double radius = 1.0);
  181. ball_topology(RandomNumberGenerator&amp; gen, double radius = 1.0);
  182. point_type random_point() const;
  183. };
  184. </pre>
  185. <a name="circle_topology"><h3>Class template <tt>circle_topology</tt></h3></a>
  186. <p>Class template <tt>circle_topology</tt> is a two-dimensional
  187. ball topology.
  188. <pre>
  189. template&lt;typename RandomNumberGenerator = minstd_rand&gt;
  190. class circle_topology : public <a href="#ball_topology">ball_topology</a>&lt;2, RandomNumberGenerator&gt;
  191. {
  192. public:
  193. explicit circle_topology(double radius = 1.0);
  194. circle_topology(RandomNumberGenerator&amp; gen, double radius = 1.0);
  195. };
  196. </pre>
  197. <a name="sphere_topology"><h3>Class template <tt>sphere_topology</tt></h3></a>
  198. <p>Class template <tt>sphere_topology</tt> is a three-dimensional
  199. ball topology.
  200. <pre>
  201. template&lt;typename RandomNumberGenerator = minstd_rand&gt;
  202. class sphere_topology : public <a href="#ball_topology">ball_topology</a>&lt;3, RandomNumberGenerator&gt;
  203. {
  204. public:
  205. explicit sphere_topology(double radius = 1.0);
  206. sphere_topology(RandomNumberGenerator&amp; gen, double radius = 1.0);
  207. };
  208. </pre>
  209. <a name="heart_topology"><h3>Class template <tt>heart_topology</tt></h3></a>
  210. <p>Class template <tt>heart_topology</tt> is topology in the shape of
  211. a heart. It serves as an example of a non-convex, nontrivial topology
  212. for layout.
  213. <pre>
  214. template&lt;typename RandomNumberGenerator = minstd_rand&gt;
  215. class heart_topology
  216. {
  217. public:
  218. typedef <em>unspecified</em> point_type;
  219. heart_topology();
  220. heart_topology(RandomNumberGenerator&amp; gen);
  221. point_type random_point() const;
  222. double distance(point_type a, point_type b) const;
  223. point_type move_position_toward(point_type a, double fraction, point_type b) const;
  224. };
  225. </pre>
  226. <br>
  227. <HR>
  228. <TABLE>
  229. <TR valign=top>
  230. <TD nowrap>Copyright &copy; 2004, 2010 Trustees of Indiana University</TD><TD>
  231. Jeremiah Willcock, Indiana University (<script language="Javascript">address("osl.iu.edu", "jewillco")</script>)<br>
  232. <A HREF="http://www.boost.org/people/doug_gregor.html">Doug Gregor</A>, Indiana University (<script language="Javascript">address("cs.indiana.edu", "dgregor")</script>)<br>
  233. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  234. Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
  235. </TD></TR></TABLE>
  236. </BODY>
  237. </HTML>