main.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 = "parcellaire";
  43. std::pair<bool,bool> Spectrale = {false,false};
  44. if(type_graph == "grid"){
  45. int side = floor(sqrt(100));
  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 = 70;
  58. int nbr_sources = 2;
  59. Entiers niveau = {2,2};
  60. const char *texte;
  61. //texte = "file/data_base/tree/tree_20000.txt";
  62. build_generator_graph(go, nbr_sommets, nbr_sources, 2,
  63. 3, niveau);
  64. Plot_OrientedGraph(go,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/grid_500.txt");
  65. //Text_generator_graph(texte, go);
  66. //Graph_constructor_txt(texte,go);
  67. }else if (type_graph == "linked"){
  68. int nbr_sommets = 10;
  69. int nbr_couches = 4;
  70. build_example_linked9(*go);
  71. //build_generator_graph_linked(go, nbr_sommets, nbr_couches , 2, 3);
  72. //Text_generator_graph("file/data_base/linked/linked_50.txt",go);
  73. Plot_OrientedGraph(go,"../../sortie_graphe/Tests/Graphes/Multiniveau/txt/grid_500.txt");
  74. }else if(type_graph == "parcellaire")
  75. {
  76. build_parcellaire_graph(go, 10000, "mono");
  77. }
  78. else{
  79. build_example_grid(*go);
  80. //build_graph(*go, 11);
  81. }
  82. /*** Comparaison des méthodes par étude du ratio de coupe ***/
  83. if(Spectrale.first){
  84. UnorientedGraph *g = new UnorientedGraph();
  85. make_unoriented_graph(*go, *g);
  86. EntiersEntiers Partition2;
  87. Affichage_UnorientedGraph(g);
  88. Partition2 = Spectral_Partition("../../Classif_R/Graphe/txt/Partition2.txt");
  89. Plot_OrientedGraph_All(go,Partition2,"../../Classif_R/Graphe/txt/Spectral_Partition.txt", true);
  90. Plot_OrientedGraph(go,"../../Classif_R/Graphe/txt/toto.txt");
  91. delete g;
  92. }
  93. /*** Paramétrage du Multiniveau ***/
  94. std::vector<uint> numeric_parameters = {(uint)(num_vertices(*go)/50), 4, 10};
  95. std::vector<std::string> parameters = {"HEM", "gggp", "diff", "ratio"};
  96. uint nbr_tirage = 1;
  97. for(uint i = 0 ; i < nbr_tirage ; i++){
  98. Edges edge_partie;
  99. OutputEdgeList outputedgeslist(numeric_parameters.at(1));
  100. InputEdgeList inputedgelist;
  101. Connections connections;
  102. if(!Spectrale.first){
  103. if(Spectrale.second){
  104. UnorientedGraph *g = new UnorientedGraph();
  105. make_unoriented_graph(*go, *g);
  106. Adjacent_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Madj.txt");
  107. Weight_Matrix_Txt(g,"../../Classif_R/Graphe/txt/Mwei.txt");
  108. delete g;
  109. }
  110. std::cout<<"Multiniveau"<<std::endl;
  111. OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
  112. parameters, edge_partie ,
  113. outputedgeslist, inputedgelist,
  114. connections,false, 2);
  115. std::cout<<std::endl;
  116. }else{
  117. OrientedGraphs graphs = Multiniveau(go, numeric_parameters,
  118. parameters, edge_partie ,
  119. outputedgeslist, inputedgelist,
  120. connections,true, 2);
  121. std::cout<<std::endl;
  122. }
  123. }
  124. delete go;
  125. std::cout << "Duration : " << t.elapsed()/nbr_tirage << " seconds" << std::endl;
  126. return 0;
  127. }