main.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /**
  2. * @file tests/boost_graph/partitioning/main.cpp
  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. #include <tests/boost_graph/partitioning/gggp.hpp>
  26. #include <tests/boost_graph/partitioning/graph_build.hpp>
  27. #include <boost/timer.hpp>
  28. #include <iostream>
  29. using namespace paradevs::tests::boost_graph;
  30. UnorientedGraph::vertex_iterator vertexIt, vertexEnd;
  31. UnorientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
  32. OrientedGraph::vertex_iterator vertexIto, vertexEndo;
  33. OrientedGraph::adjacency_iterator neighbourIto, neighbourEndo;
  34. int main()
  35. {
  36. boost::timer t;
  37. srand((unsigned)time(NULL));
  38. UnorientedGraph* g = new UnorientedGraph();
  39. OrientedGraph* go = new OrientedGraph();
  40. UnorientedGraph* graph_origin = new UnorientedGraph();
  41. OrientedGraph* gop = new OrientedGraph();
  42. build_graph(*g, *go);
  43. build_graph(*graph_origin, *gop);
  44. delete gop;
  45. int nbr_parties = 4;
  46. /*EntiersEntiers Partition = Random_partitioning(g,nbr_parties);
  47. for(uint i = 0; i < Partition.size(); i++){
  48. for(uint j = 0; j < Partition.at(i)->size(); j++){
  49. std::cout<<Partition.at(i)->at(j)<<std::endl;
  50. }
  51. std::cout<<std::endl;
  52. }
  53. std::cout<<Partition.size()<<std::endl;*/
  54. Edges edge_partie;
  55. OutputEdgeList outputedgeslist(nbr_parties);
  56. InputEdgeList inputedgelist;
  57. Connections connections;
  58. std::cout<<num_vertices(*g)/4<<std::endl;
  59. OrientedGraphs graphs = Multiniveau(num_vertices(*g)/2, g, graph_origin, go, nbr_parties,"rand", "gggp_pond",
  60. "cut_norm", "norm", edge_partie ,
  61. outputedgeslist, inputedgelist,
  62. connections);
  63. std::cout << std::endl;
  64. std::cout << "Sous Graphes :" << std::endl;
  65. for (uint i = 0; i< graphs.size(); i++) {
  66. tie(vertexIto, vertexEndo) = vertices(graphs[i]);
  67. for (; vertexIto != vertexEndo; ++vertexIto) {
  68. std::cout << graphs[i][*vertexIto]._index
  69. << " est connecté avec ";
  70. tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
  71. graphs[i]);
  72. for (; neighbourIto != neighbourEndo; ++neighbourIto)
  73. std::cout << graphs[i][*neighbourIto]._index << " ";
  74. std::cout << " et son poids est de "
  75. << graphs[i][*vertexIto]._weight<<std::endl;
  76. }
  77. std::cout << std::endl;
  78. }
  79. std::clog << "OutputEdgeList :" << std::endl;
  80. for (uint i = 0; i < outputedgeslist.size(); i++) {
  81. for (uint j = 0; j < outputedgeslist.at(i).size(); j++){
  82. std::cout << outputedgeslist.at(i).at(j).first << " "
  83. << outputedgeslist.at(i).at(j).second << std::endl;
  84. }
  85. }
  86. std::cout << std::endl;
  87. std::clog << "InputEdgeList :" << std::endl;
  88. for (uint i = 0; i < inputedgelist.size(); i++) {
  89. for (uint j = 0; j < inputedgelist.at(i).size(); j++){
  90. std::cout << inputedgelist.at(i).at(j).first << " "
  91. << inputedgelist.at(i).at(j).second << std::endl;
  92. }
  93. }
  94. std::cout << std::endl;
  95. std::clog << "Connections :" << std::endl;
  96. for (uint i = 0; i < connections.size(); i++) {
  97. std::cout << "(" << connections.at(i).first.first << ","
  98. << connections.at(i).first.second << ") -> ("
  99. << connections.at(i).second.first << ","
  100. << connections.at(i).second.second << ")"
  101. << std::endl;
  102. }
  103. delete graph_origin;
  104. delete go;
  105. std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
  106. }