graph_partitioning.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @file tests/boost_graph/graph_partitioning.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_BOOST_GRAPH_GRAPH_PARTITIONING_HPP
  26. #define __TESTS_BOOST_GRAPH_GRAPH_PARTITIONING_HPP 1
  27. #include <tests/boost_graph/graph_generator.hpp>
  28. #include <tests/boost_graph/partitioning/graph_build.hpp>
  29. #include <tests/boost_graph/partitioning/gggp.hpp>
  30. #include <boost/graph/copy.hpp>
  31. namespace paradevs { namespace tests { namespace boost_graph {
  32. class PartitioningGraphBuilder
  33. {
  34. public:
  35. PartitioningGraphBuilder(uint cn, std::string pmn, uint cc, bool ccf,
  36. GraphGenerator& g) :
  37. cluster_number(cn),/*ajout d'un paramètre nbr_tirage,*/ partitioning_method_name(pmn),
  38. contraction_coef(cc), contraction_coef_flag(ccf), generator(g)
  39. { }
  40. void build(OrientedGraphs& graphs,
  41. InputEdgeList& input_edges,
  42. OutputEdgeList& output_edges,
  43. Connections& parent_connections)
  44. {
  45. // std::cout<<"**"<<cluster_number<<"**"<<std::endl;
  46. OrientedGraph go;
  47. /** Méthode de contraction possible :
  48. * HEM : hem standars amélioré en temps
  49. * HEM_degree : hem aves suppression de l'aléatoire
  50. * autre : random_matching
  51. * **/
  52. std::vector<std::string> parameters = {"HEM",
  53. partitioning_method_name,
  54. "diff", "ratio"};
  55. generator.generate(go);
  56. Edges edge_partie;
  57. Connections connections;
  58. output_edges = OutputEdgeList(cluster_number);
  59. if (contraction_coef_flag) {
  60. uint coars = num_vertices(go) / contraction_coef;
  61. uint nbr_tirage = 10;
  62. std::vector<uint> numeric_parameters = {coars,
  63. cluster_number,
  64. nbr_tirage};
  65. graphs = Multiniveau(&go, numeric_parameters,
  66. parameters, edge_partie ,
  67. output_edges, input_edges,
  68. parent_connections, false, 2);
  69. } else {
  70. uint nbr_tirage = 10;
  71. std::vector<uint> numeric_parameters = {contraction_coef ,
  72. cluster_number,
  73. nbr_tirage};
  74. graphs = Multiniveau(&go, numeric_parameters,
  75. parameters, edge_partie ,
  76. output_edges, input_edges,
  77. parent_connections, false, 2);
  78. }
  79. // std::cout << "*********************************" << std::endl;
  80. // std::cout << "Graphs:" << std::endl;
  81. // for (unsigned int i = 0; i < graphs.size(); ++i) {
  82. // std::cout << "graph[" << i << "]:" << std::endl;
  83. // const OrientedGraph& og = graphs[i];
  84. // OrientedGraph::vertex_iterator it_og, end_og;
  85. // tie(it_og, end_og) = vertices(og);
  86. // for (; it_og != end_og; ++it_og) {
  87. // OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  88. // std::cout << og[*it_og]._index << " -> { ";
  89. // tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_og,
  90. // og);
  91. // for (; neighbour_it != neighbour_end; ++neighbour_it) {
  92. // std::cout << og[*neighbour_it]._index << " ";
  93. // }
  94. // std::cout << "}" << std::endl;
  95. // }
  96. // }
  97. // {
  98. // unsigned int i = 0;
  99. // std::cout << "Input edges:" << std::endl;
  100. // for (InputEdgeList::const_iterator it = input_edges.begin();
  101. // it != input_edges.end(); ++it, ++i) {
  102. // std::cout << "S" << i << " = {";
  103. // for (InputEdges::const_iterator it2 = it->begin();
  104. // it2 != it->end(); ++it2) {
  105. // std::cout << " ( " << it2->first << " -> " << it2->second
  106. // << " )";
  107. // }
  108. // std::cout << " }" << std::endl;;
  109. // }
  110. // }
  111. // {
  112. // unsigned int i = 0;
  113. // std::cout << "Output edges:" << std::endl;
  114. // for (OutputEdgeList::const_iterator it = output_edges.begin();
  115. // it != output_edges.end(); ++it, ++i) {
  116. // std::cout << "S" << i << " = {";
  117. // for (OutputEdges::const_iterator it2 = it->begin();
  118. // it2 != it->end(); ++it2) {
  119. // std::cout << " ( " << it2->first << " -> " << it2->second
  120. // << " )";
  121. // }
  122. // std::cout << " }" << std::endl;;
  123. // }
  124. // }
  125. // std::cout << "*********************************" << std::endl;
  126. }
  127. private:
  128. uint cluster_number;
  129. std::string partitioning_method_name;
  130. uint contraction_coef;
  131. bool contraction_coef_flag;
  132. GraphGenerator& generator;
  133. };
  134. } } } // namespace paradevs tests boost_graph
  135. #endif