Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/boost/graph/random_layout.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.6 KB
Line 
1// Copyright 2004 The Trustees of Indiana University.
2
3// Use, modification and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7//  Authors: Douglas Gregor
8//           Andrew Lumsdaine
9#ifndef BOOST_GRAPH_RANDOM_LAYOUT_HPP
10#define BOOST_GRAPH_RANDOM_LAYOUT_HPP
11
12#include <boost/graph/graph_traits.hpp>
13#include <boost/random/uniform_int.hpp>
14#include <boost/random/uniform_01.hpp>
15#include <boost/random/uniform_real.hpp>
16#include <boost/type_traits/is_integral.hpp>
17#include <boost/mpl/if.hpp>
18
19namespace boost {
20
21template<typename Graph, typename PositionMap, typename Dimension, 
22         typename RandomNumberGenerator>
23void
24random_graph_layout(const Graph& g, PositionMap position_map,
25                    Dimension minX, Dimension maxX, 
26                    Dimension minY, Dimension maxY,
27                    RandomNumberGenerator& gen)
28{
29  typedef typename mpl::if_<is_integral<Dimension>,
30                            uniform_int<Dimension>,
31                            uniform_real<Dimension> >::type distrib_t;
32  typedef typename mpl::if_<is_integral<Dimension>,
33                            RandomNumberGenerator&,
34                            uniform_01<RandomNumberGenerator, Dimension> >
35    ::type gen_t;
36
37  gen_t my_gen(gen);
38  distrib_t x(minX, maxX);
39  distrib_t y(minY, maxY);
40  typename graph_traits<Graph>::vertex_iterator vi, vi_end;
41  for(tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
42    position_map[*vi].x = x(my_gen);
43    position_map[*vi].y = y(my_gen);
44  }
45}
46
47} // end namespace boost
48
49#endif // BOOST_GRAPH_RANDOM_LAYOUT_HPP
Note: See TracBrowser for help on using the repository browser.