graph_builder.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. * @file tests/multithreading/lifegame/graph_builder.hpp
  3. * @author The PARADEVS Development Team
  4. * See the AUTHORS or Authors.txt file
  5. */
  6. /*
  7. * PARADEVS - the multimodeling and simulation environment
  8. * This file is a part of the PARADEVS environment
  9. *
  10. * Copyright (C) 2013-2015 ULCO http://www.univ-litoral.fr
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. #ifndef TESTS_MULTITHREADING_LIFEGAME_GRAPH_BUILDER_HPP
  26. #define TESTS_MULTITHREADING_LIFEGAME_GRAPH_BUILDER_HPP 1
  27. #include <tests/boost_graph/graph_defs.hpp>
  28. #include <tests/boost_graph/partitioning/gggp.hpp>
  29. using namespace paradevs::tests::boost_graph;
  30. namespace paradevs { namespace tests {
  31. namespace multithreading { namespace lifegame {
  32. const int NCOLUMNS = 10;
  33. const int NLINES = 10;
  34. class GraphBuilder
  35. {
  36. public:
  37. GraphBuilder(int cluster_number) :
  38. _cluster_number(cluster_number)
  39. { }
  40. void build(OrientedGraphs& graphs,
  41. InputEdgeList& input_edges,
  42. OutputEdgeList& output_edges,
  43. Connections& parent_connections)
  44. {
  45. std::vector < std::string > parameters = {
  46. "HEM", "rande", "diff", "ratio"
  47. };
  48. // std::vector < std::string > parameters = {
  49. // "HEM", "gggp", "diff", "ratio"
  50. // };
  51. bool contraction_coef_flag = false;
  52. uint contraction_coef = 20;
  53. uint cluster_number = _cluster_number;
  54. OrientedGraph go;
  55. Edges edge_partie;
  56. Connections connections;
  57. generate(go);
  58. output_edges = OutputEdgeList(cluster_number);
  59. if (contraction_coef_flag) {
  60. uint coars = num_vertices(go) / contraction_coef;
  61. std::vector < uint > numeric_parameters = { coars,
  62. cluster_number,
  63. 10 };
  64. graphs = Multiniveau(&go, numeric_parameters,
  65. parameters, edge_partie,
  66. output_edges, input_edges,
  67. parent_connections,
  68. false, 2);
  69. } else {
  70. std::vector < uint > numeric_parameters = { contraction_coef,
  71. cluster_number,
  72. 10 };
  73. graphs = Multiniveau(&go, numeric_parameters,
  74. parameters, edge_partie ,
  75. output_edges, input_edges,
  76. parent_connections, false, 2);
  77. }
  78. }
  79. private:
  80. void generate(OrientedGraph& g)
  81. {
  82. std::vector < OrientedGraph::vertex_descriptor > vertices;
  83. for (int i = 0; i < NLINES; ++i) {
  84. for (int j = 0; j < NCOLUMNS; ++j) {
  85. vertices.push_back(boost::add_vertex(g));
  86. g[vertices.back()] = VertexProperties(i * NCOLUMNS + j, 1., 0);
  87. }
  88. }
  89. for (int i = 0; i < NLINES; ++i) {
  90. for (int j = 0; j < NCOLUMNS; ++j) {
  91. int index = i * NCOLUMNS + j;
  92. if (i > 0) {
  93. boost::add_edge(vertices[(i - 1) * NCOLUMNS + j],
  94. vertices[index], 1., g);
  95. }
  96. if (i < NLINES - 1) {
  97. boost::add_edge(vertices[(i + 1) * NCOLUMNS + j],
  98. vertices[index], 1., g);
  99. }
  100. if (j > 0) {
  101. boost::add_edge(vertices[i * NCOLUMNS + j - 1],
  102. vertices[index], 1., g);
  103. }
  104. if (j < NCOLUMNS - 1) {
  105. boost::add_edge(vertices[i * NCOLUMNS + j + 1],
  106. vertices[index], 1., g);
  107. }
  108. }
  109. }
  110. // OrientedGraph::vertex_iterator it_og, end_og;
  111. // boost::tie(it_og, end_og) = boost::vertices(g);
  112. // for (; it_og != end_og; ++it_og) {
  113. // OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  114. // std::cout << g[*it_og]._index << " -> { ";
  115. // tie(neighbour_it, neighbour_end) =
  116. // boost::adjacent_vertices(*it_og, g);
  117. // for (; neighbour_it != neighbour_end; ++neighbour_it) {
  118. // std::cout << g[*neighbour_it]._index << " ";
  119. // }
  120. // std::cout << "}" << std::endl;
  121. // }
  122. }
  123. int _cluster_number;
  124. };
  125. } } } } // namespace paradevs tests multithreading lifegame
  126. #endif