graph_builder.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**
  2. * @file tests/boost_graph/graph_builder.hpp
  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. #ifndef __TESTS_BOOST_GRAPH_GRAPH_BUILDER_HPP
  26. #define __TESTS_BOOST_GRAPH_GRAPH_BUILDER_HPP 1
  27. #include <tests/boost_graph/graph_defs.hpp>
  28. namespace paradevs { namespace tests { namespace boost_graph {
  29. class FlatGraphBuilder
  30. {
  31. public:
  32. FlatGraphBuilder()
  33. { }
  34. void build(OrientedGraphs& graphs, InputEdgeList& /* input_edges */,
  35. OutputEdgeList& /* output_edges */,
  36. Connections& /* parent_connections */)
  37. {
  38. OrientedGraph graph;
  39. OrientedGraph::vertex_descriptor v0 = boost::add_vertex(graph);
  40. OrientedGraph::vertex_descriptor v1 = boost::add_vertex(graph);
  41. OrientedGraph::vertex_descriptor v2 = boost::add_vertex(graph);
  42. OrientedGraph::vertex_descriptor v3 = boost::add_vertex(graph);
  43. OrientedGraph::vertex_descriptor v4 = boost::add_vertex(graph);
  44. OrientedGraph::vertex_descriptor v5 = boost::add_vertex(graph);
  45. OrientedGraph::vertex_descriptor v6 = boost::add_vertex(graph);
  46. OrientedGraph::vertex_descriptor v7 = boost::add_vertex(graph);
  47. OrientedGraph::vertex_descriptor v8 = boost::add_vertex(graph);
  48. OrientedGraph::vertex_descriptor v9 = boost::add_vertex(graph);
  49. OrientedGraph::vertex_descriptor v10 = boost::add_vertex(graph);
  50. boost::add_edge(v1, v0, 1., graph);
  51. boost::add_edge(v2, v0, 1., graph);
  52. boost::add_edge(v3, v0, 1., graph);
  53. boost::add_edge(v1, v2, 1., graph);
  54. boost::add_edge(v4, v1, 1., graph);
  55. boost::add_edge(v5, v1, 1., graph);
  56. boost::add_edge(v6, v1, 1., graph);
  57. boost::add_edge(v6, v2, 1., graph);
  58. boost::add_edge(v2, v3, 1., graph);
  59. boost::add_edge(v9, v3, 1., graph);
  60. boost::add_edge(v10, v3 , 1., graph);
  61. boost::add_edge(v4, v5, 1., graph);
  62. boost::add_edge(v5, v6, 1., graph);
  63. boost::add_edge(v7, v4, 1., graph);
  64. boost::add_edge(v8, v4, 1., graph);
  65. boost::add_edge(v7, v8, 1., graph);
  66. boost::add_edge(v9, v10 , 1., graph);
  67. graph[v6] = VertexProperties(6, 1., NORMAL_PIXEL);
  68. graph[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
  69. graph[v10] = VertexProperties(10, 1., NORMAL_PIXEL);
  70. graph[v0] = VertexProperties(0, 1., NORMAL_PIXEL);
  71. graph[v1] = VertexProperties(1, 1., NORMAL_PIXEL);
  72. graph[v2] = VertexProperties(2, 1., NORMAL_PIXEL);
  73. graph[v3] = VertexProperties(3, 1., NORMAL_PIXEL);
  74. graph[v4] = VertexProperties(4, 1., NORMAL_PIXEL);
  75. graph[v5] = VertexProperties(5, 1., NORMAL_PIXEL);
  76. graph[v7] = VertexProperties(7, 1., TOP_PIXEL);
  77. graph[v9] = VertexProperties(9, 1., TOP_PIXEL);
  78. graphs.push_back(graph);
  79. }
  80. };
  81. class HierarchicalGraphBuilder
  82. {
  83. public:
  84. HierarchicalGraphBuilder()
  85. { }
  86. void build(OrientedGraphs& graphs, InputEdgeList& input_edges,
  87. OutputEdgeList& output_edges, Connections& parent_connections)
  88. {
  89. // S1
  90. {
  91. OrientedGraph graph;
  92. OrientedGraph::vertex_descriptor v1 = boost::add_vertex(graph);
  93. OrientedGraph::vertex_descriptor v2 = boost::add_vertex(graph);
  94. OrientedGraph::vertex_descriptor v4 = boost::add_vertex(graph);
  95. OrientedGraph::vertex_descriptor v5 = boost::add_vertex(graph);
  96. OrientedGraph::vertex_descriptor v6 = boost::add_vertex(graph);
  97. OrientedGraph::vertex_descriptor v7 = boost::add_vertex(graph);
  98. OrientedGraph::vertex_descriptor v8 = boost::add_vertex(graph);
  99. boost::add_edge(v1, v2, 1., graph);
  100. boost::add_edge(v4, v1, 1., graph);
  101. boost::add_edge(v5, v1, 1., graph);
  102. boost::add_edge(v6, v1, 1., graph);
  103. boost::add_edge(v6, v2, 1., graph);
  104. boost::add_edge(v4, v5, 1., graph);
  105. boost::add_edge(v5, v6, 1., graph);
  106. boost::add_edge(v7, v4, 1., graph);
  107. boost::add_edge(v8, v4, 1., graph);
  108. boost::add_edge(v7, v8, 1., graph);
  109. graph[v6] = VertexProperties(6, 1., NORMAL_PIXEL);
  110. graph[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
  111. graph[v1] = VertexProperties(1, 1., NORMAL_PIXEL);
  112. graph[v2] = VertexProperties(2, 1., NORMAL_PIXEL);
  113. graph[v4] = VertexProperties(4, 1., NORMAL_PIXEL);
  114. graph[v5] = VertexProperties(5, 1., NORMAL_PIXEL);
  115. graph[v7] = VertexProperties(7, 1., TOP_PIXEL);
  116. graphs.push_back(graph);
  117. }
  118. // S2
  119. {
  120. OrientedGraph graph;
  121. OrientedGraph::vertex_descriptor v0 = boost::add_vertex(graph);
  122. OrientedGraph::vertex_descriptor v3 = boost::add_vertex(graph);
  123. OrientedGraph::vertex_descriptor v9 = boost::add_vertex(graph);
  124. OrientedGraph::vertex_descriptor v10 = boost::add_vertex(graph);
  125. boost::add_edge(v3, v0, 1., graph);
  126. boost::add_edge(v10, v3, 1., graph);
  127. boost::add_edge(v9, v10, 1., graph);
  128. boost::add_edge(v9, v3, 1., graph);
  129. graph[v10] = VertexProperties(10, 1., NORMAL_PIXEL);
  130. graph[v0] = VertexProperties(0, 1., NORMAL_PIXEL);
  131. graph[v3] = VertexProperties(3, 1., NORMAL_PIXEL);
  132. graph[v9] = VertexProperties(9, 1., TOP_PIXEL);
  133. graphs.push_back(graph);
  134. }
  135. {
  136. // input S1
  137. input_edges.push_back(InputEdges());
  138. // input S2
  139. input_edges.push_back(InputEdges());
  140. input_edges[1].push_back(Edge(1, 0));
  141. input_edges[1].push_back(Edge(2, 0));
  142. input_edges[1].push_back(Edge(2, 3));
  143. // output S1
  144. output_edges.push_back(OutputEdges());
  145. output_edges[0].push_back(Edge(1, 0));
  146. output_edges[0].push_back(Edge(2, 0));
  147. output_edges[0].push_back(Edge(2, 3));
  148. // output S2
  149. output_edges.push_back(OutputEdges());
  150. // parent
  151. parent_connections.push_back(Connection(Port(1,1),Port(2,0)));
  152. parent_connections.push_back(Connection(Port(1,2),Port(2,0)));
  153. parent_connections.push_back(Connection(Port(1,2),Port(2,3)));
  154. }
  155. }
  156. };
  157. } } } // namespace paradevs tests boost_graph
  158. #endif