graph_partitioning.hpp 5.7 KB

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