graph_build.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. /**
  2. * @file tests/boost_graph/partitioning/graph_build.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 <tests/boost_graph/partitioning/graph_build.hpp>
  26. #include <iostream>
  27. //#include <tests/corsen/lib/Corsen.hpp>
  28. namespace paradevs { namespace tests { namespace boost_graph {
  29. void build_graph(OrientedGraph& og, unsigned int edge_number)
  30. {
  31. if(edge_number == 11){
  32. vertex_to v0 = boost::add_vertex(og);
  33. vertex_to v1 = boost::add_vertex(og);
  34. vertex_to v2 = boost::add_vertex(og);
  35. vertex_to v3 = boost::add_vertex(og);
  36. vertex_to v4 = boost::add_vertex(og);
  37. vertex_to v5 = boost::add_vertex(og);
  38. vertex_to v6 = boost::add_vertex(og);
  39. vertex_to v7 = boost::add_vertex(og);
  40. vertex_to v8 = boost::add_vertex(og);
  41. vertex_to v9 = boost::add_vertex(og);
  42. vertex_to v10 = boost::add_vertex(og);
  43. add_edge(v1, v0, EdgeProperties(1), og);
  44. add_edge(v2, v0, EdgeProperties(1), og);
  45. add_edge(v3, v0, EdgeProperties(1), og);
  46. add_edge(v1, v2, EdgeProperties(1), og);
  47. add_edge(v4, v1, EdgeProperties(1.), og);
  48. add_edge(v5, v1, EdgeProperties(1.), og);
  49. add_edge(v6, v1, EdgeProperties(1.), og);
  50. add_edge(v6, v2, EdgeProperties(1.), og);
  51. add_edge(v2, v3, EdgeProperties(1.), og);
  52. add_edge(v9, v3, EdgeProperties(1.), og);
  53. add_edge(v10, v3, EdgeProperties(1.), og);
  54. add_edge(v4, v5, EdgeProperties(1), og);
  55. add_edge(v5, v6, EdgeProperties(1), og);
  56. add_edge(v7, v4, EdgeProperties(1.), og);
  57. add_edge(v8, v4, EdgeProperties(1.), og);
  58. add_edge(v7, v8, EdgeProperties(1), og);
  59. add_edge(v9, v10, EdgeProperties(1.), og);
  60. og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
  61. og[v8] = VertexProperties(8, 1., NORMAL_PIXEL);
  62. og[v10] = VertexProperties(10, 1, NORMAL_PIXEL);
  63. og[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
  64. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  65. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  66. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  67. og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
  68. og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
  69. og[v7] = VertexProperties(7, 1., TOP_PIXEL);
  70. og[v9] = VertexProperties(9, 1., TOP_PIXEL);
  71. } else if(edge_number == 38){
  72. vertex_to v0 = boost::add_vertex(og);
  73. vertex_to v1 = boost::add_vertex(og);
  74. vertex_to v2 = boost::add_vertex(og);
  75. vertex_to v3 = boost::add_vertex(og);
  76. vertex_to v4 = boost::add_vertex(og);
  77. vertex_to v5 = boost::add_vertex(og);
  78. vertex_to v6 = boost::add_vertex(og);
  79. vertex_to v7 = boost::add_vertex(og);
  80. vertex_to v8 = boost::add_vertex(og);
  81. vertex_to v9 = boost::add_vertex(og);
  82. vertex_to v10 = boost::add_vertex(og);
  83. vertex_to v11 = boost::add_vertex(og);
  84. vertex_to v12 = boost::add_vertex(og);
  85. vertex_to v13 = boost::add_vertex(og);
  86. vertex_to v14 = boost::add_vertex(og);
  87. vertex_to v15 = boost::add_vertex(og);
  88. vertex_to v16 = boost::add_vertex(og);
  89. vertex_to v17 = boost::add_vertex(og);
  90. vertex_to v18 = boost::add_vertex(og);
  91. vertex_to v19 = boost::add_vertex(og);
  92. vertex_to v20 = boost::add_vertex(og);
  93. vertex_to v21 = boost::add_vertex(og);
  94. vertex_to v22 = boost::add_vertex(og);
  95. vertex_to v23 = boost::add_vertex(og);
  96. vertex_to v24 = boost::add_vertex(og);
  97. vertex_to v25 = boost::add_vertex(og);
  98. vertex_to v26 = boost::add_vertex(og);
  99. vertex_to v27 = boost::add_vertex(og);
  100. vertex_to v28 = boost::add_vertex(og);
  101. vertex_to v29 = boost::add_vertex(og);
  102. vertex_to v30 = boost::add_vertex(og);
  103. vertex_to v31 = boost::add_vertex(og);
  104. vertex_to v32 = boost::add_vertex(og);
  105. vertex_to v33 = boost::add_vertex(og);
  106. vertex_to v34 = boost::add_vertex(og);
  107. vertex_to v35 = boost::add_vertex(og);
  108. vertex_to v36 = boost::add_vertex(og);
  109. vertex_to v37 = boost::add_vertex(og);
  110. add_edge(v1, v0, EdgeProperties(1.), og);
  111. add_edge(v2, v0, EdgeProperties(1.), og);
  112. add_edge(v3, v0, EdgeProperties(1.), og);
  113. add_edge(v1, v2, EdgeProperties(1.), og);
  114. add_edge(v4, v1, EdgeProperties(1.), og);
  115. add_edge(v5, v1, EdgeProperties(1.), og);
  116. add_edge(v6, v1, EdgeProperties(1.), og);
  117. add_edge(v6, v2, EdgeProperties(1.), og);
  118. add_edge(v2, v3, EdgeProperties(1.), og);
  119. add_edge(v9, v3, EdgeProperties(1.), og);
  120. add_edge(v10, v3, EdgeProperties(1.), og);
  121. add_edge(v4, v5, EdgeProperties(1.), og);
  122. add_edge(v5, v6, EdgeProperties(1.), og);
  123. add_edge(v7, v4, EdgeProperties(1.), og);
  124. add_edge(v8, v4, EdgeProperties(1.), og);
  125. add_edge(v7, v8, EdgeProperties(1.), og);
  126. add_edge(v9, v10, EdgeProperties(1.), og);
  127. add_edge(v8, v11, EdgeProperties(1.), og);
  128. add_edge(v11, v4, EdgeProperties(1.), og);
  129. add_edge(v12, v13, EdgeProperties(1.), og);
  130. add_edge(v12, v7, EdgeProperties(1.), og);
  131. add_edge(v13, v7, EdgeProperties(1.), og);
  132. add_edge(v14, v15, EdgeProperties(1.), og);
  133. add_edge(v14, v12, EdgeProperties(1.), og);
  134. add_edge(v15, v16, EdgeProperties(1.), og);
  135. add_edge(v15, v12, EdgeProperties(1.), og);
  136. add_edge(v16, v17, EdgeProperties(1.), og);
  137. add_edge(v16, v12, EdgeProperties(1.), og);
  138. add_edge(v17, v12, EdgeProperties(1.), og);
  139. add_edge(v18, v19, EdgeProperties(1.), og);
  140. add_edge(v18, v8, EdgeProperties(1.), og);
  141. add_edge(v19, v20, EdgeProperties(1.), og);
  142. add_edge(v19, v8, EdgeProperties(1.), og);
  143. add_edge(v20, v8, EdgeProperties(1.), og);
  144. add_edge(v21, v22, EdgeProperties(1.), og);
  145. add_edge(v21, v19, EdgeProperties(1.), og);
  146. add_edge(v22, v23, EdgeProperties(1.), og);
  147. add_edge(v22, v19, EdgeProperties(1.), og);
  148. add_edge(v23, v19, EdgeProperties(1.), og);
  149. add_edge(v24, v25, EdgeProperties(1.), og);
  150. add_edge(v24, v6, EdgeProperties(1.), og);
  151. add_edge(v25, v6, EdgeProperties(1.), og);
  152. add_edge(v26, v11, EdgeProperties(1.), og);
  153. add_edge(v26, v27, EdgeProperties(1.), og);
  154. add_edge(v26, v24, EdgeProperties(1.), og);
  155. add_edge(v27, v24, EdgeProperties(1.), og);
  156. add_edge(v28, v25, EdgeProperties(1.), og);
  157. add_edge(v29, v27, EdgeProperties(1.), og);
  158. add_edge(v29, v28, EdgeProperties(1.), og);
  159. add_edge(v30, v27, EdgeProperties(1.), og);
  160. add_edge(v30, v28, EdgeProperties(1.), og);
  161. add_edge(v31, v32, EdgeProperties(1.), og);
  162. add_edge(v31, v10, EdgeProperties(1.), og);
  163. add_edge(v32, v33, EdgeProperties(1.), og);
  164. add_edge(v32, v10, EdgeProperties(1.), og);
  165. add_edge(v33, v10, EdgeProperties(1.), og);
  166. add_edge(v34, v31, EdgeProperties(1.), og);
  167. add_edge(v34, v35, EdgeProperties(1.), og);
  168. add_edge(v35, v31, EdgeProperties(1.), og);
  169. add_edge(v35, v32, EdgeProperties(1.), og);
  170. add_edge(v36, v32, EdgeProperties(1.), og);
  171. add_edge(v36, v37, EdgeProperties(1.), og);
  172. add_edge(v36, v33, EdgeProperties(1.), og);
  173. add_edge(v37, v33, EdgeProperties(1.), og);
  174. add_edge(v4, v0, EdgeProperties(1.), og);
  175. add_edge(v9, v2, EdgeProperties(1.), og);
  176. add_edge(v28, v24, EdgeProperties(1.), og);
  177. add_edge(v28, v31, EdgeProperties(1.), og);
  178. add_edge(v33, v3, EdgeProperties(1.), og);
  179. add_edge(v33, v0, EdgeProperties(1.), og);
  180. add_edge(v36, v3, EdgeProperties(1.), og);
  181. add_edge(v17, v13, EdgeProperties(1.), og);
  182. add_edge(v17, v7, EdgeProperties(1.), og);
  183. add_edge(v21, v23, EdgeProperties(1.), og);
  184. add_edge(v23, v20, EdgeProperties(1.), og);
  185. add_edge(v26, v4, EdgeProperties(1.), og);
  186. og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
  187. og[v8] = VertexProperties(8, 1, NORMAL_PIXEL);
  188. og[v10] = VertexProperties(10, 1, NORMAL_PIXEL);
  189. og[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
  190. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  191. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  192. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  193. og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
  194. og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
  195. og[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
  196. og[v9] = VertexProperties(9, 1, TOP_PIXEL);
  197. og[v11] = VertexProperties(11, 1, NORMAL_PIXEL);
  198. og[v12] = VertexProperties(12, 1, NORMAL_PIXEL);
  199. og[v13] = VertexProperties(13, 1, NORMAL_PIXEL);
  200. og[v14] = VertexProperties(14, 1, TOP_PIXEL);
  201. og[v15] = VertexProperties(15, 1, NORMAL_PIXEL);
  202. og[v16] = VertexProperties(16, 1, NORMAL_PIXEL);
  203. og[v17] = VertexProperties(17, 1, NORMAL_PIXEL);
  204. og[v18] = VertexProperties(18, 1, TOP_PIXEL);
  205. og[v19] = VertexProperties(19, 1, NORMAL_PIXEL);
  206. og[v20] = VertexProperties(20, 1, NORMAL_PIXEL);
  207. og[v21] = VertexProperties(21, 1, TOP_PIXEL);
  208. og[v22] = VertexProperties(22, 1, NORMAL_PIXEL);
  209. og[v23] = VertexProperties(23, 1, NORMAL_PIXEL);
  210. og[v24] = VertexProperties(24, 1, NORMAL_PIXEL);
  211. og[v25] = VertexProperties(25, 1, NORMAL_PIXEL);
  212. og[v26] = VertexProperties(26, 1, TOP_PIXEL);
  213. og[v27] = VertexProperties(27, 1, NORMAL_PIXEL);
  214. og[v28] = VertexProperties(28, 1, NORMAL_PIXEL);
  215. og[v29] = VertexProperties(29, 1, TOP_PIXEL);
  216. og[v30] = VertexProperties(30, 1, TOP_PIXEL);
  217. og[v31] = VertexProperties(31, 1, NORMAL_PIXEL);
  218. og[v32] = VertexProperties(32, 1, NORMAL_PIXEL);
  219. og[v33] = VertexProperties(33, 1, NORMAL_PIXEL);
  220. og[v34] = VertexProperties(34, 1, TOP_PIXEL);
  221. og[v35] = VertexProperties(35, 1, NORMAL_PIXEL);
  222. og[v36] = VertexProperties(36, 1, TOP_PIXEL);
  223. og[v37] = VertexProperties(37, 1, NORMAL_PIXEL);
  224. }else{
  225. std::cout<<"Le type de artificiel graphe choisi n'existe pas ! "<<std::endl;
  226. }
  227. }
  228. void modify_file_paths(std::string& absolutePath,
  229. std::vector < std::string* >& files)
  230. {
  231. for (std::vector < std::string* >::iterator it = files.begin();
  232. it != files.end(); it++) {
  233. (*it)->insert(0, absolutePath);
  234. }
  235. }
  236. void build_graph_cyclique(OrientedGraph& og)
  237. {
  238. vertex_to v0 = boost::add_vertex(og);
  239. vertex_to v1 = boost::add_vertex(og);
  240. vertex_to v2 = boost::add_vertex(og);
  241. vertex_to v3 = boost::add_vertex(og);
  242. vertex_to v4 = boost::add_vertex(og);
  243. vertex_to v5 = boost::add_vertex(og);
  244. vertex_to v6 = boost::add_vertex(og);
  245. vertex_to v7 = boost::add_vertex(og);
  246. vertex_to v8 = boost::add_vertex(og);
  247. vertex_to v9 = boost::add_vertex(og);
  248. vertex_to v10 = boost::add_vertex(og);
  249. add_edge(v0, v1, EdgeProperties(1.), og);
  250. add_edge(v0, v2, EdgeProperties(1.), og);
  251. add_edge(v0, v3, EdgeProperties(1.), og);
  252. add_edge(v1, v3, EdgeProperties(1.), og);
  253. add_edge(v2, v1, EdgeProperties(1.), og);
  254. add_edge(v2, v3, EdgeProperties(1.), og);
  255. add_edge(v2, v4, EdgeProperties(1.), og);
  256. add_edge(v2, v5, EdgeProperties(1.), og);
  257. add_edge(v2, v7, EdgeProperties(1.), og);
  258. add_edge(v2, v9, EdgeProperties(1.), og);
  259. add_edge(v3, v4, EdgeProperties(1.), og);
  260. add_edge(v3, v5, EdgeProperties(1.), og);
  261. add_edge(v3, v7, EdgeProperties(1.), og);
  262. add_edge(v3, v9, EdgeProperties(1.), og);
  263. add_edge(v4, v6, EdgeProperties(1.), og);
  264. add_edge(v5, v4, EdgeProperties(1.), og);
  265. add_edge(v5, v6, EdgeProperties(1.), og);
  266. add_edge(v6, v7, EdgeProperties(1.), og);
  267. add_edge(v7, v8, EdgeProperties(1.), og);
  268. add_edge(v7, v10, EdgeProperties(1.), og);
  269. add_edge(v8, v9, EdgeProperties(1.), og);
  270. add_edge(v8, v10, EdgeProperties(1.), og);
  271. add_edge(v9, v10, EdgeProperties(1.), og);
  272. add_edge(v10, v0, EdgeProperties(1.), og);
  273. og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
  274. og[v8] = VertexProperties(8, 1, NORMAL_PIXEL);
  275. og[v10] = VertexProperties(10, 1, NORMAL_PIXEL);
  276. og[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
  277. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  278. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  279. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  280. og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
  281. og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
  282. og[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
  283. og[v9] = VertexProperties(9, 1, NORMAL_PIXEL);
  284. }
  285. void build_example_linked9(OrientedGraph& og)
  286. {
  287. vertex_to v0 = boost::add_vertex(og);
  288. vertex_to v1 = boost::add_vertex(og);
  289. vertex_to v2 = boost::add_vertex(og);
  290. vertex_to v3 = boost::add_vertex(og);
  291. vertex_to v4 = boost::add_vertex(og);
  292. vertex_to v5 = boost::add_vertex(og);
  293. vertex_to v6 = boost::add_vertex(og);
  294. vertex_to v7 = boost::add_vertex(og);
  295. vertex_to v8 = boost::add_vertex(og);
  296. vertex_to v9 = boost::add_vertex(og);
  297. add_edge(v1, v0, EdgeProperties(1.), og);
  298. add_edge(v2, v0, EdgeProperties(1.), og);
  299. add_edge(v3, v0, EdgeProperties(1.), og);
  300. add_edge(v4, v1, EdgeProperties(1.), og);
  301. add_edge(v4, v2, EdgeProperties(1.), og);
  302. add_edge(v5, v1, EdgeProperties(1.), og);
  303. add_edge(v6, v1, EdgeProperties(1.), og);
  304. add_edge(v6, v2, EdgeProperties(1.), og);
  305. add_edge(v6, v3, EdgeProperties(1.), og);
  306. add_edge(v7, v2, EdgeProperties(1.), og);
  307. add_edge(v7, v3, EdgeProperties(1.), og);
  308. add_edge(v8, v2, EdgeProperties(1.), og);
  309. add_edge(v9, v1, EdgeProperties(1.), og);
  310. add_edge(v9, v3, EdgeProperties(1.), og);
  311. og[v6] = VertexProperties(6, 1, TOP_PIXEL);
  312. og[v8] = VertexProperties(8, 1, TOP_PIXEL);
  313. og[v0] = VertexProperties(0, 1, NORMAL_PIXEL);
  314. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  315. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  316. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  317. og[v4] = VertexProperties(4, 1, TOP_PIXEL);
  318. og[v5] = VertexProperties(5, 1, TOP_PIXEL);
  319. og[v7] = VertexProperties(7, 1, TOP_PIXEL);
  320. og[v9] = VertexProperties(9, 1, TOP_PIXEL);
  321. }
  322. /*void build_corsen_graph(OrientedGraph& graph)
  323. {
  324. std::string absolutePath(
  325. "/home/eric/vle/vle-labs/paradevs/src/tests/corsen/data_s/");
  326. std::string modeFile(".mode");
  327. std::string parametersFile("par.txt");
  328. std::string elevationFile("alt");
  329. std::string outletFile("arbre");
  330. std::string layersFile("couche");
  331. std::string contextFile("contexte_yar_scenario.xml");
  332. std::string slopeFile("pav");
  333. std::vector < std::string* > files;
  334. Corsen c;
  335. files.push_back(&parametersFile);
  336. files.push_back(&modeFile);
  337. files.push_back(&elevationFile);
  338. files.push_back(&outletFile);
  339. files.push_back(&slopeFile);
  340. files.push_back(&contextFile);
  341. files.push_back(&layersFile);
  342. modify_file_paths(absolutePath, files);
  343. c.read(files, absolutePath);
  344. c.buildGraph();
  345. const DirectedGraph& g = c.getGraph().graph();
  346. std::vector < vertex_t > og_vertex_list;
  347. std::vector < vertex_t > dg_vertex_list;
  348. std::vector < int > dg_in_vertex_list;
  349. DirectedGraph::vertex_iterator it_dg, end_dg;
  350. tie(it_dg, end_dg) = vertices(g);
  351. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  352. og_vertex_list.push_back(add_vertex(graph));
  353. dg_vertex_list.push_back(*it_dg);
  354. dg_in_vertex_list.push_back(0);
  355. }
  356. tie(it_dg, end_dg) = vertices(g);
  357. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  358. DirectedGraph::adjacency_iterator neighbour_it, neighbour_end;
  359. tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_dg, g);
  360. for (; neighbour_it != neighbour_end; ++neighbour_it) {
  361. uint index = 0;
  362. while (dg_vertex_list[index] != *neighbour_it) {
  363. ++index;
  364. }
  365. ++dg_in_vertex_list[index];
  366. boost::add_edge(og_vertex_list[i], og_vertex_list[index],
  367. EdgeProperties(1.), graph);
  368. }
  369. }
  370. tie(it_dg, end_dg) = vertices(g);
  371. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  372. if (dg_in_vertex_list[i] == 0) {
  373. graph[og_vertex_list[i]] = VertexProperties(i, 1., TOP_PIXEL);
  374. } else {
  375. graph[og_vertex_list[i]] = VertexProperties(i, 1., NORMAL_PIXEL);
  376. }
  377. }
  378. }*/
  379. void brhtg_source(OrientedGraph *go,int nbr_vertex, int nbr_source, int nbr_v_min, int nbr_v_max, const std::vector<int> &niveau,
  380. std::vector<int> &Ram, std::vector<int> &Exu, const std::vector<vertex_to> &Vertexs,
  381. int nbr_passe, int nbr_npb){
  382. uint nbr_voisin;
  383. int niv=1;
  384. for(uint j =0; j<niveau.size()-1; j++){
  385. niv *= niveau.at(j);
  386. }
  387. int niv_tot=1;
  388. for(uint j =0; j<niveau.size(); j++){
  389. niv_tot *= niveau.at(j);
  390. }
  391. for(int b = 0; b<niv; b++){
  392. std::vector<uint> branche;
  393. int cpt = 0;
  394. while(cpt != niveau.at(niveau.size()-1)+1){
  395. branche.push_back((b*niveau.at(niveau.size()-1)+cpt)*nbr_npb);
  396. cpt++;
  397. }
  398. for(uint i =0; i<branche.size()-1;i++){
  399. for(uint j = branche.at(i); j<branche.at(i+1); j++){
  400. if(j==branche.at(branche.size()-1)-1){
  401. break;
  402. }
  403. else{
  404. nbr_voisin = rand_fini(nbr_v_min, nbr_v_max+1);
  405. uint cpt=0;
  406. Entiers ensemble;
  407. int cpt_nbr_s = 0;
  408. while(cpt != nbr_voisin){
  409. int val;
  410. if(j<branche.at(i)+nbr_source){ // Les sommets sont des sources donc imossible de recevoir des données
  411. val = rand_fini(j + 4, j + nbr_v_max + nbr_passe);
  412. }
  413. else if(j>=branche.at(i)+nbr_npb-nbr_passe && i!= (branche.size()-2)){ // Les sommets sont en fin de branche, nécessité de raccordement avec les autres branches
  414. val = rand_fini(branche.at(branche.size()-1)-4, branche.at(branche.size()-1));
  415. }
  416. else if(j>=branche.at(i)+nbr_npb-nbr_passe && i== (branche.size()-2)){ // Les sommets sont proche de l'exutoire
  417. val = rand_fini(j+1,branche.at(branche.size()-1));
  418. }
  419. else{ // Les sommets sont en plein milieu d'une branche
  420. val = rand_fini(j+1, j+nbr_passe);
  421. }
  422. if(In_tab(ensemble,val) != 1){
  423. ensemble.push_back(val);
  424. boost::add_edge(Vertexs.at(j), Vertexs.at(val), EdgeProperties(1.), *go);
  425. cpt++;
  426. }
  427. else{
  428. if((nbr_vertex-j) == cpt)
  429. break;
  430. else
  431. cpt_nbr_s++;
  432. }
  433. if(cpt_nbr_s>2*nbr_passe)
  434. break;
  435. }
  436. }
  437. }
  438. }
  439. /*for(int i =0; i<branche.size()-1; i++){
  440. for(int j = branche.at(i)+nbr_source; j<branche.at(i+1); j++){
  441. (*go)[Vertexs.at(j)] = VertexProperties(j, 1, NORMAL_PIXEL);
  442. }
  443. }
  444. for(int i =0; i<branche.size()-1; i++){
  445. for(int j = branche.at(i); j<branche.at(i)+nbr_source; j++){
  446. (*go)[Vertexs.at(j)] = VertexProperties(j, 1, TOP_PIXEL);
  447. }
  448. }*/
  449. Ram.push_back((niv_tot+b)*nbr_npb);
  450. Exu.push_back(branche.at(branche.size()-1)-1);
  451. }
  452. Ram.push_back(Ram.at(Ram.size()-1)+nbr_npb);
  453. if(niveau.size()>1){
  454. nbr_voisin = 2;
  455. for(uint k =0; k<Exu.size(); k++){
  456. for(uint l = Exu.at(k)-2; l<Exu.at(k)+1; l++){
  457. int cpt=0;
  458. Entiers ensemble;
  459. int cpt_nbr_s = 0;
  460. while(cpt!=nbr_voisin){
  461. int val = rand_fini(Ram.at(k),Ram.at(k)+2);
  462. if(In_tab(ensemble,val)!=1){
  463. ensemble.push_back(val);
  464. boost::add_edge(Vertexs.at(l), Vertexs.at(val), EdgeProperties(1.), *go);
  465. cpt++;
  466. }
  467. else{
  468. if((nbr_vertex-l)==cpt)
  469. break;
  470. else
  471. cpt_nbr_s++;
  472. }
  473. if(cpt_nbr_s>2*nbr_passe)
  474. break;
  475. }
  476. }
  477. }
  478. }
  479. }
  480. void brhtg_ramification(OrientedGraph *go, int nbr_vertex, int nbr_v_min, int nbr_v_max, const std::vector<int> &niveau,
  481. std::vector<int> &Ram, std::vector<int> &Exu, const std::vector<vertex_to> &Vertexs,
  482. int nbr_passe, int nbr_npb){
  483. int nbr_voisin;
  484. int cpt_ram = 1;
  485. while(cpt_ram != niveau.size()-1){
  486. int niv=1;
  487. for(int j =0; j<niveau.size()-1-cpt_ram; j++){
  488. niv *= niveau.at(j);
  489. }
  490. int niv_tot=0;
  491. for(int i =0; i<=cpt_ram; i++){
  492. int tmp_niv_tot=1;
  493. for(int j =0; j<niveau.size()-i; j++){
  494. tmp_niv_tot *= niveau.at(j);
  495. }
  496. niv_tot+=tmp_niv_tot;
  497. }
  498. std::vector<std::vector<int> > branche;
  499. int cpt_b=0;
  500. for(int j = 0; j<(Ram.size()-1)/niveau.at(niveau.size()-1-cpt_ram); j++){
  501. std::vector<int> tmp_branche;
  502. for(int i =0; i< niveau.at(niveau.size()-1-cpt_ram); i++){
  503. tmp_branche.push_back(Ram.at(i+cpt_b));
  504. }
  505. tmp_branche.push_back(tmp_branche.at(tmp_branche.size()-1)+nbr_npb);
  506. branche.push_back(tmp_branche);
  507. cpt_b+=niveau.at(niveau.size()-1-cpt_ram);
  508. }
  509. Ram.clear();
  510. Exu.clear();
  511. for(int b = 0; b<niv; b++){
  512. for(int i =0; i<branche.at(b).size()-1;i++){
  513. for(int j = branche.at(b).at(i); j<branche.at(b).at(i+1); j++){
  514. if(j==branche.at(b).at(branche.at(b).size()-1)-1){
  515. break;
  516. }
  517. else{
  518. nbr_voisin = rand_fini(nbr_v_min, nbr_v_max+1);
  519. int cpt=0;
  520. Entiers ensemble;
  521. int cpt_nbr_s = 0;
  522. while(cpt!=nbr_voisin){
  523. int val;
  524. if(j>=branche.at(b).at(i)+nbr_npb-nbr_passe && i!= (branche.at(b).size()-2)){ // Les sommets sont en fin de branche, nécessité de raccordement avec les autres branches
  525. val = rand_fini(branche.at(b).at(branche.at(b).size()-1)-4, branche.at(b).at(branche.at(b).size()-1));
  526. }
  527. else if(j>=branche.at(b).at(i)+nbr_npb-nbr_passe && i== (branche.at(b).size()-2)){ // Les sommets sont proche de l'exutoire
  528. val = rand_fini(j+1,branche.at(b).at(branche.at(b).size()-1));
  529. }
  530. else{ // Les sommets sont en plein milieu d'une branche
  531. val = rand_fini(j+1, j+nbr_passe);
  532. }
  533. if(In_tab(ensemble,val)!=1){
  534. ensemble.push_back(val);
  535. boost::add_edge(Vertexs.at(j), Vertexs.at(val), EdgeProperties(1.), *go);
  536. cpt++;
  537. }
  538. else{
  539. if((nbr_vertex-j)==cpt)
  540. break;
  541. else
  542. cpt_nbr_s++;
  543. }
  544. if(cpt_nbr_s>2*nbr_passe)
  545. break;
  546. }
  547. }
  548. }
  549. }
  550. Ram.push_back((niv_tot+b)*nbr_npb);
  551. Exu.push_back(branche.at(b).at(branche.at(b).size()-1)-1);
  552. /*for(int y =0; y<branche.at(b).size()-1; y++){
  553. for(int x = branche.at(b).at(y); x<branche.at(b).at(y+1); x++){
  554. (*go)[Vertexs.at(x)] = VertexProperties(x, 1, NORMAL_PIXEL);
  555. }
  556. }*/
  557. }
  558. Ram.push_back(Ram.at(Ram.size()-1)+nbr_npb);
  559. nbr_voisin = 2;
  560. for(int k =0; k<Exu.size(); k++){
  561. for(int l = Exu.at(k)-1; l<Exu.at(k)+1; l++){
  562. int cpt=0;
  563. Entiers ensemble;
  564. int cpt_nbr_s = 0;
  565. while(cpt!=nbr_voisin){
  566. int val = rand_fini(Ram.at(k),Ram.at(k)+2);
  567. if(In_tab(ensemble,val)!=1){
  568. ensemble.push_back(val);
  569. boost::add_edge(Vertexs.at(l), Vertexs.at(val), EdgeProperties(1.), *go);
  570. cpt++;
  571. }
  572. else{
  573. if((nbr_vertex-l)==cpt)
  574. break;
  575. else
  576. cpt_nbr_s++;
  577. }
  578. if(cpt_nbr_s>2*nbr_passe)
  579. break;
  580. }
  581. }
  582. }
  583. cpt_ram++;
  584. }
  585. }
  586. void brhtg_exutoire(OrientedGraph *go,int nbr_vertex,int nbr_v_min, int nbr_v_max,
  587. std::vector<int> &Ram, const std::vector<vertex_to> &Vertexs,
  588. int nbr_passe){
  589. int nbr_voisin;
  590. Ram.at(Ram.size()-1)=nbr_vertex;
  591. for(int i =0; i<Ram.size()-1;i++){
  592. for(int j = Ram.at(i); j<Ram.at(i+1); j++){
  593. if(j==Ram.at(Ram.size()-1)-1){
  594. //(*go)[Vertexs.at(j)] = VertexProperties(j, 1, NORMAL_PIXEL);
  595. break;
  596. }
  597. else{
  598. if(Ram.at(i+1)-j<nbr_passe)
  599. nbr_voisin = 2;
  600. else
  601. nbr_voisin = rand_fini(nbr_v_min, nbr_v_max+1);
  602. int cpt=0;
  603. Entiers ensemble;
  604. int cpt_nbr_s = 0;
  605. while(cpt!=nbr_voisin){
  606. int val;
  607. if(j>=Ram.at(i+1)-nbr_passe && i!=Ram.size()-2){ // Les sommets sont proche de l'exutoire
  608. val = rand_fini(Ram.at(Ram.size()-1)-4,Ram.at(Ram.size()-1));
  609. }
  610. else if(j>=Ram.at(i+1)-nbr_passe && i==Ram.size()-2){ // Les sommets sont proche de l'exutoire
  611. val = rand_fini(j+1,Ram.at(Ram.size()-1));
  612. }
  613. else{ // Les sommets sont en plein milieu d'une branche
  614. val = rand_fini(j+1, j+nbr_passe);
  615. }
  616. if(In_tab(ensemble,val)!=1&& j!=val){
  617. ensemble.push_back(val);
  618. boost::add_edge(Vertexs.at(j), Vertexs.at(val), EdgeProperties(1.), *go);
  619. cpt++;
  620. }
  621. else{
  622. if((nbr_vertex-j)==cpt)
  623. break;
  624. else
  625. cpt_nbr_s++;
  626. }
  627. if(cpt_nbr_s>2*nbr_passe)
  628. break;
  629. }
  630. }
  631. //(*go)[Vertexs.at(j)] = VertexProperties(j, 1, NORMAL_PIXEL);
  632. }
  633. }
  634. }
  635. void build_generator_graph(OrientedGraph *go, int nbr_vertex, int nbr_source, int nbr_v_min, int nbr_v_max,const std::vector<int> &niveau){
  636. std::vector<vertex_to> Vertexs;
  637. OrientedGraph::in_edge_iterator ei, edge_end;
  638. int nbr_npb;
  639. int nbr_branche = 0;
  640. int nbr_passe = 4;
  641. for(int i =0; i<nbr_vertex; i++){
  642. vertex_to vo = boost::add_vertex(*go);
  643. Vertexs.push_back(vo);
  644. }
  645. // Calcul du nombre de branches à partir de l'information des niveaux
  646. for(int i =0; i< niveau.size(); i++){
  647. int nbr_tmp =1;
  648. for(int j =0; j<=i; j++){
  649. nbr_tmp *= niveau.at(j);
  650. }
  651. nbr_branche += nbr_tmp;
  652. }
  653. // std::cout<<nbr_branche<<std::endl;
  654. nbr_npb = nbr_vertex/(nbr_branche);
  655. std::vector<int> Ram;
  656. std::vector<int> Exu;
  657. if(niveau.size()>1){
  658. /*
  659. * *** Code Source ***
  660. */
  661. brhtg_source(go,nbr_vertex,nbr_source,nbr_v_min,nbr_v_max,niveau,Ram,Exu,Vertexs,nbr_passe,nbr_npb);
  662. /*
  663. * *** Code Ramifications ***
  664. */
  665. brhtg_ramification(go,nbr_vertex,nbr_v_min,nbr_v_max,niveau,
  666. Ram,Exu,Vertexs,nbr_passe,nbr_npb);
  667. /*
  668. * *** Code Exutoire ***
  669. */
  670. brhtg_exutoire(go,nbr_vertex,nbr_v_min,nbr_v_max,
  671. Ram,Vertexs,nbr_passe);
  672. } else {
  673. brhtg_source(go,nbr_vertex,nbr_source,nbr_v_min,nbr_v_max,niveau,Ram,Exu,Vertexs,nbr_passe,nbr_npb);
  674. }
  675. std::vector < int > dg_in_vertex_list;
  676. std::vector <vertex_to> dg_vertex_list;
  677. OrientedGraph::vertex_iterator it_dg, end_dg;
  678. tie(it_dg, end_dg) = vertices(*go);
  679. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  680. dg_in_vertex_list.push_back(0);
  681. dg_vertex_list.push_back(*it_dg);
  682. }
  683. tie(it_dg, end_dg) = vertices(*go);
  684. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  685. OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  686. tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_dg, *go);
  687. for (; neighbour_it != neighbour_end; ++neighbour_it) {
  688. uint index = 0;
  689. while (dg_vertex_list[index] != *neighbour_it) {
  690. ++index;
  691. }
  692. ++dg_in_vertex_list[index];
  693. }
  694. }
  695. int compteur = 0;
  696. for(uint i = 0; i<num_vertices(*go); i++){
  697. bool indic = false;
  698. for(tie(ei,edge_end) = in_edges(i,*go); ei != edge_end; ++ei){
  699. indic = true;
  700. break;
  701. }
  702. if(dg_in_vertex_list.at(i) == 0 || indic == false){
  703. compteur++;
  704. (*go)[i] = VertexProperties(i, 1, TOP_PIXEL);
  705. }else{
  706. (*go)[i] = VertexProperties(i, 1, NORMAL_PIXEL);
  707. }
  708. //std::cout<<(*go)[i]._index<<" "<<indic<<" -> "<<(*go)[i]._type<<std::endl;
  709. }
  710. // std::cout<<"Compteur : "<<compteur<<std::endl;
  711. }
  712. void build_generator_graph_linked(OrientedGraph *go, int nbr_vertex, int nbr_couche, int nbr_v_min, int nbr_v_max){
  713. std::vector<vertex_to> Vertexs;
  714. OrientedGraph::in_edge_iterator ei, edge_end;
  715. for(int i =0; i<nbr_vertex; i++){
  716. vertex_to vo = boost::add_vertex(*go);
  717. Vertexs.push_back(vo);
  718. }
  719. /*Création du vecteur contenant le nombre de sommets par couche*/
  720. int midel_couche = nbr_couche-2;
  721. int top_couche;
  722. if(nbr_couche>5){
  723. top_couche = floor(nbr_vertex/3);//floor(midel_couche/2));
  724. }else{
  725. top_couche = floor(nbr_vertex/2);
  726. }
  727. int nbr_vertex_midel_couche = nbr_vertex - top_couche -1;
  728. int tmp = 0;
  729. std::vector<int> nbr_som_couche;
  730. nbr_som_couche.push_back(1);
  731. for(int i = 1; i <= midel_couche; i++){
  732. tmp += i;
  733. }
  734. for(int i = 0; i < midel_couche; i++){
  735. nbr_som_couche.push_back(floor((i+1)*nbr_vertex_midel_couche/tmp));
  736. }
  737. nbr_som_couche.push_back(top_couche);
  738. int sum = 0;
  739. for(int i = 0; i < nbr_som_couche.size(); i++){
  740. sum += nbr_som_couche.at(i);
  741. }
  742. int reste = nbr_vertex - sum;
  743. /*std::cout<<"sum : "<<sum<<std::endl;
  744. std::cout<<"midel_couche : "<<midel_couche<<std::endl;
  745. std::cout<<"top_couche : "<<top_couche<<std::endl;
  746. std::cout<<"nbr_vertex_midel_couche : "<<nbr_vertex_midel_couche<<std::endl;
  747. std::cout<<"tmp : "<<tmp<<std::endl;
  748. std::cout<<"reste : "<<reste<<std::endl;
  749. for(int i =0; i < nbr_som_couche.size(); i++){
  750. std::cout<<nbr_som_couche.at(i)<<" ";
  751. }
  752. std::cout<<std::endl;*/
  753. while(reste != 0){
  754. for(int i = 1; i <nbr_som_couche.size(); i++){
  755. nbr_som_couche.at(i) += 1;
  756. reste --;
  757. if(reste == 0){
  758. break;
  759. }
  760. }
  761. }
  762. /*for(int i =0; i < nbr_som_couche.size(); i++){
  763. std::cout<<nbr_som_couche.at(i)<<" ";
  764. }
  765. std::cout<<std::endl;*/
  766. /*Génération du graphe*/
  767. std::vector<int> tab_couche_som;
  768. tab_couche_som.push_back(0);
  769. for(int i =1; i<nbr_som_couche.size(); i++){
  770. tab_couche_som.push_back(tab_couche_som.at(i-1)+nbr_som_couche.at(i));
  771. }
  772. /*for(int i =0; i < tab_couche_som.size(); i++){
  773. std::cout<<tab_couche_som.at(i)<<" ";
  774. }
  775. std::cout<<std::endl;*/
  776. int nbr_vois = nbr_v_max+2;
  777. int cpt = 0;
  778. for(int i = tab_couche_som.at(tab_couche_som.size()-2)+1; i <= tab_couche_som.at(tab_couche_som.size()-1); i++){
  779. std::vector<int> vertex_tmp;
  780. int rand = rand_fini(nbr_v_min,nbr_v_max+1);
  781. int neigh_cpt = 0;
  782. while(neigh_cpt != rand){
  783. int val;
  784. if(cpt<nbr_vois){
  785. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-3)+cpt+1,tab_couche_som.at(tab_couche_som.size()-3)+cpt+1+nbr_vois);
  786. //std::cout<<"val1 : "<<val<<std::endl;
  787. }else if(cpt>nbr_vois && cpt<(tab_couche_som.at(tab_couche_som.size()-2)-tab_couche_som.at(tab_couche_som.size()-3)+1-nbr_vois)){
  788. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-3)+cpt+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-3)+cpt+1+nbr_vois);
  789. //std::cout<<"val2 : "<<val<<std::endl;
  790. }else{
  791. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2)+1-2*nbr_vois,tab_couche_som.at(tab_couche_som.size()-2)+1);
  792. //std::cout<<"val3 : "<<val<<std::endl;
  793. }
  794. if(In_tab(vertex_tmp,val) != 1){
  795. boost::add_edge(Vertexs.at(i), Vertexs.at(val), EdgeProperties(1.), *go);
  796. vertex_tmp.push_back(val);
  797. neigh_cpt ++;
  798. }
  799. }
  800. cpt ++;
  801. }
  802. //std::cout<<"Passage !"<<std::endl;
  803. for(int j = 2; j < tab_couche_som.size()-1; j++){
  804. cpt = 0;
  805. for(int i = tab_couche_som.at(tab_couche_som.size()-1-j)+1; i <= tab_couche_som.at(tab_couche_som.size()-1-(j-1)); i++){
  806. std::vector<int> vertex_tmp;
  807. int rand = rand_fini(nbr_v_min,nbr_v_max+1);
  808. //std::cout<<"rand : "<<rand<<std::endl;
  809. int neigh_cpt = 0;
  810. while(neigh_cpt != rand){
  811. int val;
  812. if((tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j))>2*nbr_vois){
  813. if(cpt<nbr_vois){
  814. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1,tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1+nbr_vois);
  815. //std::cout<<"val1 : "<<val<<std::endl;
  816. }else if(cpt>nbr_vois && cpt<(tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j)+1-nbr_vois)){
  817. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-j)+cpt+1+nbr_vois);
  818. //std::cout<<"val2 : "<<val<<std::endl;
  819. }else{
  820. if(2*nbr_vois<(tab_couche_som.at(tab_couche_som.size()-2-(j-1))-tab_couche_som.at(tab_couche_som.size()-2-j)+1)){
  821. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1-2*nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
  822. }else{
  823. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1-nbr_vois,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
  824. }
  825. //std::cout<<"val3 : "<<val<<std::endl;
  826. }
  827. }else{
  828. val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+1,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
  829. }
  830. //int val = rand_fini(tab_couche_som.at(tab_couche_som.size()-2-j)+1,tab_couche_som.at(tab_couche_som.size()-2-(j-1))+1);
  831. if(In_tab(vertex_tmp,val) != 1){
  832. boost::add_edge(Vertexs.at(i), Vertexs.at(val), EdgeProperties(1.), *go);
  833. vertex_tmp.push_back(val);
  834. neigh_cpt ++;
  835. }
  836. }
  837. cpt ++;
  838. }
  839. }
  840. //std::cout<<"Passage2 !"<<std::endl;
  841. for(int i = tab_couche_som.at(0)+1; i <= tab_couche_som.at(1); i++){
  842. //int val = rand_fini(0,2);
  843. //if(val == 0){
  844. boost::add_edge(Vertexs.at(i), Vertexs.at(0), EdgeProperties(1.), *go);
  845. //}
  846. }
  847. //std::cout<<"Passage3 !"<<std::endl;
  848. std::vector < int > dg_in_vertex_list;
  849. std::vector <vertex_to> dg_vertex_list;
  850. OrientedGraph::vertex_iterator it_dg, end_dg;
  851. tie(it_dg, end_dg) = vertices(*go);
  852. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  853. dg_in_vertex_list.push_back(0);
  854. dg_vertex_list.push_back(*it_dg);
  855. }
  856. tie(it_dg, end_dg) = vertices(*go);
  857. for (uint i = 0; it_dg != end_dg; ++it_dg, ++i) {
  858. OrientedGraph::adjacency_iterator neighbour_it, neighbour_end;
  859. tie(neighbour_it, neighbour_end) = adjacent_vertices(*it_dg, *go);
  860. for (; neighbour_it != neighbour_end; ++neighbour_it) {
  861. uint index = 0;
  862. while (dg_vertex_list[index] != *neighbour_it) {
  863. ++index;
  864. }
  865. ++dg_in_vertex_list[index];
  866. }
  867. }
  868. for(uint i = 0; i<num_vertices(*go); i++){
  869. bool indic = false;
  870. for(tie(ei,edge_end) = in_edges(i,*go); ei != edge_end; ++ei){
  871. indic = true;
  872. break;
  873. }
  874. if(dg_in_vertex_list.at(i) == 0 || indic == false){
  875. (*go)[i] = VertexProperties(i, 1, TOP_PIXEL);
  876. }else{
  877. (*go)[i] = VertexProperties(i, 1, NORMAL_PIXEL);
  878. }
  879. }
  880. }
  881. void build_graph_grid(OrientedGraph *go, int side, const std::vector<std::pair<int,int>> &vertex_selection, const Entiers &weight_vertex,const char *edge_weight, bool rec){
  882. int nbr_vertex = side*side;
  883. std::vector<vertex_to> Vertexs;
  884. for(int i =0; i<nbr_vertex; i++){
  885. vertex_to vo = boost::add_vertex(*go);
  886. Vertexs.push_back(vo);
  887. }
  888. if(rec == true){
  889. std::ofstream fichier (edge_weight, std::ios::out);
  890. for(int i = 0; i<side; i++){
  891. for(int j = 0; j<side-1; j++){
  892. boost::add_edge(i*side+j, i*side+j+1,EdgeProperties(1), *go);
  893. fichier<<i*side+j<<" "<<i*side+j+1<<" "<<1<<" "<<std::endl;
  894. }
  895. }
  896. for(int i = 0; i<side-1; i++){
  897. for(int j = 0; j<side; j++){
  898. boost::add_edge(i*side+j, (i+1)*side+j,EdgeProperties(1), *go);
  899. fichier<<i*side+j<<" "<<(i+1)*side+j<<" "<<1<<" "<<std::endl;
  900. }
  901. }
  902. fichier.close();
  903. }else{
  904. for(int i = 0; i<side; i++){
  905. for(int j = 0; j<side-1; j++){
  906. boost::add_edge(i*side+j, i*side+j+1,EdgeProperties(1), *go);
  907. }
  908. }
  909. for(int i = 0; i<side-1; i++){
  910. for(int j = 0; j<side; j++){
  911. boost::add_edge(i*side+j, (i+1)*side+j,EdgeProperties(1), *go);
  912. }
  913. }
  914. }
  915. (*go)[0] = VertexProperties(0, 1, TOP_PIXEL);
  916. for(uint i = 1; i<num_vertices(*go); i++){
  917. (*go)[i] = VertexProperties(i, 1, NORMAL_PIXEL);
  918. }
  919. for(int ind=0; ind<vertex_selection.size(); ind++){
  920. for(int ind_i = vertex_selection.at(ind).first; ind_i<vertex_selection.at(ind).second+1; ind_i++){
  921. if(ind_i != 0)
  922. (*go)[ind_i] = VertexProperties(ind_i, weight_vertex.at(ind), NORMAL_PIXEL);
  923. else
  924. (*go)[ind_i] = VertexProperties(ind_i, weight_vertex.at(ind), TOP_PIXEL);
  925. }
  926. }
  927. if(rec == false){
  928. std::ifstream fichier (edge_weight, std::ios::in);
  929. if(fichier){
  930. bool found;
  931. edge_to e1;
  932. int edge1, edge2;
  933. double edge_weight;
  934. int lines = std::count(std::istreambuf_iterator<char>( fichier ),std::istreambuf_iterator<char>(),'\n' );
  935. //std::cout<<lines<<std::endl;
  936. int cpt =0;
  937. int length;
  938. fichier.seekg(0, std::ios::beg);
  939. while(cpt < lines){
  940. fichier >> edge1 >> edge2 >> edge_weight;
  941. tie(e1,found)=edge(vertex(edge1,*go),vertex(edge2,*go),*go);
  942. (*go)[e1] = EdgeProperties(edge_weight);
  943. //std::cout<<edge1<<" "<<edge2<<" "<<edge_weight<<std::endl;
  944. length = fichier.tellg();
  945. fichier.seekg(length+1, std::ios::beg);
  946. cpt++;
  947. }
  948. }else{
  949. // std::cerr<<"Bugggggg du fichier txt !!!! "<<std::endl;
  950. }
  951. fichier.close();
  952. }
  953. }
  954. void build_example_ligne(OrientedGraph& og)
  955. {
  956. vertex_to v0 = boost::add_vertex(og);
  957. vertex_to v1 = boost::add_vertex(og);
  958. vertex_to v2 = boost::add_vertex(og);
  959. vertex_to v3 = boost::add_vertex(og);
  960. vertex_to v4 = boost::add_vertex(og);
  961. vertex_to v5 = boost::add_vertex(og);
  962. vertex_to v6 = boost::add_vertex(og);
  963. vertex_to v7 = boost::add_vertex(og);
  964. add_edge(v0, v1, EdgeProperties(1.), og);
  965. add_edge(v1, v2, EdgeProperties(1.), og);
  966. add_edge(v2, v3, EdgeProperties(1.), og);
  967. add_edge(v3, v4, EdgeProperties(1.), og);
  968. add_edge(v4, v5, EdgeProperties(1.), og);
  969. add_edge(v5, v6, EdgeProperties(1.), og);
  970. add_edge(v6, v7, EdgeProperties(1.), og);
  971. og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
  972. og[v0] = VertexProperties(0, 1, TOP_PIXEL);
  973. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  974. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  975. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  976. og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
  977. og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
  978. og[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
  979. }
  980. void build_example_grid(OrientedGraph& og)
  981. {
  982. vertex_to v0 = boost::add_vertex(og);
  983. vertex_to v1 = boost::add_vertex(og);
  984. vertex_to v2 = boost::add_vertex(og);
  985. vertex_to v3 = boost::add_vertex(og);
  986. vertex_to v4 = boost::add_vertex(og);
  987. vertex_to v5 = boost::add_vertex(og);
  988. vertex_to v6 = boost::add_vertex(og);
  989. vertex_to v7 = boost::add_vertex(og);
  990. add_edge(v0, v1, EdgeProperties(0.9), og);
  991. add_edge(v0, v2, EdgeProperties(0.9), og);
  992. add_edge(v0, v3, EdgeProperties(0.1), og);
  993. add_edge(v1, v2, EdgeProperties(0.1), og);
  994. add_edge(v1, v3, EdgeProperties(0.9), og);
  995. add_edge(v2, v3, EdgeProperties(0.9), og);
  996. add_edge(v2, v4, EdgeProperties(0.9), og);
  997. add_edge(v2, v5, EdgeProperties(0.1), og);
  998. add_edge(v3, v4, EdgeProperties(0.1), og);
  999. add_edge(v3, v5, EdgeProperties(0.9), og);
  1000. add_edge(v4, v5, EdgeProperties(0.9), og);
  1001. add_edge(v4, v6, EdgeProperties(0.9), og);
  1002. add_edge(v4, v7, EdgeProperties(0.1), og);
  1003. add_edge(v5, v6, EdgeProperties(0.1), og);
  1004. add_edge(v5, v7, EdgeProperties(0.9), og);
  1005. add_edge(v6, v7, EdgeProperties(0.9), og);
  1006. og[v6] = VertexProperties(6, 1, NORMAL_PIXEL);
  1007. og[v0] = VertexProperties(0, 1, TOP_PIXEL);
  1008. og[v1] = VertexProperties(1, 1, NORMAL_PIXEL);
  1009. og[v2] = VertexProperties(2, 1, NORMAL_PIXEL);
  1010. og[v3] = VertexProperties(3, 1, NORMAL_PIXEL);
  1011. og[v4] = VertexProperties(4, 1, NORMAL_PIXEL);
  1012. og[v5] = VertexProperties(5, 1, NORMAL_PIXEL);
  1013. og[v7] = VertexProperties(7, 1, NORMAL_PIXEL);
  1014. }
  1015. void build_parcellaire_graph(OrientedGraph *go, uint size_max, std::string name)
  1016. {
  1017. std::vector<std::pair<double,double> > point;
  1018. OrientedGraph::in_edge_iterator ei, edge_end;
  1019. double max_distance = 3000;//sqrt(2)*5*size_max/50;
  1020. double crit = sqrt(2)*5*size_max/1000;
  1021. std::cout << "distance max : " << max_distance << std::endl;
  1022. std::cout << "crit : " << crit << std::endl;
  1023. for(uint i = 0; i < size_max; i++)
  1024. {
  1025. std::pair<double,double> p;
  1026. p.first = rand()%(size_max*5-0) + 0;
  1027. p.second = rand()%(size_max*5-0) + 0;
  1028. point.push_back(p);
  1029. }
  1030. //std::cout << std::endl;
  1031. sort(point.begin(),point.end());
  1032. std::vector<std::vector<std::pair<double,uint> > > save_point_distance;
  1033. for(uint id = 0 ; id < point.size() - 1; id++)
  1034. {
  1035. std::vector<std::pair<double,uint> > point_distance, point_distance_sort;
  1036. //if(name != "multi"){
  1037. for(uint i = id +1 ; i < point.size(); i++)
  1038. {
  1039. std::pair<double,uint> pd;
  1040. pd.first = distance_t(point.at(id),point.at(i));
  1041. pd.second = i;
  1042. point_distance.push_back(pd);
  1043. }
  1044. /*}else{
  1045. for(uint i = 0 ; i < point.size(); i++)
  1046. {
  1047. std::pair<double,uint> pd;
  1048. pd.first = distance_t(point.at(id),point.at(i));
  1049. pd.second = i;
  1050. point_distance.push_back(pd);
  1051. }
  1052. }*/
  1053. point_distance_sort = point_distance;
  1054. sort(point_distance_sort.begin(), point_distance_sort.end());
  1055. std::vector<uint> deleted;
  1056. uint t;
  1057. if(point_distance_sort.size() > 50)
  1058. t = point_distance_sort.size()/2;
  1059. else
  1060. t = point_distance_sort.size();
  1061. /*if(name != "multi"){*/
  1062. for(uint i = 0 ; i < t; i++)
  1063. {
  1064. if(point_distance_sort.at(i).first < crit)
  1065. deleted.push_back(point_distance_sort.at(i).second);
  1066. //std::cout << point_distance_sort.at(i).second << " " << point_distance_sort.at(i).first <<std::endl;
  1067. }
  1068. /*}else{
  1069. for(uint i = 0 ; i < t; i++)
  1070. {
  1071. if(point_distance_sort.at(i).first < crit & point_distance_sort.at(i).first != 0)
  1072. deleted.push_back(point_distance_sort.at(i).second);
  1073. //std::cout << point_distance_sort.at(i).second << " " << point_distance_sort.at(i).first <<std::endl;
  1074. }
  1075. }*/
  1076. //std::cout<<std::endl;
  1077. sort(deleted.begin(), deleted.end());
  1078. std::reverse(deleted.begin(), deleted.end());
  1079. /*for(uint k = 0 ; k < deleted.size(); k++)
  1080. std::cout << deleted.at(k) << " " ;
  1081. std::cout<< std::endl << std::endl;*/
  1082. /*std::cout << "A : " << std::endl;
  1083. for(uint pp = 0; pp < point_distance.size(); pp++)
  1084. std::cout << point_distance.at(pp).second << " ";
  1085. std::cout<< std::endl << std::endl;*/
  1086. if(deleted.size() > 1)
  1087. {
  1088. //std::cout<<"Deleted"<<std::endl;
  1089. for(uint del = 0 ; del < deleted.size(); del++)
  1090. {
  1091. //std::cout << deleted.at(del) << " ";
  1092. for(uint idp = 0; idp < point_distance.size(); idp++)
  1093. {
  1094. if(point_distance.at(idp).second == deleted.at(del))
  1095. {
  1096. //std::cout << idp + id + 1 << std::endl;
  1097. /*if(name != "multi")
  1098. {*/
  1099. point.erase(point.begin() + idp + id + 1);
  1100. point_distance.erase(point_distance.begin() + idp);
  1101. for(uint pp = 0; pp < id ; pp++)
  1102. {
  1103. save_point_distance.at(pp).erase(save_point_distance.at(pp).begin() + idp);
  1104. for(uint j = idp; j < save_point_distance.at(pp).size(); j++)
  1105. save_point_distance.at(pp).at(j).second -=1;
  1106. }
  1107. for(uint j = idp; j < point_distance.size(); j++)
  1108. point_distance.at(j).second -= 1;
  1109. /*}else
  1110. {
  1111. point.erase(point.begin() + idp);
  1112. point_distance.erase(point_distance.begin() + idp);
  1113. for(uint pp = 0; pp < id ; pp++)
  1114. {
  1115. save_point_distance.at(pp).erase(save_point_distance.at(pp).begin() + idp);
  1116. for(uint j = idp; j < save_point_distance.at(pp).size(); j++)
  1117. save_point_distance.at(pp).at(j).second -=1;
  1118. }
  1119. for(uint j = idp; j < point_distance.size(); j++)
  1120. point_distance.at(j).second -= 1;
  1121. }*/
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. //std::cout << std::endl;
  1127. }else if(deleted.size() == 1)
  1128. {
  1129. //std::cout<<"Deleted 2"<<std::endl;
  1130. //std::cout << deleted.at(0) << " ";
  1131. for(uint idp = 0; idp < point_distance.size(); idp++)
  1132. {
  1133. if(point_distance.at(idp).second == deleted.at(0))
  1134. {
  1135. /*if(name != "multi")
  1136. {*/
  1137. //std::cout << idp + id + 1 << std::endl;
  1138. point.erase(point.begin() + idp + id + 1);
  1139. point_distance.erase(point_distance.begin() + idp);
  1140. for(uint pp = 0; pp < id ; pp++)
  1141. {
  1142. save_point_distance.at(pp).erase(save_point_distance.at(pp).begin() + idp);
  1143. for(uint j = idp; j < save_point_distance.at(pp).size(); j++)
  1144. save_point_distance.at(pp).at(j).second -=1;
  1145. }
  1146. for(uint j = idp; j < point_distance.size(); j++)
  1147. point_distance.at(j).second -= 1;
  1148. //std::cout << " toto " << std::endl;
  1149. /*}else{
  1150. point.erase(point.begin() + idp);
  1151. point_distance.erase(point_distance.begin() + idp);
  1152. for(uint pp = 0; pp < id ; pp++)
  1153. {
  1154. save_point_distance.at(pp).erase(save_point_distance.at(pp).begin() + idp);
  1155. for(uint j = idp; j < save_point_distance.at(pp).size(); j++)
  1156. save_point_distance.at(pp).at(j).second -=1;
  1157. }
  1158. for(uint j = idp; j < point_distance.size(); j++)
  1159. point_distance.at(j).second -= 1;
  1160. }*/
  1161. break;
  1162. }
  1163. }
  1164. //std::cout << std::endl;
  1165. }
  1166. /*std::cout << " B : " << std::endl;
  1167. for(uint pp = 0; pp < point_distance.size(); pp++)
  1168. std::cout << point_distance.at(pp).second << " ";
  1169. std::cout << std::endl << std::endl;*/
  1170. //sort(point_distance.begin(), point_distance.end());
  1171. save_point_distance.push_back(point_distance);
  1172. //std::cout << std::endl;
  1173. }
  1174. std::cout << "nombre de sommet" << point.size() << std::endl;
  1175. for(uint xt = 0; xt < save_point_distance.size(); xt++){
  1176. //std::cout << "** " << xt << " ** : ";
  1177. sort(save_point_distance.at(xt).begin(), save_point_distance.at(xt).end());
  1178. /*for(uint yt = 0; yt < save_point_distance.at(xt).size(); yt++){
  1179. std::cout << save_point_distance.at(xt).at(yt).first << " ";
  1180. }
  1181. std::cout << std::endl;*/
  1182. }
  1183. std::vector<vertex_to> Vertexs;
  1184. for(int i = 0; i < point.size(); i++){
  1185. vertex_to vo = boost::add_vertex(*go);
  1186. Vertexs.push_back(vo);
  1187. }
  1188. //std::cout << point.size() << std::endl;
  1189. for(int i = 0; i < point.size() -1; i++){
  1190. //std::cout << i << std::endl;
  1191. double dist = 0.;
  1192. uint xi;
  1193. //if(name != "multi")
  1194. xi = 0;
  1195. /*else
  1196. xi = 1;*/
  1197. while(dist < max_distance & xi < save_point_distance.at(i).size())
  1198. {
  1199. dist = save_point_distance.at(i).at(xi).first;
  1200. if(name != "multi")
  1201. add_edge(Vertexs.at(i), Vertexs.at(save_point_distance.at(i).at(xi).second), EdgeProperties(1.), *go);
  1202. else{
  1203. add_edge(Vertexs.at(i), Vertexs.at(save_point_distance.at(i).at(xi).second), EdgeProperties(1.), *go);
  1204. add_edge(Vertexs.at(save_point_distance.at(i).at(xi).second),Vertexs.at(i), EdgeProperties(1.), *go);
  1205. }
  1206. xi++;
  1207. }
  1208. (*go)[Vertexs.at(i)] = VertexProperties(i, 1., NORMAL_PIXEL);
  1209. }
  1210. (*go)[Vertexs.at(point.size()-1)] = VertexProperties(point.size()-1, 1., NORMAL_PIXEL);
  1211. /*std::cout << "ok"<< point.size() << std::endl;
  1212. for(int i = 0; i < (point.size() - arcs_max); i++)
  1213. {
  1214. std::cout << "ok"<< i << " "<< point.size() <<std::endl;
  1215. Entiers tmp_vector = Random_Sort_Vector2(i+1, point.size());
  1216. int ac = rand_fini(arcs_min, arcs_max);
  1217. std::cout << "! " << ac <<std::endl;
  1218. Entiers arcs;
  1219. for(uint p = 0; p < ac; p++)
  1220. arcs.push_back(tmp_vector.at(p));
  1221. //sort(arcs.begin(),arcs.end());
  1222. for(uint j = 0; j < arcs.size(); j++)
  1223. add_edge(Vertexs.at(i), Vertexs.at(arcs.at(j)), EdgeProperties(1.), *go);
  1224. (*go)[Vertexs.at(i)] = VertexProperties(i, 1., NORMAL_PIXEL);
  1225. }
  1226. std::cout << "ok1"<<std::endl;
  1227. for(int i = point.size() - arcs_max; i < point.size() - 2; i++)
  1228. {
  1229. Entiers tmp_vector = Random_Sort_Vector2(i+1,point.size());
  1230. int ac = rand_fini(1, 2);
  1231. Entiers arcs;
  1232. for(uint p = 0; p < ac; p++)
  1233. arcs.push_back(tmp_vector.at(p));
  1234. sort(arcs.begin(),arcs.end());
  1235. for(uint j = 0; j < arcs.size(); j++)
  1236. add_edge(Vertexs.at(i), Vertexs.at(arcs.at(j)), EdgeProperties(1.), *go);
  1237. (*go)[Vertexs.at(i)] = VertexProperties(i, 1., NORMAL_PIXEL);
  1238. }
  1239. std::cout << "ok2"<<std::endl;
  1240. add_edge(Vertexs.at(point.size()-2), Vertexs.at(point.size()-1), EdgeProperties(1.), *go);
  1241. (*go)[Vertexs.at(point.size()-2)] = VertexProperties(point.size()-2, 1., NORMAL_PIXEL);
  1242. (*go)[Vertexs.at(point.size()-1)] = VertexProperties(point.size()-1, 1., NORMAL_PIXEL);*/
  1243. for(uint i = 0; i< point.size(); i++){
  1244. bool indic = false;
  1245. for(tie(ei,edge_end) = in_edges(i,*go); ei != edge_end; ++ei){
  1246. indic = true;
  1247. break;
  1248. }
  1249. if(indic == false){
  1250. (*go)[i] = VertexProperties(i, 1, TOP_PIXEL);
  1251. }else{
  1252. (*go)[i] = VertexProperties(i, 1, NORMAL_PIXEL);
  1253. }
  1254. //std::cout<<(*go)[i]._index<<" "<<indic<<" -> "<<(*go)[i]._type<<std::endl;
  1255. }
  1256. }
  1257. /*void build_graph_grid_center(OrientedGraph *go, int side, const std::vector<std::pair<int,int>> &vertex_selection, const Entiers &weight_vertex,const char *edge_weight, bool rec){
  1258. int nbr_vertex = side*side;
  1259. std::vector<vertex_to> Vertexs;
  1260. for(int i =0; i<nbr_vertex; i++){
  1261. vertex_to vo = boost::add_vertex(*go);
  1262. Vertexs.push_back(vo);
  1263. }
  1264. // Ité 0
  1265. for(uint i = 0; i < 4; i++){
  1266. boost::add_edge(0, 2 + 2*i ,EdgeProperties(1) , *go);
  1267. }
  1268. // Ité 1
  1269. for(uint i = 1; i < 9; i++){
  1270. }
  1271. }*/
  1272. /*Vérification de la pondération + vérification des poids de la contraction + vérification de la structure de contraction*/
  1273. } } } // namespace paradevs tests boost_graph