graph_builder.hpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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-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. #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. #include <tests/boost_graph/partitioning/graph_build.hpp>
  29. namespace paradevs { namespace tests { namespace boost_graph {
  30. class FlatGraphBuilder
  31. {
  32. public:
  33. FlatGraphBuilder()
  34. { }
  35. void build(OrientedGraphs& graphs, InputEdgeList& /* input_edges */,
  36. OutputEdgeList& /* output_edges */,
  37. Connections& /* parent_connections */)
  38. {
  39. OrientedGraph graph;
  40. build_graph(graph, 38);
  41. graphs.push_back(graph);
  42. }
  43. };
  44. class HierarchicalGraphBuilder
  45. {
  46. public:
  47. HierarchicalGraphBuilder()
  48. { }
  49. void build(OrientedGraphs& graphs, InputEdgeList& input_edges,
  50. OutputEdgeList& output_edges, Connections& parent_connections)
  51. {
  52. // S1
  53. {
  54. OrientedGraph graph;
  55. OrientedGraph::vertex_descriptor v1 = boost::add_vertex(graph);
  56. OrientedGraph::vertex_descriptor v4 = boost::add_vertex(graph);
  57. OrientedGraph::vertex_descriptor v5 = boost::add_vertex(graph);
  58. OrientedGraph::vertex_descriptor v7 = boost::add_vertex(graph);
  59. OrientedGraph::vertex_descriptor v8 = boost::add_vertex(graph);
  60. OrientedGraph::vertex_descriptor v11 = boost::add_vertex(graph);
  61. OrientedGraph::vertex_descriptor v12 = boost::add_vertex(graph);
  62. OrientedGraph::vertex_descriptor v13 = boost::add_vertex(graph);
  63. OrientedGraph::vertex_descriptor v14 = boost::add_vertex(graph);
  64. OrientedGraph::vertex_descriptor v15 = boost::add_vertex(graph);
  65. OrientedGraph::vertex_descriptor v16 = boost::add_vertex(graph);
  66. OrientedGraph::vertex_descriptor v17 = boost::add_vertex(graph);
  67. OrientedGraph::vertex_descriptor v18 = boost::add_vertex(graph);
  68. OrientedGraph::vertex_descriptor v19 = boost::add_vertex(graph);
  69. OrientedGraph::vertex_descriptor v20 = boost::add_vertex(graph);
  70. OrientedGraph::vertex_descriptor v21 = boost::add_vertex(graph);
  71. OrientedGraph::vertex_descriptor v22 = boost::add_vertex(graph);
  72. OrientedGraph::vertex_descriptor v23 = boost::add_vertex(graph);
  73. boost::add_edge(v4, v1, 1., graph);
  74. boost::add_edge(v5, v1, 1., graph);
  75. boost::add_edge(v4, v5, 1., graph);
  76. boost::add_edge(v7, v4, 1., graph);
  77. boost::add_edge(v8, v4, 1., graph);
  78. boost::add_edge(v7, v8, 1., graph);
  79. boost::add_edge(v8, v11, 1., graph);
  80. boost::add_edge(v11, v4, 1., graph);
  81. boost::add_edge(v12, v13, 1., graph);
  82. boost::add_edge(v12, v7, 1., graph);
  83. boost::add_edge(v13, v7, 1., graph);
  84. boost::add_edge(v14, v15, 1., graph);
  85. boost::add_edge(v14, v12, 1., graph);
  86. boost::add_edge(v15, v16, 1., graph);
  87. boost::add_edge(v15, v12, 1., graph);
  88. boost::add_edge(v16, v17, 1., graph);
  89. boost::add_edge(v16, v12, 1., graph);
  90. boost::add_edge(v17, v12, 1., graph);
  91. boost::add_edge(v18, v19, 1., graph);
  92. boost::add_edge(v18, v8, 1., graph);
  93. boost::add_edge(v19, v20, 1., graph);
  94. boost::add_edge(v19, v8, 1., graph);
  95. boost::add_edge(v20, v8, 1., graph);
  96. boost::add_edge(v21, v22, 1., graph);
  97. boost::add_edge(v21, v19, 1., graph);
  98. boost::add_edge(v22, v23, 1., graph);
  99. boost::add_edge(v22, v19, 1., graph);
  100. boost::add_edge(v23, v19, 1., graph);
  101. graph[v8] = VertexProperties(8, 2., NORMAL_PIXEL);
  102. graph[v1] = VertexProperties(1, 3, NORMAL_PIXEL);
  103. graph[v4] = VertexProperties(4, 2.5, NORMAL_PIXEL);
  104. graph[v5] = VertexProperties(5, 2.5, NORMAL_PIXEL);
  105. graph[v7] = VertexProperties(7, 2., NORMAL_PIXEL);
  106. graph[v11] = VertexProperties(11, 2, NORMAL_PIXEL);
  107. graph[v12] = VertexProperties(12, 1.5, NORMAL_PIXEL);
  108. graph[v13] = VertexProperties(13, 1.5, NORMAL_PIXEL);
  109. graph[v14] = VertexProperties(14, 1, TOP_PIXEL);
  110. graph[v15] = VertexProperties(15, 1, NORMAL_PIXEL);
  111. graph[v16] = VertexProperties(16, 1, NORMAL_PIXEL);
  112. graph[v17] = VertexProperties(17, 1, NORMAL_PIXEL);
  113. graph[v18] = VertexProperties(18, 1.5, TOP_PIXEL);
  114. graph[v19] = VertexProperties(19, 1.5, NORMAL_PIXEL);
  115. graph[v20] = VertexProperties(20, 1.5, NORMAL_PIXEL);
  116. graph[v21] = VertexProperties(21, 1, TOP_PIXEL);
  117. graph[v22] = VertexProperties(22, 1, NORMAL_PIXEL);
  118. graph[v23] = VertexProperties(23, 1, NORMAL_PIXEL);
  119. /*OrientedGraph::vertex_descriptor v1 = boost::add_vertex(graph);
  120. OrientedGraph::vertex_descriptor v2 = boost::add_vertex(graph);
  121. OrientedGraph::vertex_descriptor v4 = boost::add_vertex(graph);
  122. OrientedGraph::vertex_descriptor v5 = boost::add_vertex(graph);
  123. OrientedGraph::vertex_descriptor v6 = boost::add_vertex(graph);
  124. OrientedGraph::vertex_descriptor v7 = boost::add_vertex(graph);
  125. OrientedGraph::vertex_descriptor v8 = boost::add_vertex(graph);
  126. boost::add_edge(v1, v2, 1., graph);
  127. boost::add_edge(v4, v1, 1., graph);
  128. boost::add_edge(v5, v1, 1., graph);
  129. boost::add_edge(v6, v1, 1., graph);
  130. boost::add_edge(v6, v2, 1., graph);
  131. boost::add_edge(v4, v5, 1., graph);
  132. boost::add_edge(v5, v6, 1., graph);
  133. boost::add_edge(v7, v4, 1., graph);
  134. boost::add_edge(v8, v4, 1., graph);
  135. boost::add_edge(v7, v8, 1., graph);
  136. graph[v6] = VertexProperties(6, 1., NORMAL_PIXEL);
  137. graph[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
  138. graph[v1] = VertexProperties(1, 1., NORMAL_PIXEL);
  139. graph[v2] = VertexProperties(2, 1., NORMAL_PIXEL);
  140. graph[v4] = VertexProperties(4, 1., NORMAL_PIXEL);
  141. graph[v5] = VertexProperties(5, 1., NORMAL_PIXEL);
  142. graph[v7] = VertexProperties(7, 1., TOP_PIXEL);*/
  143. graphs.push_back(graph);
  144. }
  145. // S2
  146. {
  147. OrientedGraph graph;
  148. OrientedGraph::vertex_descriptor v0 = boost::add_vertex(graph);
  149. OrientedGraph::vertex_descriptor v2 = boost::add_vertex(graph);
  150. OrientedGraph::vertex_descriptor v3 = boost::add_vertex(graph);
  151. OrientedGraph::vertex_descriptor v6 = boost::add_vertex(graph);
  152. OrientedGraph::vertex_descriptor v9 = boost::add_vertex(graph);
  153. OrientedGraph::vertex_descriptor v10 = boost::add_vertex(graph);
  154. OrientedGraph::vertex_descriptor v24 = boost::add_vertex(graph);
  155. OrientedGraph::vertex_descriptor v25 = boost::add_vertex(graph);
  156. OrientedGraph::vertex_descriptor v26 = boost::add_vertex(graph);
  157. OrientedGraph::vertex_descriptor v27 = boost::add_vertex(graph);
  158. OrientedGraph::vertex_descriptor v28 = boost::add_vertex(graph);
  159. OrientedGraph::vertex_descriptor v29 = boost::add_vertex(graph);
  160. OrientedGraph::vertex_descriptor v30 = boost::add_vertex(graph);
  161. OrientedGraph::vertex_descriptor v31 = boost::add_vertex(graph);
  162. OrientedGraph::vertex_descriptor v32 = boost::add_vertex(graph);
  163. OrientedGraph::vertex_descriptor v33 = boost::add_vertex(graph);
  164. OrientedGraph::vertex_descriptor v34 = boost::add_vertex(graph);
  165. OrientedGraph::vertex_descriptor v35 = boost::add_vertex(graph);
  166. OrientedGraph::vertex_descriptor v36 = boost::add_vertex(graph);
  167. OrientedGraph::vertex_descriptor v37 = boost::add_vertex(graph);
  168. boost::add_edge(v2, v0, 1., graph);
  169. boost::add_edge(v3, v0, 1., graph);
  170. boost::add_edge(v6, v2, 1., graph);
  171. boost::add_edge(v2, v3, 1., graph);
  172. boost::add_edge(v9, v3, 1., graph);
  173. boost::add_edge(v10, v3 , 1., graph);
  174. boost::add_edge(v9, v10 , 1., graph);
  175. boost::add_edge(v24, v25, 1., graph);
  176. boost::add_edge(v24, v6, 1., graph);
  177. boost::add_edge(v25, v6, 1., graph);
  178. boost::add_edge(v26, v27, 1., graph);
  179. boost::add_edge(v26, v24, 1., graph);
  180. boost::add_edge(v27, v24, 1., graph);
  181. boost::add_edge(v28, v25, 1., graph);
  182. boost::add_edge(v29, v27, 1., graph);
  183. boost::add_edge(v29, v28, 1., graph);
  184. boost::add_edge(v30, v27, 1., graph);
  185. boost::add_edge(v31, v32, 1., graph);
  186. boost::add_edge(v31, v10, 1., graph);
  187. boost::add_edge(v32, v33, 1., graph);
  188. boost::add_edge(v32, v10, 1., graph);
  189. boost::add_edge(v33, v10, 1., graph);
  190. boost::add_edge(v34, v31, 1., graph);
  191. boost::add_edge(v34, v35, 1., graph);
  192. boost::add_edge(v35, v31, 1., graph);
  193. boost::add_edge(v35, v32, 1., graph);
  194. boost::add_edge(v36, v32, 1., graph);
  195. boost::add_edge(v36, v37, 1., graph);
  196. boost::add_edge(v36, v33, 1., graph);
  197. boost::add_edge(v37, v33, 1., graph);
  198. graph[v6] = VertexProperties(6, 2.5, NORMAL_PIXEL);
  199. graph[v10] = VertexProperties(10, 2.5, NORMAL_PIXEL);
  200. graph[v0] = VertexProperties(0, 4, NORMAL_PIXEL);
  201. graph[v2] = VertexProperties(2, 3, NORMAL_PIXEL);
  202. graph[v3] = VertexProperties(3, 3, NORMAL_PIXEL);
  203. graph[v9] = VertexProperties(9, 2.5, TOP_PIXEL);
  204. graph[v24] = VertexProperties(24, 2, NORMAL_PIXEL);
  205. graph[v25] = VertexProperties(25, 2, NORMAL_PIXEL);
  206. graph[v26] = VertexProperties(26, 1.5, TOP_PIXEL);
  207. graph[v27] = VertexProperties(27, 1.5, NORMAL_PIXEL);
  208. graph[v28] = VertexProperties(28, 1.5, NORMAL_PIXEL);
  209. graph[v29] = VertexProperties(29, 1, TOP_PIXEL);
  210. graph[v30] = VertexProperties(30, 1, TOP_PIXEL);
  211. graph[v31] = VertexProperties(31, 2, NORMAL_PIXEL);
  212. graph[v32] = VertexProperties(32, 2, NORMAL_PIXEL);
  213. graph[v33] = VertexProperties(33, 2, NORMAL_PIXEL);
  214. graph[v34] = VertexProperties(34, 1.5, TOP_PIXEL);
  215. graph[v35] = VertexProperties(35, 1.5, NORMAL_PIXEL);
  216. graph[v36] = VertexProperties(36, 1.5, TOP_PIXEL);
  217. graph[v37] = VertexProperties(37, 1.5, NORMAL_PIXEL);
  218. /*OrientedGraph::vertex_descriptor v0 = boost::add_vertex(graph);
  219. OrientedGraph::vertex_descriptor v3 = boost::add_vertex(graph);
  220. OrientedGraph::vertex_descriptor v9 = boost::add_vertex(graph);
  221. OrientedGraph::vertex_descriptor v10 = boost::add_vertex(graph);
  222. boost::add_edge(v3, v0, 1., graph);
  223. boost::add_edge(v10, v3, 1., graph);
  224. boost::add_edge(v9, v10, 1., graph);
  225. boost::add_edge(v9, v3, 1., graph);
  226. graph[v10] = VertexProperties(10, 1., NORMAL_PIXEL);
  227. graph[v0] = VertexProperties(0, 1., NORMAL_PIXEL);
  228. graph[v3] = VertexProperties(3, 1., NORMAL_PIXEL);
  229. graph[v9] = VertexProperties(9, 1., TOP_PIXEL);*/
  230. graphs.push_back(graph);
  231. }
  232. {
  233. /*// input S1
  234. input_edges.push_back(InputEdges());
  235. // input S2
  236. input_edges.push_back(InputEdges());
  237. input_edges[1].push_back(Edge(1, 0));
  238. input_edges[1].push_back(Edge(2, 0));
  239. input_edges[1].push_back(Edge(2, 3));
  240. // output S1
  241. output_edges.push_back(OutputEdges());
  242. output_edges[0].push_back(Edge(1, 0));
  243. output_edges[0].push_back(Edge(2, 0));
  244. output_edges[0].push_back(Edge(2, 3));
  245. // output S2
  246. output_edges.push_back(OutputEdges());
  247. // parent
  248. parent_connections.push_back(Connection(Port(1,1),Port(2,0)));
  249. parent_connections.push_back(Connection(Port(1,2),Port(2,0)));
  250. parent_connections.push_back(Connection(Port(1,2),Port(2,3)));*/
  251. // input S1
  252. input_edges.push_back(InputEdges());
  253. input_edges[0].push_back(Edge(6, 1));
  254. input_edges[0].push_back(Edge(26, 11));
  255. // input S2
  256. input_edges.push_back(InputEdges());
  257. input_edges[1].push_back(Edge(1, 0));
  258. input_edges[1].push_back(Edge(1, 2));
  259. input_edges[1].push_back(Edge(5, 6));
  260. // output S1
  261. output_edges.push_back(OutputEdges());
  262. output_edges[0].push_back(Edge(1, 0));
  263. output_edges[0].push_back(Edge(1, 2));
  264. output_edges[0].push_back(Edge(5, 6));
  265. // output S2
  266. output_edges.push_back(OutputEdges());
  267. output_edges[1].push_back(Edge(6, 1));
  268. output_edges[1].push_back(Edge(26, 11));
  269. // parent
  270. parent_connections.push_back(Connection(Port(1,1),Port(2,0)));
  271. parent_connections.push_back(Connection(Port(1,1),Port(2,2)));
  272. parent_connections.push_back(Connection(Port(1,5),Port(2,6)));
  273. parent_connections.push_back(Connection(Port(2,6),Port(1,1)));
  274. parent_connections.push_back(Connection(Port(2,26),Port(1,11)));
  275. }
  276. }
  277. };
  278. class CorsenFlatGraphBuilder
  279. {
  280. public:
  281. CorsenFlatGraphBuilder()
  282. { }
  283. void build(OrientedGraphs& graphs, InputEdgeList& /* input_edges */,
  284. OutputEdgeList& /* output_edges */,
  285. Connections& /* parent_connections */)
  286. {
  287. OrientedGraph graph;
  288. //build_corsen_graph(graph);
  289. graphs.push_back(graph);
  290. }
  291. };
  292. class RandomFlatGraphBuilder
  293. {
  294. public:
  295. RandomFlatGraphBuilder()
  296. { }
  297. void build(OrientedGraphs& graphs, InputEdgeList& ,
  298. OutputEdgeList& ,
  299. Connections& )
  300. {
  301. /*
  302. * *** Graphe créé différent du graphe obtenu dans graph_partitioning ! Solution ? ***
  303. */
  304. /*
  305. const char *texte = new const char();
  306. texte = "enregistrement.txt";
  307. Graph_constructor_txt(texte, &graph);*/
  308. OrientedGraph graph;
  309. unsigned int edge_number = 200;
  310. std::vector<int> levels = {/*5,4,*/ 3, 2 };
  311. unsigned int source_number = edge_number/100*1;
  312. unsigned int min_neigh = 2;
  313. unsigned int max_neigh = 3;
  314. build_generator_graph(&graph,edge_number,source_number,min_neigh,max_neigh,levels);
  315. graphs.push_back(graph);
  316. }
  317. };
  318. class RandomLinkedFlatGraphBuilder
  319. {
  320. public:
  321. RandomLinkedFlatGraphBuilder()
  322. { }
  323. void build(OrientedGraphs& graphs, InputEdgeList& ,
  324. OutputEdgeList& ,
  325. Connections& )
  326. {
  327. /*
  328. * *** Graphe créé différent du graphe obtenu dans graph_partitioning ! Solution ? ***
  329. */
  330. /*
  331. const char *texte = new const char();
  332. texte = "enregistrement.txt";
  333. Graph_constructor_txt(texte, &graph);*/
  334. OrientedGraph graph;
  335. unsigned int edge_number = 5000;
  336. unsigned int levels = 60;
  337. unsigned int min_neigh = 2;
  338. unsigned int max_neigh = 3;
  339. build_generator_graph_linked(&graph,edge_number,levels,min_neigh,max_neigh);
  340. graphs.push_back(graph);
  341. }
  342. };
  343. class RandomGridFlatGraphBuilder
  344. {
  345. public:
  346. RandomGridFlatGraphBuilder()
  347. { }
  348. void build(OrientedGraphs& graphs, InputEdgeList& ,
  349. OutputEdgeList& ,
  350. Connections& )
  351. {
  352. OrientedGraph graph;
  353. unsigned int side = 90;
  354. std::vector<std::pair<int,int>> vertex_selection;
  355. std::pair<int,int> tmp;
  356. tmp.first = 0;
  357. tmp.second = 3;
  358. vertex_selection.push_back(tmp);
  359. Entiers weight_vertex;
  360. weight_vertex.push_back(1);
  361. const char *edge_weight;
  362. edge_weight = "../../sortie_graphe/tests_grid.txt";
  363. bool rec = false;
  364. build_graph_grid(&graph, side, vertex_selection, weight_vertex, edge_weight, rec);;
  365. graphs.push_back(graph);
  366. }
  367. };
  368. } } } // namespace paradevs tests boost_graph
  369. #endif