1 | <HTML> |
---|
2 | <Head> |
---|
3 | <Title>Boost Graph Library: Gürsoy-Atun Layout</Title> |
---|
4 | <script language="JavaScript" type="text/JavaScript"> |
---|
5 | <!-- |
---|
6 | function address(host, user) { |
---|
7 | var atchar = '@'; |
---|
8 | var thingy = user+atchar+host; |
---|
9 | thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>'; |
---|
10 | document.write(thingy); |
---|
11 | } |
---|
12 | //--> |
---|
13 | </script> |
---|
14 | </head> |
---|
15 | |
---|
16 | |
---|
17 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
---|
18 | ALINK="#ff0000"> |
---|
19 | <IMG SRC="../../../boost.png" |
---|
20 | ALT="C++ Boost" width="277" height="86"> |
---|
21 | |
---|
22 | <BR Clear> |
---|
23 | |
---|
24 | <TT>gursoy_atun_layout</TT> |
---|
25 | </H1> |
---|
26 | |
---|
27 | <P> |
---|
28 | |
---|
29 | <h3>Synopsis</h3> |
---|
30 | <PRE> |
---|
31 | <em>// Non-named parameter version</em> |
---|
32 | template<typename VertexListAndIncidenceGraph, typename Topology, |
---|
33 | typename PositionMap, typename VertexIndexMap, |
---|
34 | typename EdgeWeightMap> |
---|
35 | void |
---|
36 | gursoy_atun_layout(const VertexListAndIncidenceGraph& g, |
---|
37 | const Topology& space, |
---|
38 | PositionMap position, |
---|
39 | int nsteps = num_vertices(g), |
---|
40 | double diameter_initial = sqrt((double)num_vertices(g)), |
---|
41 | double diameter_final = 1, |
---|
42 | double learning_constant_initial = 0.8, |
---|
43 | double learning_constant_final = 0.2, |
---|
44 | VertexIndexMap vertex_index_map = get(vertex_index, g), |
---|
45 | EdgeWeightMap weight = dummy_property_map()); |
---|
46 | |
---|
47 | <em>// Named parameter version</em> |
---|
48 | template<typename VertexListAndIncidenceGraph, typename Topology, |
---|
49 | typename PositionMap, typename P, typename T, typename R> |
---|
50 | void |
---|
51 | gursoy_atun_layout(const VertexListAndIncidenceGraph& g, |
---|
52 | const Topology& space, |
---|
53 | PositionMap position, |
---|
54 | const bgl_named_params<P,T,R>& params = <em>all defaults</em>); |
---|
55 | |
---|
56 | <em>// Topologies</em> |
---|
57 | template<std::size_t Dims> class <a href="#convex_topology">convex_topology</a>; |
---|
58 | template<std::size_t Dims, typename RandomNumberGenerator = minstd_rand> class <a href="#hypercube_topology">hypercube_topology</a>; |
---|
59 | template<typename RandomNumberGenerator = minstd_rand> class <a href="#square_topology">square_topology</a>; |
---|
60 | template<typename RandomNumberGenerator = minstd_rand> class <a href="#cube_topology">cube_topology</a>; |
---|
61 | template<std::size_t Dims, typename RandomNumberGenerator = minstd_rand> class <a href="#ball_topology">ball_topology</a>; |
---|
62 | template<typename RandomNumberGenerator = minstd_rand> class <a href="#circle_topology">circle_topology</a>; |
---|
63 | template<typename RandomNumberGenerator = minstd_rand> class <a href="#sphere_topology">sphere_topology</a>; |
---|
64 | template<typename RandomNumberGenerator = minstd_rand> class <a href="#heart_topology">heart_topology</a>; |
---|
65 | </PRE> |
---|
66 | |
---|
67 | <h3>Description</h3> |
---|
68 | |
---|
69 | <P> This algorithm [<A HREF="bibliography.html#gursoy00">60</A>] |
---|
70 | performs layout of directed graphs, either weighted or unweighted. This |
---|
71 | algorithm is very different from the <a |
---|
72 | href="kamada_kawai_spring_layout.html">Kamada-Kawai</a> and <a |
---|
73 | href="fruchterman_reingold.html">Fruchterman-Reingold</a> algorithms, |
---|
74 | because it does not explicitly strive to layout graphs in a visually |
---|
75 | pleasing manner. Instead, it attempts to distribute the vertices |
---|
76 | uniformly within a <em>topology</em> (e.g., rectangle, sphere, heart shape), |
---|
77 | keeping vertices close to their neighbors. The algorithm itself is |
---|
78 | based on <a |
---|
79 | href="http://davis.wpi.edu/~matt/courses/soms/">Self-Organizing |
---|
80 | Maps</a>. |
---|
81 | |
---|
82 | <p> <a href="#topologies">Various topologies</a> are provided that |
---|
83 | produce different, interesting results. The <a |
---|
84 | href="#square_topology">square toplogy</a> can be used for normal |
---|
85 | display of graphs or distributing vertices for parallel computation on |
---|
86 | a process array, for instance. Other topologies, such as the <a |
---|
87 | href="#sphere_topology">sphere topology</a> (or N-dimensional <a |
---|
88 | href="#ball_topology">ball topology</a>) make sense for different |
---|
89 | problems, whereas the <a href="#heart_topology">heart topology</a> is |
---|
90 | just plain fun. One can also <a href="#topology-concept">define a |
---|
91 | topology</a> to suit other particular needs. <br> |
---|
92 | |
---|
93 | <a href="#square_topology"><img src="figs/ga-square.png"></a> |
---|
94 | <a href="#heart_topology"><img src="figs/ga-heart.png"></a> |
---|
95 | <a href="#circle_topology"><img src="figs/ga-circle.png"></a> |
---|
96 | |
---|
97 | |
---|
98 | <h3>Where Defined</h3> |
---|
99 | |
---|
100 | <a href="../../../boost/graph/gursoy_atun_layout.hpp"><tt>boost/graph/gursoy_atun_layout.hpp</tt></a> |
---|
101 | |
---|
102 | <h3>Parameters</h3> |
---|
103 | |
---|
104 | IN: <tt>const Graph& g</tt> |
---|
105 | <blockquote> |
---|
106 | The graph object on which the algorithm will be applied. The type |
---|
107 | <tt>Graph</tt> must be a model of <a |
---|
108 | href="./VertexAndEdgeListGraph.html">Vertex List Graph</a> and <a |
---|
109 | href="IncidenceGraph.html">Incidence Graph</a>. |
---|
110 | </blockquote> |
---|
111 | |
---|
112 | IN: <tt>const Topology& space</tt> |
---|
113 | <blockquote> |
---|
114 | The topology on which the graph will be layed out. The type must |
---|
115 | model the <a href="#topology-concept">Topology</a> concept. |
---|
116 | </blockquote> |
---|
117 | |
---|
118 | OUT: <tt>PositionMap position</tt> |
---|
119 | <blockquote> |
---|
120 | The property map that stores the position of each vertex. The type |
---|
121 | <tt>PositionMap</tt> must be a model of <a |
---|
122 | href="../../property_map/LvaluePropertyMap.html">Lvalue Property |
---|
123 | Map</a> such that the vertex descriptor type of <tt>Graph</tt> is |
---|
124 | convertible to its key type. Its value type must be the type of a |
---|
125 | point in the topology. |
---|
126 | </blockquote> |
---|
127 | |
---|
128 | IN: <tt>int nsteps</tt> |
---|
129 | <blockquote> |
---|
130 | The number of iterations to perform.<br> |
---|
131 | <b>Default</b>: <tt>num_vertices(g)</tt> |
---|
132 | </blockquote> |
---|
133 | |
---|
134 | IN: <tt>double diameter_initial</tt> |
---|
135 | <blockquote> |
---|
136 | When a vertex is selected to be updated, all vertices that are |
---|
137 | reachable from that vertex within a certain diameter (in graph |
---|
138 | terms) will also be updated. This diameter begins at |
---|
139 | <tt>diameter_initial</tt> in the first iteration and ends at |
---|
140 | <tt>diameter_final</tt> in the last iteration, progressing |
---|
141 | exponentially. Generally the diameter decreases, in a manner similar to |
---|
142 | the cooling schedule in <a |
---|
143 | href="fruchterman_reingold.html">Fruchterman-Reingold</a>. The |
---|
144 | diameter should typically decrease in later iterations, so this value |
---|
145 | should not be less than <tt>diameter_final</tt>.<br> |
---|
146 | <b>Default</b>: <tt>sqrt((double)num_vertices(g))</tt> |
---|
147 | </blockquote> |
---|
148 | |
---|
149 | IN: <tt>double diameter_final</tt> |
---|
150 | <blockquote> |
---|
151 | The final value of the diameter.<br> |
---|
152 | <b>Default</b>: 1.0 |
---|
153 | </blockquote> |
---|
154 | |
---|
155 | IN: <tt>double learning_constant_initial</tt> |
---|
156 | <blockquote> |
---|
157 | The learning rate affects how far vertices can moved to rearrange |
---|
158 | themselves in a given iteration. The learning rate progresses |
---|
159 | linearly from the initial value to the final value, both of which |
---|
160 | should be between 0 and 1. The learning rate should typically |
---|
161 | decrease, so the initial value should not exceed the final |
---|
162 | value.<br> <b>Default</b>: 0.8 |
---|
163 | </blockquote> |
---|
164 | |
---|
165 | IN: <tt>double learning_constant_final</tt> |
---|
166 | <blockquote> |
---|
167 | The final learning rate constant.<br> |
---|
168 | <b>Default</b>: 0.2 |
---|
169 | </blockquote> |
---|
170 | |
---|
171 | IN: <tt>VertexIndexMap vertex_index_map</tt> |
---|
172 | <blockquote> |
---|
173 | This maps each vertex to an integer in the range <tt>[0, |
---|
174 | num_vertices(g))</tt>. |
---|
175 | The type <tt>VertexIndexMap</tt> must be a model of <a |
---|
176 | href="../../property_map/ReadablePropertyMap.html">Readable Property |
---|
177 | Map</a>. The value type of the map must be an integer type. The |
---|
178 | vertex descriptor type of the graph needs to be usable as the key |
---|
179 | type of the map.<br> |
---|
180 | <b>Default:</b> <tt>get(vertex_index, g)</tt> |
---|
181 | </blockquote> |
---|
182 | |
---|
183 | IN: <tt>EdgeWeightMap weight</tt> |
---|
184 | <blockquote> |
---|
185 | This maps each edge to an weight. |
---|
186 | num_vertices(g))</tt>. This is only necessary when no |
---|
187 | displacement map is provided. |
---|
188 | The type <tt>EdgeWeightMap</tt> must be a model of <a |
---|
189 | href="../../property_map/ReadablePropertyMap.html">Readable Property |
---|
190 | Map</a>. The value type of the map must be an floating-point type |
---|
191 | compatible with <tt>double</tt>. The edge descriptor type of the |
---|
192 | graph needs to be usable as the key type of the map. When this map |
---|
193 | is a <tt>dummy_property_map</tt>, the algorithm assumes the graph is |
---|
194 | unweighted.<br> |
---|
195 | <b>Default:</b> <tt>dummy_property_map()</tt> |
---|
196 | </blockquote> |
---|
197 | |
---|
198 | <h3>Named Parameters</h3> |
---|
199 | |
---|
200 | IN: <tt>iterations(int n)</tt> |
---|
201 | <blockquote> |
---|
202 | Executes the algorithm for <em>n</em> iterations.<br> |
---|
203 | <b>Default:</b> <tt>num_vertices(g)</tt> |
---|
204 | </blockquote> |
---|
205 | |
---|
206 | IN: <tt>diameter_range(std::pair<T, T> range)</tt> |
---|
207 | <blockquote> |
---|
208 | Range specifying the parameters (<tt>diameter_initial</tt>, <tt>diameter_final</tt>). <br> |
---|
209 | <b>Default:</b> <tt>std::make_pair(sqrt((double)num_vertices(g)), 1.0)</tt> |
---|
210 | </blockquote> |
---|
211 | |
---|
212 | IN: <tt>learning_constant_range(std::pair<T, T> range)</tt> |
---|
213 | <blockquote> |
---|
214 | Range specifying the parameters (<tt>learning_constant_initial</tt>, <tt>learning_constant_final</tt>). <br> |
---|
215 | <b>Default:</b> <tt>std::make_pair(0.8, 0.2)</tt> |
---|
216 | </blockquote> |
---|
217 | |
---|
218 | IN: <tt>edge_weight(EdgeWeightMap weight)</tt> |
---|
219 | <blockquote> |
---|
220 | Equivalent to the non-named <tt>weight</tt> parameter.<br> |
---|
221 | <b>Default:</b> <tt>dummy_property_map()</tt> |
---|
222 | </blockquote> |
---|
223 | |
---|
224 | IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt> |
---|
225 | <blockquote> |
---|
226 | Equivalent to the non-named <tt>vertex_index_map</tt> parameter.<br> |
---|
227 | <b>Default:</b> <tt>get(vertex_index, g)</tt> |
---|
228 | </blockquote> |
---|
229 | |
---|
230 | <a name="topologies"><h3>Topologies</h3></a> |
---|
231 | A topology is a description of a space on which layout can be |
---|
232 | performed. Some common two, three, and multidimensional topologies |
---|
233 | are provided, or you may create your own so long as it meets the |
---|
234 | requirements of the <a href="#topology-concept">Topology concept</a>. |
---|
235 | |
---|
236 | <a name="topology-concept"><h4>Topology Concept</h4></a> Let |
---|
237 | <tt>Topology</tt> be a model of the Toplogy concept and let |
---|
238 | <tt>space</tt> be an object of type <tt>Topology</tt>. <tt>p1</tt> and |
---|
239 | <tt>p2</tt> are objects of associated type <tt>point_type</tt> (see |
---|
240 | below). The following expressions must be valid: |
---|
241 | |
---|
242 | <table border="1"> |
---|
243 | <tr> |
---|
244 | <th>Expression</th> |
---|
245 | <th>Type</th> |
---|
246 | <th>Description</th> |
---|
247 | </tr> |
---|
248 | <tr> |
---|
249 | <td><tt>Topology::point_type</tt></td> |
---|
250 | <td>type</td> |
---|
251 | <td>The type of points in the space.</td> |
---|
252 | </tr> |
---|
253 | <tr> |
---|
254 | <td><tt>space.random_point()</tt></td> |
---|
255 | <td>point_type</td> |
---|
256 | <td>Returns a random point (usually uniformly distributed) within |
---|
257 | the space.</td> |
---|
258 | </tr> |
---|
259 | <tr> |
---|
260 | <td><tt>space.distance(p1, p2)</tt></td> |
---|
261 | <td>double</td> |
---|
262 | <td>Get a quantity representing the distance between <tt>p1</tt> |
---|
263 | and <tt>p2</tt> using a path going completely inside the space. |
---|
264 | This only needs to have the same < relation as actual |
---|
265 | distances, and does not need to satisfy the other properties of a |
---|
266 | norm in a Banach space.</td> |
---|
267 | </tr> |
---|
268 | <tr> |
---|
269 | <td><tt>space.move_position_toward(p1, fraction, p2)</tt></td> |
---|
270 | <td>point_type</td> |
---|
271 | <td>Returns a point that is a fraction of the way from <tt>p1</tt> |
---|
272 | to <tt>p2</tt>, moving along a "line" in the space according to |
---|
273 | the distance measure. <tt>fraction</tt> is a <tt>double</tt> |
---|
274 | between 0 and 1, inclusive.</td> |
---|
275 | </tr> |
---|
276 | </table> |
---|
277 | |
---|
278 | <a name="convex_topology"><h3>Class template <tt>convex_topology</tt></h3></a> |
---|
279 | |
---|
280 | <p>Class template <tt>convex_topology</tt> implements the basic |
---|
281 | distance and point movement functions for any convex topology in |
---|
282 | <tt>Dims</tt> dimensions. It is not itself a topology, but is intended |
---|
283 | as a base class that any convex topology can derive from. The derived |
---|
284 | topology need only provide a suitable <tt>random_point</tt> function |
---|
285 | that returns a random point within the space. |
---|
286 | |
---|
287 | <pre> |
---|
288 | template<std::size_t Dims> |
---|
289 | class convex_topology |
---|
290 | { |
---|
291 | struct point |
---|
292 | { |
---|
293 | point() { } |
---|
294 | double& operator[](std::size_t i) {return values[i];} |
---|
295 | const double& operator[](std::size_t i) const {return values[i];} |
---|
296 | |
---|
297 | private: |
---|
298 | double values[Dims]; |
---|
299 | }; |
---|
300 | |
---|
301 | public: |
---|
302 | typedef point point_type; |
---|
303 | |
---|
304 | double distance(point a, point b) const; |
---|
305 | point move_position_toward(point a, double fraction, point b) const; |
---|
306 | }; |
---|
307 | </pre> |
---|
308 | |
---|
309 | <a name="hypercube_topology"><h3>Class template <tt>hypercube_topology</tt></h3></a> |
---|
310 | |
---|
311 | <p>Class template <tt>hypercube_topology</tt> implements a |
---|
312 | <tt>Dims</tt>-dimensional hypercube. It is a convex topology whose |
---|
313 | points are drawn from a random number generator of type |
---|
314 | <tt>RandomNumberGenerator</tt>. The <tt>hypercube_topology</tt> can |
---|
315 | be constructed with a given random number generator; if omitted, a |
---|
316 | new, default-constructed random number generator will be used. The |
---|
317 | resulting layout will be contained within the hypercube, whose sides |
---|
318 | measure 2*<tt>scaling</tt> long (points will fall in the range |
---|
319 | [-<tt>scaling</tt>, <tt>scaling</tt>] in each dimension). |
---|
320 | |
---|
321 | <pre> |
---|
322 | template<std::size_t Dims, typename RandomNumberGenerator = minstd_rand> |
---|
323 | class hypercube_topology : public <a href="#convex_topology">convex_topology</a><Dims> |
---|
324 | { |
---|
325 | public: |
---|
326 | explicit hypercube_topology(double scaling = 1.0); |
---|
327 | hypercube_topology(RandomNumberGenerator& gen, double scaling = 1.0); |
---|
328 | point_type random_point() const; |
---|
329 | }; |
---|
330 | </pre> |
---|
331 | |
---|
332 | <a name="square_topology"><h3>Class template <tt>square_topology</tt></h3></a> |
---|
333 | |
---|
334 | <p>Class template <tt>square_topology</tt> is a two-dimensional |
---|
335 | hypercube topology. |
---|
336 | |
---|
337 | <pre> |
---|
338 | template<typename RandomNumberGenerator = minstd_rand> |
---|
339 | class square_topology : public <a href="#hypercube_topology">hypercube_topology</a><2, RandomNumberGenerator> |
---|
340 | { |
---|
341 | public: |
---|
342 | explicit square_topology(double scaling = 1.0); |
---|
343 | square_topology(RandomNumberGenerator& gen, double scaling = 1.0); |
---|
344 | }; |
---|
345 | </pre> |
---|
346 | |
---|
347 | <a name="cube_topology"><h3>Class template <tt>cube_topology</tt></h3></a> |
---|
348 | |
---|
349 | <p>Class template <tt>cube_topology</tt> is a two-dimensional |
---|
350 | hypercube topology. |
---|
351 | |
---|
352 | <pre> |
---|
353 | template<typename RandomNumberGenerator = minstd_rand> |
---|
354 | class cube_topology : public <a href="#hypercube_topology">hypercube_topology</a><3, RandomNumberGenerator> |
---|
355 | { |
---|
356 | public: |
---|
357 | explicit cube_topology(double scaling = 1.0); |
---|
358 | cube_topology(RandomNumberGenerator& gen, double scaling = 1.0); |
---|
359 | }; |
---|
360 | </pre> |
---|
361 | |
---|
362 | <a name="ball_topology"><h3>Class template <tt>ball_topology</tt></h3></a> |
---|
363 | |
---|
364 | <p>Class template <tt>ball_topology</tt> implements a |
---|
365 | <tt>Dims</tt>-dimensional ball. It is a convex topology whose points |
---|
366 | are drawn from a random number generator of type |
---|
367 | <tt>RandomNumberGenerator</tt> but reside inside the ball. The |
---|
368 | <tt>ball_topology</tt> can be constructed with a given random number |
---|
369 | generator; if omitted, a new, default-constructed random number |
---|
370 | generator will be used. The resulting layout will be contained within |
---|
371 | the ball with the given <tt>radius</tt>. |
---|
372 | |
---|
373 | <pre> |
---|
374 | template<std::size_t Dims, typename RandomNumberGenerator = minstd_rand> |
---|
375 | class ball_topology : public <a href="#convex_topology">convex_topology</a><Dims> |
---|
376 | { |
---|
377 | public: |
---|
378 | explicit ball_topology(double radius = 1.0); |
---|
379 | ball_topology(RandomNumberGenerator& gen, double radius = 1.0); |
---|
380 | point_type random_point() const; |
---|
381 | }; |
---|
382 | </pre> |
---|
383 | |
---|
384 | <a name="circle_topology"><h3>Class template <tt>circle_topology</tt></h3></a> |
---|
385 | |
---|
386 | <p>Class template <tt>circle_topology</tt> is a two-dimensional |
---|
387 | ball topology. |
---|
388 | |
---|
389 | <pre> |
---|
390 | template<typename RandomNumberGenerator = minstd_rand> |
---|
391 | class circle_topology : public <a href="#ball_topology">ball_topology</a><2, RandomNumberGenerator> |
---|
392 | { |
---|
393 | public: |
---|
394 | explicit circle_topology(double radius = 1.0); |
---|
395 | circle_topology(RandomNumberGenerator& gen, double radius = 1.0); |
---|
396 | }; |
---|
397 | </pre> |
---|
398 | |
---|
399 | <a name="sphere_topology"><h3>Class template <tt>sphere_topology</tt></h3></a> |
---|
400 | |
---|
401 | <p>Class template <tt>sphere_topology</tt> is a two-dimensional |
---|
402 | ball topology. |
---|
403 | |
---|
404 | <pre> |
---|
405 | template<typename RandomNumberGenerator = minstd_rand> |
---|
406 | class sphere_topology : public <a href="#ball_topology">ball_topology</a><3, RandomNumberGenerator> |
---|
407 | { |
---|
408 | public: |
---|
409 | explicit sphere_topology(double radius = 1.0); |
---|
410 | sphere_topology(RandomNumberGenerator& gen, double radius = 1.0); |
---|
411 | }; |
---|
412 | </pre> |
---|
413 | |
---|
414 | <a name="heart_topology"><h3>Class template <tt>heart_topology</tt></h3></a> |
---|
415 | |
---|
416 | <p>Class template <tt>heart_topology</tt> is topology in the shape of |
---|
417 | a heart. It serves as an example of a non-convex, nontrivial topology |
---|
418 | for layout. |
---|
419 | |
---|
420 | <pre> |
---|
421 | template<typename RandomNumberGenerator = minstd_rand> |
---|
422 | class heart_topology |
---|
423 | { |
---|
424 | public: |
---|
425 | typedef <em>unspecified</em> point_type; |
---|
426 | |
---|
427 | heart_topology(); |
---|
428 | heart_topology(RandomNumberGenerator& gen); |
---|
429 | point_type random_point() const; |
---|
430 | double distance(point_type a, point_type b) const; |
---|
431 | point_type move_position_toward(point_type a, double fraction, point_type b) const; |
---|
432 | }; |
---|
433 | </pre> |
---|
434 | |
---|
435 | <br> |
---|
436 | <HR> |
---|
437 | <TABLE> |
---|
438 | <TR valign=top> |
---|
439 | <TD nowrap>Copyright © 2004</TD><TD> |
---|
440 | Jeremiah Willcock, Indiana University (<script language="Javascript">address("osl.iu.edu", "jewillco")</script>)<br> |
---|
441 | <A HREF="../../../people/doug_gregor.html">Doug Gregor</A>, Indiana University (<script language="Javascript">address("cs.indiana.edu", "dgregor")</script>)<br> |
---|
442 | <A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>, |
---|
443 | Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>) |
---|
444 | </TD></TR></TABLE> |
---|
445 | |
---|
446 | </BODY> |
---|
447 | </HTML> |
---|