generator_test.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 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. // Authors: Nicholas Edmonds
  6. // Andrew Lumsdaine
  7. #include <boost/random.hpp>
  8. #include <boost/test/minimal.hpp>
  9. #include <boost/graph/rmat_graph_generator.hpp>
  10. #include <boost/graph/small_world_generator.hpp>
  11. #include <boost/graph/ssca_graph_generator.hpp>
  12. #include <boost/graph/erdos_renyi_generator.hpp>
  13. #include <boost/graph/mesh_graph_generator.hpp>
  14. #include <boost/graph/adjacency_list.hpp>
  15. using namespace boost;
  16. int test_main(int argc, char** argv) {
  17. typedef rand48 RandomGenerator;
  18. typedef adjacency_list<vecS, vecS, directedS> Graph;
  19. RandomGenerator gen;
  20. size_t N = 100;
  21. size_t M = 1000;
  22. double p = 0.05;
  23. // Test Erdos-Renyi generator
  24. {
  25. erdos_renyi_iterator<RandomGenerator, Graph> start(gen, N, p);
  26. erdos_renyi_iterator<RandomGenerator, Graph> end;
  27. while (start != end) ++start;
  28. BOOST_CHECK(start == end);
  29. }
  30. {
  31. sorted_erdos_renyi_iterator<RandomGenerator, Graph> start(gen, N, p);
  32. sorted_erdos_renyi_iterator<RandomGenerator, Graph> end;
  33. while (start != end) ++start;
  34. BOOST_CHECK(start == end);
  35. }
  36. // Test Small World generator
  37. {
  38. small_world_iterator<RandomGenerator, Graph> start(gen, N, M, p);
  39. small_world_iterator<RandomGenerator, Graph> end;
  40. while (start != end) ++start;
  41. BOOST_CHECK(start == end);
  42. }
  43. // Test SSCA generator
  44. {
  45. ssca_iterator<RandomGenerator, Graph> start(gen, N, 5, 0.5, 5, p);
  46. ssca_iterator<RandomGenerator, Graph> end;
  47. while (start != end) ++start;
  48. BOOST_CHECK(start == end);
  49. }
  50. // Test Mesh generator
  51. {
  52. mesh_iterator<Graph> start(N, N);
  53. mesh_iterator<Graph> end;
  54. while (start != end) ++start;
  55. BOOST_CHECK(start == end);
  56. }
  57. // Test R-MAT generator
  58. double a = 0.57, b = 0.19, c = 0.19, d = 0.05;
  59. {
  60. rmat_iterator<RandomGenerator, Graph> start(gen, N, M, a, b, c, d);
  61. rmat_iterator<RandomGenerator, Graph> end;
  62. while (start != end) ++start;
  63. BOOST_CHECK(start == end);
  64. }
  65. {
  66. unique_rmat_iterator<RandomGenerator, Graph> start(gen, N, M, a, b, c, d);
  67. unique_rmat_iterator<RandomGenerator, Graph> end;
  68. while (start != end) ++start;
  69. BOOST_CHECK(start == end);
  70. }
  71. {
  72. sorted_unique_rmat_iterator<RandomGenerator, Graph> start(gen, N, M, a, b, c, d);
  73. sorted_unique_rmat_iterator<RandomGenerator, Graph> end;
  74. while (start != end) ++start;
  75. BOOST_CHECK(start == end);
  76. }
  77. {
  78. sorted_unique_rmat_iterator<RandomGenerator, Graph> start(gen, N, M, a, b, c, d, true);
  79. sorted_unique_rmat_iterator<RandomGenerator, Graph> end;
  80. while (start != end) ++start;
  81. BOOST_CHECK(start == end);
  82. }
  83. return 0;
  84. }