main.cpp 4.2 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-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. #include <tests/boost_graph/partitioning/gggp.hpp>
  26. #include <tests/boost_graph/partitioning/graph_build.hpp>
  27. #include <boost/graph/copy.hpp>
  28. #include <boost/timer.hpp>
  29. #include <fstream>
  30. #include <iostream>
  31. using namespace paradevs::tests::boost_graph;
  32. UnorientedGraph::vertex_iterator vertexIt, vertexEnd;
  33. UnorientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
  34. OrientedGraph::vertex_iterator vertexIto, vertexEndo;
  35. OrientedGraph::adjacency_iterator neighbourIto, neighbourEndo;
  36. int main()
  37. {
  38. boost::timer t;
  39. srand((unsigned)time(NULL));
  40. /*** Génération du graphe ***/
  41. OrientedGraph *go = new OrientedGraph();
  42. std::string type_graph = "tree";
  43. std::pair<bool,bool> Spectrale = {false,false};
  44. if(type_graph == "grid"){
  45. int side = floor(sqrt(5000));
  46. std::vector<std::pair<int,int>> vertex_selection;
  47. std::pair<int,int> tmp;
  48. tmp.first = 0;
  49. tmp.second = 3;
  50. vertex_selection.push_back(tmp);
  51. Entiers weight_vertex;
  52. weight_vertex.push_back(1);
  53. const char *texte = "../../sortie_graphe/tests_grid.txt";
  54. build_graph_grid(go, side, vertex_selection, weight_vertex,texte,true);
  55. Plot_OrientedGraph(go,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/grid_500.txt");
  56. }else if (type_graph == "tree"){
  57. int nbr_sommets = 5000;
  58. int nbr_sources = nbr_sommets/100*1;
  59. Entiers niveau = {5,4,3,2};
  60. build_generator_graph(go, nbr_sommets, nbr_sources , 2 , 4 ,niveau);
  61. }else if (type_graph == "linked"){
  62. int nbr_sommets = 1000;
  63. int nbr_couches = 150;
  64. build_generator_graph_linked(go, nbr_sommets, nbr_couches , 2, 3);
  65. }else{
  66. build_graph(*go, 38);
  67. }
  68. /*** Comparaison des méthodes par étude du ratio de coupe ***/
  69. if(Spectrale.first){
  70. UnorientedGraph *g = new UnorientedGraph();
  71. make_unoriented_graph(*go, *g);
  72. EntiersEntiers Partition2;
  73. Affichage_UnorientedGraph(g);
  74. Partition2 = Spectral_Partition("../../Classif_R/Graphe/txt/Partition2.txt");
  75. Plot_OrientedGraph_All(go,Partition2,"../../Classif_R/Graphe/txt/Spectral_Partition.txt", true);
  76. Plot_OrientedGraph(go,"../../Classif_R/Graphe/txt/toto.txt");
  77. delete g;
  78. }
  79. /*** Paramétrage du Multiniveau ***/
  80. std::vector<uint> numeric_parameters = {num_vertices(*go)/20, 8, 10};
  81. std::vector<std::string> parameters = {"HEM", "rand", "diff", "cut"};
  82. uint nbr_tirage = 1;
  83. for(uint i = 0 ; i < nbr_tirage ; i++){
  84. Edges edge_partie;
  85. OutputEdgeList outputedgeslist(numeric_parameters.at(1));
  86. InputEdgeList inputedgelist;
  87. Connections connections;
  88. if(!Spectrale.first){
  89. if(Spectrale.second){
  90. UnorientedGraph *g = new UnorientedGraph();
  91. make_unoriented_graph(*go, *g);
  92. Adjacent_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Madj.txt");
  93. Weight_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Mwei.txt");
  94. delete g;
  95. }
  96. OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
  97. parameters, edge_partie ,
  98. outputedgeslist, inputedgelist,
  99. connections,true, i);
  100. std::cout<<std::endl;
  101. }else{
  102. OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
  103. parameters, edge_partie ,
  104. outputedgeslist, inputedgelist,
  105. connections,true, i);
  106. std::cout<<std::endl;
  107. }
  108. }
  109. delete go;
  110. std::cout << "Duration : " << t.elapsed()/nbr_tirage << " seconds" << std::endl;
  111. return 0;
  112. }