main.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. build_graph(*g, *go);
  41. int nbr_parties = 3;
  42. Edges edge_partie;
  43. OutputEdgeList outputedgeslist(nbr_parties);
  44. InputEdgeList inputedgelist;
  45. Connections connections;
  46. /*EntiersEntiers Partition;
  47. Entiers *part = new Entiers();
  48. Base_Graph baseg;
  49. baseg.push_back(g);
  50. ListEntiersEntiers liste_corr;
  51. uint cpt=0;
  52. while(num_vertices(*baseg.at(cpt))>4)
  53. {
  54. contraction_HEM(baseg.at(cpt),baseg,liste_corr);
  55. cpt++;
  56. }
  57. edge_t e1;
  58. bool found;
  59. for(uint i=0;i<baseg.size();i++){
  60. tie(vertexIt, vertexEnd) = vertices((*baseg.at(i)));
  61. for (; vertexIt != vertexEnd; ++vertexIt)
  62. {
  63. std::cout << *vertexIt << " est connecté avec ";
  64. tie(neighbourIt, neighbourEnd) = adjacent_vertices(*vertexIt, (*baseg.at(i)));
  65. for (; neighbourIt != neighbourEnd; ++neighbourIt){
  66. std::cout << *neighbourIt << " ";
  67. tie(e1,found)=edge(vertex(*vertexIt,*baseg.at(i)),vertex(*neighbourIt,*baseg.at(i)),*baseg.at(i));
  68. std::cout << "poids arc : "<<(*baseg.at(i))[e1]._weight<<"\n";
  69. }
  70. std::cout<<" et son poids est de "<< (*baseg.at(i))[*vertexIt]._weight<<std::endl;
  71. }
  72. std::cout<<"\n"<<std::endl;
  73. }
  74. for(int i =0;i<num_vertices(*baseg.at(baseg.size()-1));i++)
  75. {
  76. part->push_back(i);
  77. }
  78. Partition.push_back(part);
  79. bissectionRec(baseg.at(baseg.size()-1),Partition,3,"gggp_pond");
  80. //Pseudo_random_partitioning(g,Partition,3);
  81. std::cout<<"Nombre de parties : "<<Partition.size()<<std::endl;
  82. std::clog<<"Resultat de la partition : "<<std::endl;
  83. std::cout<<"****"<<std::endl;
  84. for(uint i = 0; i< Partition.size() ; i++)
  85. {
  86. for(uint j = 0 ; j<Partition.at(i)->size() ; j++)
  87. {
  88. std::cout<<(*baseg.at(baseg.size()-1))[Partition.at(i)->at(j)]._index<<std::endl;
  89. }
  90. std::cout<<"\n"<<std::endl;
  91. }
  92. std::cout<<"****"<<std::endl;
  93. ListEntiersEntiers::iterator lit(liste_corr.end());
  94. lit--;
  95. for(uint y =0; y<liste_corr.size();y++){
  96. projection(Partition,lit);
  97. std::clog<<"liste de correspondance : "<<std::endl;
  98. for(uint i = 0; i < (*lit)->size(); i++)
  99. {
  100. for(uint j = 0; j < (*lit)->at(i)->size();j++){
  101. std::cout<<(*lit)->at(i)->at(j)<<std::endl;;
  102. }
  103. std::cout<<"\n"<<std::endl;
  104. }
  105. std::clog<<"Resultat projection : "<<std::endl;
  106. for(uint i = 0; i< Partition.size() ; i++)
  107. {
  108. for(uint j = 0 ; j<Partition.at(i)->size() ; j++)
  109. {
  110. std::cout<<Partition.at(i)->at(j)<<std::endl;
  111. }
  112. std::cout<<"\n"<<std::endl;
  113. }
  114. double cut = Cut_cluster(Partition,*baseg.at(baseg.size()-2-y),"norm");
  115. std::cout<<"Cout de coupe avant affinage : "<<cut<<std::endl;
  116. Affinage_recherche_locale(baseg.at(baseg.size()-2-y),Partition,cut,"norm");
  117. //Affinage_equilibrage_charge(baseg.at(baseg.size()-2-y),Partition);
  118. std::cout<<"Cout de coupe après affinage : "<<cut<<std::endl;
  119. std::cout<<"\n"<<std::endl;
  120. double tmp = Cut_cluster(Partition,*baseg.at(baseg.size()-2-y),"norm");
  121. std::cout<<"verification cout de coupe après affinage : "<<tmp<<std::endl;
  122. std::cout<<"\n"<<std::endl;
  123. std::clog<<"Partition après affinage : "<<std::endl;
  124. for(uint i = 0; i< Partition.size() ; i++)
  125. {
  126. for(uint j = 0 ; j<Partition.at(i)->size() ; j++)
  127. {
  128. std::cout<<Partition.at(i)->at(j)<<std::endl;
  129. }
  130. std::cout<<"\n"<<std::endl;
  131. }
  132. lit--;
  133. }
  134. std::cout<<"mathieu va me buter ! et en plus c'est walker !!!"<<std::endl;
  135. std::cout<<"\n"<<std::endl;
  136. OrientedGraphs Graphes = Graph_Partition(Partition,go,g,outputedgeslist,inputedgelist,connections);*/
  137. OrientedGraphs graphs = Multiniveau(4, g, go, nbr_parties, "gggp_pond",
  138. "cut_norm", "norm", edge_partie ,
  139. outputedgeslist, inputedgelist,
  140. connections);
  141. std::cout << std::endl;
  142. std::cout << "Sous Graphes :" << std::endl;
  143. for (uint i = 0; i< graphs.size(); i++) {
  144. tie(vertexIto, vertexEndo) = vertices(graphs[i]);
  145. for (; vertexIto != vertexEndo; ++vertexIto) {
  146. std::cout << graphs[i][*vertexIto]._index
  147. << " est connecté avec ";
  148. tie(neighbourIto, neighbourEndo) = adjacent_vertices(*vertexIto,
  149. graphs[i]);
  150. for (; neighbourIto != neighbourEndo; ++neighbourIto)
  151. std::cout << graphs[i][*neighbourIto]._index << " ";
  152. std::cout << " et son poids est de "
  153. << graphs[i][*vertexIto]._weight<<std::endl;
  154. }
  155. std::cout << std::endl;
  156. }
  157. std::clog << "OutputEdgeList :" << std::endl;
  158. for (uint i = 0; i < outputedgeslist.size(); i++) {
  159. for (uint j = 0; j < outputedgeslist.at(i).size(); j++){
  160. std::cout << outputedgeslist.at(i).at(j).first << " "
  161. << outputedgeslist.at(i).at(j).second << std::endl;
  162. }
  163. }
  164. std::cout << std::endl;
  165. std::clog << "InputEdgeList :" << std::endl;
  166. for (uint i = 0; i < inputedgelist.size(); i++) {
  167. for (uint j = 0; j < inputedgelist.at(i).size(); j++){
  168. std::cout << inputedgelist.at(i).at(j).first << " "
  169. << inputedgelist.at(i).at(j).second << std::endl;
  170. }
  171. }
  172. std::cout << std::endl;
  173. std::clog << "Connections :" << std::endl;
  174. for (uint i = 0; i < connections.size(); i++) {
  175. std::cout << "(" << connections.at(i).first.first << ","
  176. << connections.at(i).first.second << ") -> ("
  177. << connections.at(i).second.first << ","
  178. << connections.at(i).second.second << ")"
  179. << std::endl;
  180. }
  181. /*for(EntiersEntiers::iterator it = Partition.begin(); it != Partition.end(); it++)
  182. {
  183. delete *it;
  184. *it = NULL;
  185. }
  186. for(ListEntiersEntiers::iterator it = liste_corr.begin(); it != liste_corr.end(); it++)
  187. {
  188. for(EntiersEntiers::iterator it1 = (*it)->begin(); it1 != (*it)->end(); it1++)
  189. {
  190. delete *it1;
  191. *it1 = NULL;
  192. }
  193. delete *it;
  194. *it = NULL;
  195. }
  196. for(Base_Graph::iterator it = baseg.begin(); it != baseg.end(); it++)
  197. {
  198. delete *it;
  199. *it = NULL;
  200. }*/
  201. // for(OrientedGraphs::iterator it = Graphes.begin(); it != Graphes.end();
  202. // it++) {
  203. // delete *it;
  204. // *it = NULL;
  205. // }
  206. std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
  207. //EntiersEntiersEntiers Stock_Partition;
  208. /*for(int i=0;i<11;i++){
  209. g1=g;
  210. Partition1=Partition;
  211. bissectionRec(g1,Partition1,4,"gggp");
  212. Stock_Partition.push_back(Partition1);
  213. Cut.push_back(Cut_cluster(Partition1,g));
  214. Partition1.clear();
  215. g1.clear();
  216. }
  217. for(int i =0;i<Cut.size();i++){
  218. std::cout<<Cut[i]<<std::endl;
  219. }
  220. std::cout<<"\n"<<std::endl;
  221. std::cout<<recherche_val_double(Cut,*min_element(Cut.begin(),Cut.end()))<<std::endl;
  222. std::cout<<"\n"<<std::endl;
  223. EntiersEntiers tmp = Stock_Partition[recherche_val_double(Cut,*min_element(Cut.begin(),Cut.end()))];
  224. for(int i =0; i<tmp.size();i++){
  225. for(int j=0; j<tmp[i].size();j++){
  226. std::cout<<tmp[i][j]<<std::endl;
  227. }
  228. std::cout<<"\n"<<std::endl;
  229. }*/
  230. /*EntiersEntiers liste_corr;
  231. //double cut = Cut_cluster(Partition,g);
  232. Base_Graph baseg;
  233. baseg.push_back(g);
  234. std::cout<<"LIste des noeuds fusionés : "<<std::endl;
  235. for(uint i = 0; i< liste_corr.size() ; i++)
  236. {
  237. for(uint j = 0 ; j<liste_corr.at(i).size() ; j++)
  238. {
  239. std::cout<<liste_corr[i][j]<<std::endl;
  240. }
  241. std::cout<<"\n"<<std::endl;
  242. }*/
  243. }