file_generator.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 <tests/boost_graph/graph_generator.hpp>
  28. #include <tests/boost_graph/graph_partitioning.hpp>
  29. using namespace paradevs::tests::boost_graph;
  30. int main()
  31. {
  32. std::vector < int > levels = {/*5,4,2,*/ 2 };
  33. int nbr_sommets = 10;
  34. int sources = nbr_sommets/100*1;
  35. RandomGraphGenerator generator(nbr_sommets, levels, sources, 2, 3);
  36. PartitioningGraphBuilder graph_builder(2,
  37. "gggp_pond",
  38. 1,
  39. true,
  40. generator);
  41. OrientedGraphs graphs;
  42. InputEdgeList input_edges;
  43. OutputEdgeList output_edges;
  44. Connections parent_connections;
  45. graph_builder.build(graphs, input_edges, output_edges,
  46. parent_connections);
  47. for (unsigned int i = 0; i < graphs.size(); ++i) {
  48. OrientedGraph& g = graphs[i];
  49. Edges& inputs = input_edges[i];
  50. Edges& outputs = output_edges[i];
  51. std::map < int, int > indexes;
  52. std::ofstream f((boost::format("S%1%.tfg") % i).str());
  53. OrientedGraph::vertex_iterator vertexIt, vertexEnd;
  54. int k = 1;
  55. boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
  56. for (; vertexIt != vertexEnd; ++vertexIt) {
  57. indexes[g[*vertexIt]._index] = k;
  58. switch (g[*vertexIt]._type) {
  59. case TOP_PIXEL:
  60. f << "top " << std::endl;
  61. break;
  62. case NORMAL_PIXEL:
  63. f << "normal " << std::endl;
  64. break;
  65. };
  66. ++k;
  67. }
  68. f << "#" << std::endl;
  69. boost::tie(vertexIt, vertexEnd) = boost::vertices(g);
  70. for (; vertexIt != vertexEnd; ++vertexIt)
  71. {
  72. OrientedGraph::adjacency_iterator neighbourIt, neighbourEnd;
  73. boost::tie(neighbourIt, neighbourEnd) =
  74. boost::adjacent_vertices(*vertexIt, g);
  75. for (; neighbourIt != neighbourEnd; ++neighbourIt) {
  76. int a = *vertexIt + 1;
  77. int b = *neighbourIt + 1;
  78. f << a << " " << b << " 0 0" << std::endl;
  79. }
  80. }
  81. // input
  82. for (Edges::const_iterator it = inputs.begin(); it != inputs.end(); ++it) {
  83. f << "0 " << indexes[it->second] << " " << it->first << " 0" << std::endl;
  84. }
  85. // output
  86. std::vector < int > outs;
  87. for (Edges::const_iterator it = outputs.begin(); it != outputs.end(); ++it) {
  88. if (std::find(outs.begin(), outs.end(), it->first) == outs.end()) {
  89. f << indexes[it->first] << " 0 0 " << it->first << std::endl;
  90. outs.push_back(it->first);
  91. }
  92. }
  93. f.close();
  94. }
  95. std::ofstream f("ROOT.tfg");
  96. for (unsigned int i = 0; i < graphs.size(); ++i) {
  97. f << "coupled" << std::endl;
  98. }
  99. f << "#" << std::endl;
  100. std::vector < std::pair < int, int > > outs;
  101. for (Connections::const_iterator it = parent_connections.begin();
  102. it != parent_connections.end(); ++it) {
  103. const Connection& connection = *it;
  104. if (std::find(outs.begin(), outs.end(), connection.first) == outs.end()) {
  105. f << connection.first.first << " "
  106. << connection.second.first << " "
  107. << connection.first.second << " "
  108. << connection.first.second << std::endl;
  109. outs.push_back(connection.first);
  110. }
  111. }
  112. f.close();
  113. return 0;
  114. }