sorted_unique_rmat_generator.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .. Copyright (C) 2004-2009 The Trustees of Indiana University.
  2. Use, modification and distribution is subject to the Boost Software
  3. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. http://www.boost.org/LICENSE_1_0.txt)
  5. ====================================
  6. |Logo| Sorted unique R-MAT generator
  7. ====================================
  8. ::
  9. template<typename RandomGenerator, typename Graph,
  10. typename EdgePredicate = keep_all_edges>
  11. class sorted_unique_rmat_iterator
  12. {
  13. public:
  14. typedef std::input_iterator_tag iterator_category;
  15. typedef std::pair<vertices_size_type, vertices_size_type> value_type;
  16. typedef const value_type& reference;
  17. typedef const value_type* pointer;
  18. typedef void difference_type;
  19. sorted_unique_rmat_iterator();
  20. sorted_unique_rmat_iterator(RandomGenerator& gen, vertices_size_type n,
  21. edges_size_type m, double a, double b, double c,
  22. double d, bool bidirectional = true,
  23. bool permute_vertices = true,
  24. EdgePredicate ep = keep_all_edges());
  25. // Iterator operations
  26. reference operator*() const;
  27. pointer operator->() const;
  28. sorted_unique_rmat_iterator& operator++();
  29. sorted_unique_rmat_iterator operator++(int);
  30. bool operator==(const sorted_unique_rmat_iterator& other) const;
  31. bool operator!=(const sorted_unique_rmat_iterator& other) const;
  32. };
  33. This class template implements a generator for R-MAT graphs [CZF04]_,
  34. suitable for initializing an adjacency_list or other graph structure
  35. with iterator-based initialization. An R-MAT graph has a scale-free
  36. distribution w.r.t. vertex degree and is implemented using
  37. Recursive-MATrix partitioning. The output of this generator is sorted
  38. for use with a `compressed sparse row graph`_. The edge list produced by
  39. this iterator is guaranteed not to contain parallel edges.
  40. Where Defined
  41. -------------
  42. <``boost/graph/rmat_graph_generator.hpp``>
  43. Constructors
  44. ------------
  45. ::
  46. sorted_unique_rmat_iterator();
  47. Constructs a past-the-end iterator.
  48. ::
  49. sorted_unique_rmat_iterator(RandomGenerator& gen, vertices_size_type n,
  50. edges_size_type m, double a, double b, double c,
  51. double d, bool bidirectional = false,
  52. bool permute_vertices = true,
  53. EdgePredicate ep = keep_all_edges());
  54. Constructs an R-MAT generator iterator that creates a graph with ``n``
  55. vertices and ``m`` edges. ``a``, ``b``, ``c``, and ``d`` represent
  56. the probability that a generated edge is placed of each of the 4
  57. quadrants of the partitioned adjacency matrix. Probabilities are
  58. drawn from the random number generator ``gen``. Vertex indices are
  59. permuted to eliminate locality when ``permute_vertices`` is true.
  60. When ``bidirectional`` is ``true`` for every edge s-t, the
  61. corresponding anti-edge t-s is added as well, these anti-edges are not
  62. counted towards ``m``. ``ep`` allows the user to specify which edges
  63. are retained, this is useful in the case where the user wishes to
  64. refrain from storing remote edges locally during generation to reduce
  65. memory consumption.
  66. Example
  67. -------
  68. ::
  69. #include <boost/graph/distributed/mpi_process_group.hpp>
  70. #include <boost/graph/compressed_sparse_row_graph.hpp>
  71. #include <boost/graph/rmat_graph_generator.hpp>
  72. #include <boost/random/linear_congruential.hpp>
  73. using boost::graph::distributed::mpi_process_group;
  74. typedef compressed_sparse_row_graph<directedS, no_property, no_property, no_property,
  75. distributedS<mpi_process_group> > Graph;
  76. typedef keep_local_edges<boost::parallel::variant_distribution<mpi_process_group>,
  77. mpi_process_group::process_id_type> EdgeFilter;
  78. typedef boost::sorted_unique_rmat_iterator<boost::minstd_rand, Graph> RMATGen;
  79. int main()
  80. {
  81. boost::minstd_rand gen;
  82. mpi_process_group pg;
  83. int N = 100;
  84. boost::parallel::variant_distribution<ProcessGroup> distrib
  85. = boost::parallel::block(pg, N);
  86. mpi_process_group::process_id_type id = process_id(pg);
  87. // Create graph with 100 nodes and 400 edges
  88. Graph g(RMATGen(gen, N, 400, 0.57, 0.19, 0.19, 0.05, true,
  89. true, EdgeFilter(distrib, id)),
  90. RMATGen(), N, pg, distrib);
  91. return 0;
  92. }
  93. Bibliography
  94. ------------
  95. .. [CZF04] D Chakrabarti, Y Zhan, and C Faloutsos. R-MAT: A Recursive
  96. Model for Graph Mining. In Proceedings of 4th International Conference
  97. on Data Mining, pages 442--446, 2004.
  98. -----------------------------------------------------------------------------
  99. Copyright (C) 2009 The Trustees of Indiana University.
  100. Authors: Nick Edmonds and Andrew Lumsdaine
  101. .. |Logo| image:: pbgl-logo.png
  102. :align: middle
  103. :alt: Parallel BGL
  104. :target: http://www.osl.iu.edu/research/pbgl
  105. .. _compressed sparse row graph: http://www.boost.org/libs/graph/doc/compressed_sparse_row.html