graph_builder.hpp 17 KB

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