graph_partitioning.hpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/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(int cn, std::string pmn, int cc, bool ccf) :
  36. cluster_number(cn), partitioning_method_name(pmn),
  37. contraction_coef(cc), contraction_coef_flag(ccf)
  38. { }
  39. void build(OrientedGraphs& graphs,
  40. InputEdgeList& input_edges,
  41. OutputEdgeList& output_edges,
  42. Connections& parent_connections)
  43. {
  44. UnorientedGraph* g = new UnorientedGraph();
  45. OrientedGraph go;
  46. UnorientedGraph graph_origin;
  47. // internal examples
  48. // {
  49. // build_graph(*g, go);
  50. // boost::copy_graph(*g, graph_origin);
  51. // }
  52. // corsen examples
  53. {
  54. build_corsen_graph(go);
  55. make_unoriented_graph(go, *g);
  56. boost::copy_graph(*g, graph_origin);
  57. }
  58. Edges edge_partie;
  59. Connections connections;
  60. output_edges = OutputEdgeList(cluster_number);
  61. if (contraction_coef_flag) {
  62. graphs = Multiniveau(num_vertices(*g) / contraction_coef,
  63. g, &graph_origin, &go,
  64. cluster_number, "HEM",
  65. partitioning_method_name,
  66. "cut_norm", "norm", edge_partie ,
  67. output_edges, input_edges,
  68. parent_connections);
  69. } else {
  70. graphs = Multiniveau(contraction_coef, g, &graph_origin, &go,
  71. cluster_number, "HEM",
  72. partitioning_method_name,
  73. "cut_norm", "norm", edge_partie ,
  74. output_edges, input_edges,
  75. parent_connections);
  76. }
  77. // std::cout << "*********************************" << std::endl;
  78. // std::cout << "Graphs:" << std::endl;
  79. // for (unsigned int i = 0; i < graphs.size(); ++i) {
  80. // std::cout << "graph[" << i << "]:" << std::endl;
  81. // const OrientedGraph& og = graphs[i];
  82. // OrientedGraph::vertex_iterator it_og, end_og;
  83. // tie(it_og, end_og) = vertices(og);
  84. // for (; it_og != end_og; ++it_og) {
  85. // OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  86. // std::cout << og[*it_og]._index << " -> { ";
  87. // tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_og,
  88. // og);
  89. // for (; neighbour_it != neighbour_end; ++neighbour_it) {
  90. // std::cout << og[*neighbour_it]._index << " ";
  91. // }
  92. // std::cout << "}" << std::endl;
  93. // }
  94. // }
  95. // {
  96. // unsigned int i = 0;
  97. // std::cout << "Input edges:" << std::endl;
  98. // for (InputEdgeList::const_iterator it = input_edges.begin();
  99. // it != input_edges.end(); ++it, ++i) {
  100. // std::cout << "S" << i << " = {";
  101. // for (InputEdges::const_iterator it2 = it->begin();
  102. // it2 != it->end(); ++it2) {
  103. // std::cout << " ( " << it2->first << " -> " << it2->second
  104. // << " )";
  105. // }
  106. // std::cout << " }" << std::endl;;
  107. // }
  108. // }
  109. // {
  110. // unsigned int i = 0;
  111. // std::cout << "Output edges:" << std::endl;
  112. // for (OutputEdgeList::const_iterator it = output_edges.begin();
  113. // it != output_edges.end(); ++it, ++i) {
  114. // std::cout << "S" << i << " = {";
  115. // for (OutputEdges::const_iterator it2 = it->begin();
  116. // it2 != it->end(); ++it2) {
  117. // std::cout << " ( " << it2->first << " -> " << it2->second
  118. // << " )";
  119. // }
  120. // std::cout << " }" << std::endl;;
  121. // }
  122. // }
  123. // std::cout << "*********************************" << std::endl;
  124. }
  125. private:
  126. int cluster_number;
  127. std::string partitioning_method_name;
  128. int contraction_coef;
  129. bool contraction_coef_flag;
  130. };
  131. class CorsenFlatGraphBuilder
  132. {
  133. public:
  134. CorsenFlatGraphBuilder()
  135. { }
  136. void build(OrientedGraphs& graphs, InputEdgeList& /* input_edges */,
  137. OutputEdgeList& /* output_edges */,
  138. Connections& /* parent_connections */)
  139. {
  140. OrientedGraph graph;
  141. build_corsen_graph(graph);
  142. graphs.push_back(graph);
  143. }
  144. };
  145. } } } // namespace paradevs tests boost_graph
  146. #endif