graph_partitioning.hpp 5.5 KB

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