graph_builder.hpp 5.2 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 = 50;
  33. const int NLINES = 50;
  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 cluster_number = _cluster_number;
  53. OrientedGraph go;
  54. Edges edge_partie;
  55. Connections connections;
  56. generate(go);
  57. std::cout << "Nbrs models : " << num_vertices(go) << std::endl;
  58. uint contraction_coef = 200;//num_vertices(go);
  59. output_edges = OutputEdgeList(cluster_number);
  60. if (contraction_coef_flag) {
  61. uint coars = num_vertices(go) / contraction_coef;
  62. std::vector < uint > numeric_parameters = { coars,
  63. cluster_number,
  64. 10 };
  65. graphs = Multiniveau(&go, numeric_parameters,
  66. parameters, edge_partie,
  67. output_edges, input_edges,
  68. parent_connections,
  69. false, 2);
  70. } else {
  71. std::vector < uint > numeric_parameters = { contraction_coef,
  72. cluster_number,
  73. 10 };
  74. graphs = Multiniveau(&go, numeric_parameters,
  75. parameters, edge_partie ,
  76. output_edges, input_edges,
  77. parent_connections, false, 2);
  78. }
  79. }
  80. private:
  81. void generate(OrientedGraph& g)
  82. {
  83. std::vector < OrientedGraph::vertex_descriptor > vertices;
  84. for (int i = 0; i < NLINES; ++i) {
  85. for (int j = 0; j < NCOLUMNS; ++j) {
  86. vertices.push_back(boost::add_vertex(g));
  87. g[vertices.back()] = VertexProperties(i * NCOLUMNS + j, 1., 0);
  88. }
  89. }
  90. for (int i = 0; i < NLINES; ++i) {
  91. for (int j = 0; j < NCOLUMNS; ++j) {
  92. int index = i * NCOLUMNS + j;
  93. if (i > 0) {
  94. boost::add_edge(vertices[(i - 1) * NCOLUMNS + j],
  95. vertices[index], 1., g);
  96. }
  97. if (i < NLINES - 1) {
  98. boost::add_edge(vertices[(i + 1) * NCOLUMNS + j],
  99. vertices[index], 1., g);
  100. }
  101. if (j > 0) {
  102. boost::add_edge(vertices[i * NCOLUMNS + j - 1],
  103. vertices[index], 1., g);
  104. }
  105. if (j < NCOLUMNS - 1) {
  106. boost::add_edge(vertices[i * NCOLUMNS + j + 1],
  107. vertices[index], 1., g);
  108. }
  109. }
  110. }
  111. // OrientedGraph::vertex_iterator it_og, end_og;
  112. // boost::tie(it_og, end_og) = boost::vertices(g);
  113. // for (; it_og != end_og; ++it_og) {
  114. // OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  115. // std::cout << g[*it_og]._index << " -> { ";
  116. // tie(neighbour_it, neighbour_end) =
  117. // boost::adjacent_vertices(*it_og, g);
  118. // for (; neighbour_it != neighbour_end; ++neighbour_it) {
  119. // std::cout << g[*neighbour_it]._index << " ";
  120. // }
  121. // std::cout << "}" << std::endl;
  122. // }
  123. }
  124. int _cluster_number;
  125. };
  126. } } } } // namespace paradevs tests multithreading lifegame
  127. #endif