fruchterman_reingold.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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: Fruchterman-Reingold Force-Directed Layout</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. <img src="figs/python.gif" alt="(Python)"/>
  16. <TT>fruchterman_reingold_force_directed_layout</TT>
  17. </H1>
  18. <P>
  19. <PRE>
  20. <i>// named parameter version</i>
  21. template&lt;typename Graph, typename PositionMap, typename Topology, typename Param,
  22. typename Tag, typename Rest&gt;
  23. void
  24. fruchterman_reingold_force_directed_layout
  25. (const Graph&amp; g,
  26. PositionMap position,
  27. const Topology&amp; space,
  28. const bgl_named_params&lt;Param, Tag, Rest&gt;&amp; params);
  29. <i>// non-named parameter version</i>
  30. template&lt;typename Graph, typename PositionMap, typename Topology,
  31. typename AttractiveForce, typename RepulsiveForce,
  32. typename ForcePairs, typename DisplacementMap, typename Cooling&gt;
  33. void
  34. fruchterman_reingold_force_directed_layout
  35. (const Graph&amp; g,
  36. PositionMap position,
  37. const Topology&amp; space,
  38. AttractiveForce fa,
  39. RepulsiveForce fr,
  40. ForcePairs fp,
  41. Cooling cool,
  42. DisplacementMap displacement);
  43. template&lt;typename Graph, typename PositionMap, typename Topology&gt;
  44. void
  45. fruchterman_reingold_force_directed_layout(const Graph&amp; g,
  46. PositionMap position,
  47. Topology&amp; space,
  48. Dim width,
  49. Dim height);
  50. </PRE>
  51. <P> This algorithm&nbsp;[<A
  52. HREF="bibliography.html#fruchterman91">58</A>] performs layout of
  53. unweighted, undirected graphs. Unlike the <a
  54. href="kamada_kawai_spring_layout.html">Kamada-Kawai</a> layout
  55. algorithm, this algorithm directly supports the layout of disconnected
  56. graphs (but see the <tt>force_pairs</tt> named parameter). It is a
  57. <em>force-directed</em> algorithm, meaning that vertex layout is
  58. determined by the forces pulling vertices together and pushing them
  59. apart. Attractive forces occur between adjacent vertices only, whereas
  60. repulsive forces occur between every pair of vertices. Each iteration
  61. computes the sum of the forces on each vertex, then moves the vertices
  62. to their new positions. The movement of vertices is mitigated by the
  63. <i>temperature</i> of the system for that iteration: as the algorithm
  64. progresses through successive iterations, the temperature should
  65. decrease so that vertices settle in place. The cooling schedule,
  66. attractive forces, and repulsive forces can be provided by the user.
  67. <p> The vertices are often placed randomly prior to execution of this algorithm via <a href="random_layout.html"><tt>random_graph_layout</tt></a>.
  68. <h3>Where Defined</h3>
  69. <a href="../../../boost/graph/fruchterman_reingold.hpp"><tt>boost/graph/fruchterman_reingold.hpp</tt></a>
  70. <h3>Parameters</h3>
  71. IN: <tt>const Graph&amp; g</tt>
  72. <blockquote>
  73. The graph object on which the algorithm will be applied.
  74. The type <tt>Graph</tt> must be a model of
  75. <a href="./VertexAndEdgeListGraph.html">Vertex And Edge List Graph</a>.<br>
  76. <b>Python</b>: This parameter is named <tt>graph</tt> in Python.
  77. </blockquote>
  78. IN/OUT: <tt>PositionMap position</tt>
  79. <blockquote>
  80. The property map that stores the position of each vertex. It should
  81. typically be initialized with the vertices at random locations (use
  82. <a href="random_layout.html"><tt>random_graph_layout</tt></a>). The
  83. type <tt>PositionMap</tt> must be a model of <a
  84. href="../../property_map/doc/LvaluePropertyMap.html">Lvalue Property
  85. Map</a> such that the vertex descriptor type of <tt>Graph</tt> is
  86. convertible to its key type. Its value type must be
  87. <tt>Topology::point_type</tt>, representing the coordinates
  88. of the vertex.<br>
  89. <b>Python</b>: The position map must be a <tt>vertex_point2d_map</tt> for
  90. the graph.<br>
  91. <b>Python default</b>: <tt>graph.get_vertex_point2d_map("position")</tt>
  92. </blockquote>
  93. IN: <tt>const Topology&amp; space</tt>
  94. <blockquote>
  95. The topology used to lay out the vertices. This parameter describes both the
  96. size and shape of the layout area. Topologies are described in more detail
  97. (with a list of BGL-provided topologies) <a href="topology.html">in separate
  98. documentation</a>.
  99. </blockquote>
  100. <h3>Named Parameters</h3>
  101. IN: <tt>attractive_force(AttractiveForce fa)</tt>
  102. <blockquote>
  103. Computes the magnitude of the attractive force between two adjacent
  104. vertices. The function object <tt>fa</tt> must accept four
  105. parameters: the edge descriptor, <tt>k</tt>, the distance between the
  106. vertices, and the graph. <tt>k</tt> is the square root of the ratio
  107. of the display area to the number of vertices. <br>
  108. <b>Default:</b> <tt>square_distance_attractive_force()</tt>, which
  109. computes the attractive force as <code>dist<sup>2</sup>/k</code>.<br>
  110. <b>Python</b>: Any callable Python object that matches the signature will suffice.
  111. </blockquote>
  112. IN: <tt>repulsive_force(RepulsiveForce fr)</tt>
  113. <blockquote>
  114. Computes the magnitude of the repulsive force between any two
  115. vertices. The function object <tt>fr</tt> must accept five
  116. parameters: the two vertex descriptors, <tt>k</tt>, the distance between the
  117. vertices, and the graph. <tt>k</tt> is the square root of the ratio
  118. of the display area to the number of vertices. <br>
  119. <b>Default:</b> <tt>square_distance_repsulsive_force()</tt>, which
  120. computes the repulsive force as <code>k<sup>2</sup>/dist</code>.<br>
  121. <b>Python</b>: Any callable Python object that matches the signature will suffice.
  122. </blockquote>
  123. IN: <tt>force_pairs(ForcePairs fp)</tt>
  124. <blockquote>
  125. Enumerates the pairs of vertices on which the repulsive force should
  126. be applied. <tt>fp</tt> is a function object taking two parameters:
  127. the graph <tt>g</tt> and a binary function object that should be
  128. passed each pair of vertices to be considered. The basic formulation
  129. of the Fruchterman-Reingold algorithm computes repulsive forces
  130. between all pairs of vertices (pass <tt>all_force_pairs()</tt> for
  131. this parameter), which is functional for disconnected graphs but
  132. tends to push the connected components toward the edges of the
  133. display area. The grid variant of the algorithm places a grid over
  134. the display area and only computes repulsive forces among vertices
  135. within each rectangle in the grid. The grid variant can be more
  136. efficient than the basic formulation and tends to produce better
  137. layouts for disconnected graphs, but is not better overall: pass
  138. <tt>make_grid_force_pairs(width, height, position, g)</tt> as this
  139. parameter to use the grid variant. Other enumeration strategies may
  140. yield better results for particular graphs. <br>
  141. <b>Default:</b> <tt>make_grid_force_pairs(width, height, position, g)</tt><br>
  142. <b>Python</b>: Unsupported parameter.
  143. </blockquote>
  144. IN: <tt>cooling(Cooling cool)</tt>
  145. <blockquote>
  146. Determines the cooling schedule for the algorithm, which affects the
  147. rate of movement of vertices and termination of the algorithm. The
  148. <tt>cool</tt> parameter is a nullary function object (i.e., one that
  149. takes no arguments) and returns the temperature for the current
  150. iteration. When the returned temperature is zero, the algorithm
  151. terminates. Cooling schedules should begin with some initial
  152. temperature and gradually reduce the temperature to zero.<br>
  153. <b>Default:</b> <tt>linear_cooling&lt;double&gt;(100)</tt><br>
  154. <b>Python</b>: Any callable Python object that matches the signature will suffice.
  155. </blockquote>
  156. UTIL: <tt>displacement_map(DisplacementMap displacement)</tt>
  157. <blockquote>
  158. The displacement map is used to compute the amount by which each
  159. vertex will move in each step. The <tt>DisplacementMap</tt> type must be a
  160. property map whose key type is the graph's vertex type and whose value type is
  161. <tt>Topology::point_difference_type</tt>.<br>
  162. <b>Default:</b> An <tt>iterator_property_map</tt> with the specified value type
  163. and using the given vertex index map.<br>
  164. <b>Python:</b> Unsupported parameter.
  165. </blockquote>
  166. IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
  167. <blockquote>
  168. This maps each vertex to an integer in the range <tt>[0,
  169. num_vertices(g))</tt>. This is only necessary when no
  170. displacement map is provided.
  171. The type <tt>VertexIndexMap</tt> must be a model of <a
  172. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  173. Map</a>. The value type of the map must be an integer type. The
  174. vertex descriptor type of the graph needs to be usable as the key
  175. type of the map.<br>
  176. <b>Default:</b> <tt>get(vertex_index, g)</tt>
  177. Note: if you use this default, make sure your graph has
  178. an internal <tt>vertex_index</tt> property. For example,
  179. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  180. not have an internal <tt>vertex_index</tt> property.
  181. <br>
  182. <b>Python:</b> Unsupported parameter.
  183. </blockquote>
  184. <b>Python</b> IN: <tt>bool progressive</tt>
  185. <blockquote>
  186. When <tt>false</tt>, performs a random layout of the graph before
  187. running the Fruchterman-Reingold algorithm. If <tt>true</tt>, the
  188. algorithm is executing starting with the vertex configuration in
  189. the <tt>position</tt> map.<br>
  190. <b>Default</b>: <tt>False</tt>.
  191. </blockquote>
  192. <H3>Complexity</H3>
  193. <P> The time complexity is <i>O(|V|<sup>2</sup> + |E|)</i> for each
  194. iteration of the algorithm in the worst case. The average case for the
  195. grid variant is <i>O(|V| + |E|)</i>. The number of iterations is
  196. determined by the cooling schedule.
  197. <H3>Example</H3>
  198. <a href="../example/fr_layout.cpp">libs/graph/example/fr_layout.cpp</a>
  199. <br>
  200. <HR>
  201. <TABLE>
  202. <TR valign=top>
  203. <TD nowrap>Copyright &copy; 2004, 2010 Trustees of Indiana University</TD><TD>
  204. <A HREF="http://www.boost.org/people/doug_gregor.html">Doug Gregor</A>, Indiana University
  205. </TD></TR></TABLE>
  206. </BODY>
  207. </HTML>