file_generator.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. * @file tests/boost_graph/file_generator.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 <boost/format.hpp>
  26. #include <fstream>
  27. #include <boost/timer.hpp>
  28. #include <tests/boost_graph/graph_defs.hpp>
  29. #include <tests/boost_graph/graph_generator.hpp>
  30. #include <tests/boost_graph/graph_partitioning.hpp>
  31. using namespace paradevs::tests::boost_graph;
  32. int main()
  33. {
  34. boost::timer t;
  35. srand((unsigned)time(NULL));
  36. /** Grid **/
  37. /*int side = floor(sqrt(4900));
  38. std::vector<std::pair<int,int>> vertex_selection;
  39. std::pair<int,int> tmp;
  40. tmp.first = 0;
  41. tmp.second = 3;
  42. vertex_selection.push_back(tmp);
  43. Entiers weight_vertex;
  44. weight_vertex.push_back(1);
  45. const char *texte = "../../sortie_graphe/tests_grid.txt";
  46. RandomGridGraphGenerator generator(side, vertex_selection,
  47. weight_vertex, texte, true);*/
  48. /** Tree **/
  49. /*int nbr_sommets = 20000;
  50. int sources = nbr_sommets/100*1;
  51. Entiers levels = {5,4,3,2};
  52. //Text_generator_graph("file/data_base/linked/linked_10000.txt", &gtmp);
  53. RandomGraphGenerator generator(nbr_sommets, levels, sources, 2, 3);*/
  54. /** Linked **/
  55. //OrientedGraph gtmp;
  56. //int nbr_sommets = 10000;
  57. //int nbr_couches = 60;
  58. //RandomLinkedGraphGenerator generator(nbr_sommets, nbr_couches, 2, 3);
  59. //generator.generate(gtmp);
  60. //Text_generator_graph("file/data_base/linked/linked_10000.txt", &gtmp);
  61. //ArtificialGraphGenerator generator(38);
  62. ParcelGraphGenerator generator(10000, "mono");
  63. // std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
  64. OrientedGraph::vertex_iterator vertexIt, vertexEnd;
  65. /*UnorientedGraph gi;
  66. OrientedGraph go;
  67. generator.generate(go);
  68. std::ofstream flat("file/data_base/linked/flat.tgf");
  69. std::map < int, int > indexs;
  70. int k1 = 1;
  71. boost::tie(vertexIt, vertexEnd) = boost::vertices(go);
  72. for (; vertexIt != vertexEnd; ++vertexIt) {
  73. indexs[go[*vertexIt]._index] = k1;
  74. switch (go[*vertexIt]._type) {
  75. case TOP_PIXEL:
  76. flat << "top " << std::endl;
  77. break;
  78. case NORMAL_PIXEL:
  79. flat << "normal " << std::endl;
  80. break;
  81. };
  82. ++k1;
  83. }
  84. boost::tie(vertexIt, vertexEnd) = boost::vertices(go);
  85. for (; vertexIt != vertexEnd; ++vertexIt)
  86. {
  87. OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
  88. boost::tie(neighbourIt, neighbourEnd) =
  89. boost::adjacent_vertices(*vertexIt, go);
  90. for (; neighbourIt != neighbourEnd; ++neighbourIt) {
  91. int a = *vertexIt + 1;
  92. int b = *neighbourIt + 1
  93. flat << a << " " << b << " 0 0" << std::endl;
  94. }
  95. }*/
  96. /**Liste des méthodes possible :
  97. * gggp
  98. * ggp
  99. * rand
  100. **/
  101. PartitioningGraphBuilder graph_builder(4, "gggp", 200,
  102. false, generator);
  103. OrientedGraphs graphs;
  104. InputEdgeList input_edges;
  105. OutputEdgeList output_edges;
  106. Connections parent_connections;
  107. graph_builder.build(graphs, input_edges, output_edges,
  108. parent_connections);
  109. // std::cout << "Duration : " << t.elapsed() << " seconds" << std::endl;
  110. /*std::vector<const char*> name;
  111. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_0.txt");
  112. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_1.txt");
  113. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_2.txt");
  114. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_3.txt");
  115. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_4.txt");
  116. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_5.txt");
  117. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_6.txt");
  118. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_7.txt");
  119. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_8.txt");
  120. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_9.txt");
  121. name.push_back("../../sortie_graphe/Tests/Graphes/Multiniveau/txt/partie_10.txt");*/
  122. for (unsigned int i = 0; i < graphs.size(); ++i) {
  123. OrientedGraph& g = graphs[i];
  124. Edges& inputs = input_edges[i];
  125. Edges& outputs = output_edges[i];
  126. std::map < int, int > indexes;
  127. //std::cout<<num_vertices(graphs[i])<<std::endl;
  128. //Plot_OrientedGraph(&graphs[i],name.at(i));
  129. std::ofstream f((boost::format("file/data_base/linked/rand/S%1%.tgf") % i).str());
  130. // OrientedGraph::vertex_iterator vertexIt, vertexEnd;
  131. int k = 1;
  132. boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
  133. for (; vertexIt != vertexEnd; ++vertexIt) {
  134. indexes[g[*vertexIt]._index] = k;
  135. switch (g[*vertexIt]._type) {
  136. case 0 /*TOP_PIXEL*/:
  137. f << "top " << std::endl;
  138. break;
  139. case 1 /*NORMAL_PIXEL*/:
  140. f << "normal " << std::endl;
  141. break;
  142. };
  143. ++k;
  144. }
  145. f << "#" << std::endl;
  146. boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
  147. for (; vertexIt != vertexEnd; ++vertexIt)
  148. {
  149. OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
  150. boost::tie(neighbourIt, neighbourEnd) =
  151. boost::adjacent_vertices(*vertexIt, g);
  152. for (; neighbourIt != neighbourEnd; ++neighbourIt) {
  153. int a = *vertexIt + 1;
  154. int b = *neighbourIt + 1;
  155. f << a << " " << b << " 0 0" << std::endl;
  156. }
  157. }
  158. // input
  159. for (Edges::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
  160. f << "0 " << indexes[it->second] << " " << it->first << " 0" << std::endl;
  161. }
  162. // output
  163. std::vector < int > outs;
  164. for (Edges::const_iterator it = outputs.begin(); it != outputs.end(); ++it) {
  165. if (std::find(outs.begin(), outs.end(), it->first) == outs.end()) {
  166. f << indexes[it->first] << " 0 0 " << it->first << std::endl;
  167. outs.push_back(it->first);
  168. }
  169. }
  170. f.close();
  171. }
  172. std::ofstream f("file/data_base/linked/rand/ROOT.tgf");
  173. for (unsigned int i = 0; i < graphs.size(); ++i) {
  174. f << "coupled" << std::endl;
  175. }
  176. f << "#" << std::endl;
  177. //std::vector < std::pair < int, int > > outs;
  178. std::vector<std::pair<int, int>> Outs;
  179. for (Connections::const_iterator it = parent_connections.begin();
  180. it != parent_connections.end(); ++it) {
  181. const Connection& connection = *it;
  182. std::pair<int, int> tmp_outs;
  183. tmp_outs.first = connection.first.second;
  184. tmp_outs.second = connection.second.first;
  185. //if (std::find(outs.begin(), outs.end(), connection.) == outs.end()) {
  186. if(std::find(Outs.begin(), Outs.end(), tmp_outs) == Outs.end()){
  187. //} else{
  188. f << connection.first.first << " "
  189. << connection.second.first << " "
  190. << connection.first.second << " "
  191. << connection.first.second << std::endl;
  192. //outs.push_back(connection.second.first);
  193. //outs.push_back(connection.second.first);
  194. Outs.push_back(tmp_outs);
  195. }
  196. }
  197. f.close();
  198. return 0;
  199. }