r_c_shortest_paths_test.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. // Copyright Michael Drexl 2005, 2006.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://boost.org/LICENSE_1_0.txt)
  5. #include <boost/config.hpp>
  6. #ifdef BOOST_MSVC
  7. # pragma warning(disable: 4267)
  8. #endif
  9. #include <boost/graph/adjacency_list.hpp>
  10. //#include <boost/graph/dijkstra_shortest_paths.hpp>
  11. #include <boost/graph/r_c_shortest_paths.hpp>
  12. #include <iostream>
  13. #include <boost/test/minimal.hpp>
  14. using namespace boost;
  15. struct SPPRC_Example_Graph_Vert_Prop
  16. {
  17. SPPRC_Example_Graph_Vert_Prop( int n = 0, int e = 0, int l = 0 )
  18. : num( n ), eat( e ), lat( l ) {}
  19. int num;
  20. // earliest arrival time
  21. int eat;
  22. // latest arrival time
  23. int lat;
  24. };
  25. struct SPPRC_Example_Graph_Arc_Prop
  26. {
  27. SPPRC_Example_Graph_Arc_Prop( int n = 0, int c = 0, int t = 0 )
  28. : num( n ), cost( c ), time( t ) {}
  29. int num;
  30. // traversal cost
  31. int cost;
  32. // traversal time
  33. int time;
  34. };
  35. typedef adjacency_list<vecS,
  36. vecS,
  37. directedS,
  38. SPPRC_Example_Graph_Vert_Prop,
  39. SPPRC_Example_Graph_Arc_Prop>
  40. SPPRC_Example_Graph;
  41. // data structures for spp without resource constraints:
  42. // ResourceContainer model
  43. struct spp_no_rc_res_cont
  44. {
  45. spp_no_rc_res_cont( int c = 0 ) : cost( c ) {};
  46. spp_no_rc_res_cont& operator=( const spp_no_rc_res_cont& other )
  47. {
  48. if( this == &other )
  49. return *this;
  50. this->~spp_no_rc_res_cont();
  51. new( this ) spp_no_rc_res_cont( other );
  52. return *this;
  53. }
  54. int cost;
  55. };
  56. bool operator==( const spp_no_rc_res_cont& res_cont_1,
  57. const spp_no_rc_res_cont& res_cont_2 )
  58. {
  59. return ( res_cont_1.cost == res_cont_2.cost );
  60. }
  61. bool operator<( const spp_no_rc_res_cont& res_cont_1,
  62. const spp_no_rc_res_cont& res_cont_2 )
  63. {
  64. return ( res_cont_1.cost < res_cont_2.cost );
  65. }
  66. // ResourceExtensionFunction model
  67. class ref_no_res_cont
  68. {
  69. public:
  70. inline bool operator()( const SPPRC_Example_Graph& g,
  71. spp_no_rc_res_cont& new_cont,
  72. const spp_no_rc_res_cont& old_cont,
  73. graph_traits
  74. <SPPRC_Example_Graph>::edge_descriptor ed ) const
  75. {
  76. new_cont.cost = old_cont.cost + g[ed].cost;
  77. return true;
  78. }
  79. };
  80. // DominanceFunction model
  81. class dominance_no_res_cont
  82. {
  83. public:
  84. inline bool operator()( const spp_no_rc_res_cont& res_cont_1,
  85. const spp_no_rc_res_cont& res_cont_2 ) const
  86. {
  87. // must be "<=" here!!!
  88. // must NOT be "<"!!!
  89. return res_cont_1.cost <= res_cont_2.cost;
  90. // this is not a contradiction to the documentation
  91. // the documentation says:
  92. // "A label $l_1$ dominates a label $l_2$ if and only if both are resident
  93. // at the same vertex, and if, for each resource, the resource consumption
  94. // of $l_1$ is less than or equal to the resource consumption of $l_2$,
  95. // and if there is at least one resource where $l_1$ has a lower resource
  96. // consumption than $l_2$."
  97. // one can think of a new label with a resource consumption equal to that
  98. // of an old label as being dominated by that old label, because the new
  99. // one will have a higher number and is created at a later point in time,
  100. // so one can implicitly use the number or the creation time as a resource
  101. // for tie-breaking
  102. }
  103. };
  104. // end data structures for spp without resource constraints:
  105. // data structures for shortest path problem with time windows (spptw)
  106. // ResourceContainer model
  107. struct spp_spptw_res_cont
  108. {
  109. spp_spptw_res_cont( int c = 0, int t = 0 ) : cost( c ), time( t ) {}
  110. spp_spptw_res_cont& operator=( const spp_spptw_res_cont& other )
  111. {
  112. if( this == &other )
  113. return *this;
  114. this->~spp_spptw_res_cont();
  115. new( this ) spp_spptw_res_cont( other );
  116. return *this;
  117. }
  118. int cost;
  119. int time;
  120. };
  121. bool operator==( const spp_spptw_res_cont& res_cont_1,
  122. const spp_spptw_res_cont& res_cont_2 )
  123. {
  124. return ( res_cont_1.cost == res_cont_2.cost
  125. && res_cont_1.time == res_cont_2.time );
  126. }
  127. bool operator<( const spp_spptw_res_cont& res_cont_1,
  128. const spp_spptw_res_cont& res_cont_2 )
  129. {
  130. if( res_cont_1.cost > res_cont_2.cost )
  131. return false;
  132. if( res_cont_1.cost == res_cont_2.cost )
  133. return res_cont_1.time < res_cont_2.time;
  134. return true;
  135. }
  136. // ResourceExtensionFunction model
  137. class ref_spptw
  138. {
  139. public:
  140. inline bool operator()( const SPPRC_Example_Graph& g,
  141. spp_spptw_res_cont& new_cont,
  142. const spp_spptw_res_cont& old_cont,
  143. graph_traits
  144. <SPPRC_Example_Graph>::edge_descriptor ed ) const
  145. {
  146. const SPPRC_Example_Graph_Arc_Prop& arc_prop =
  147. get( edge_bundle, g )[ed];
  148. const SPPRC_Example_Graph_Vert_Prop& vert_prop =
  149. get( vertex_bundle, g )[target( ed, g )];
  150. new_cont.cost = old_cont.cost + arc_prop.cost;
  151. int& i_time = new_cont.time;
  152. i_time = old_cont.time + arc_prop.time;
  153. i_time < vert_prop.eat ? i_time = vert_prop.eat : 0;
  154. return i_time <= vert_prop.lat ? true : false;
  155. }
  156. };
  157. // DominanceFunction model
  158. class dominance_spptw
  159. {
  160. public:
  161. inline bool operator()( const spp_spptw_res_cont& res_cont_1,
  162. const spp_spptw_res_cont& res_cont_2 ) const
  163. {
  164. // must be "<=" here!!!
  165. // must NOT be "<"!!!
  166. return res_cont_1.cost <= res_cont_2.cost
  167. && res_cont_1.time <= res_cont_2.time;
  168. // this is not a contradiction to the documentation
  169. // the documentation says:
  170. // "A label $l_1$ dominates a label $l_2$ if and only if both are resident
  171. // at the same vertex, and if, for each resource, the resource consumption
  172. // of $l_1$ is less than or equal to the resource consumption of $l_2$,
  173. // and if there is at least one resource where $l_1$ has a lower resource
  174. // consumption than $l_2$."
  175. // one can think of a new label with a resource consumption equal to that
  176. // of an old label as being dominated by that old label, because the new
  177. // one will have a higher number and is created at a later point in time,
  178. // so one can implicitly use the number or the creation time as a resource
  179. // for tie-breaking
  180. }
  181. };
  182. // end data structures for shortest path problem with time windows (spptw)
  183. struct spp_spptw_marked_res_cont {
  184. spp_spptw_marked_res_cont(SPPRC_Example_Graph::vertex_descriptor v, int c = 0, int t = 0 ) : cost( c ), time( t ), marked() {
  185. marked.insert(v);
  186. }
  187. spp_spptw_marked_res_cont& operator=( const spp_spptw_marked_res_cont& other )
  188. {
  189. if( this == &other )
  190. return *this;
  191. this->~spp_spptw_marked_res_cont();
  192. new( this ) spp_spptw_marked_res_cont( other );
  193. return *this;
  194. }
  195. int cost;
  196. int time;
  197. std::set<SPPRC_Example_Graph::vertex_descriptor> marked;
  198. };
  199. bool operator==( const spp_spptw_marked_res_cont& res_cont_1,
  200. const spp_spptw_marked_res_cont& res_cont_2 )
  201. {
  202. return res_cont_1.cost == res_cont_2.cost
  203. && res_cont_1.time == res_cont_2.time
  204. && res_cont_1.marked == res_cont_2.marked;
  205. }
  206. bool operator<( const spp_spptw_marked_res_cont& res_cont_1,
  207. const spp_spptw_marked_res_cont& res_cont_2 )
  208. {
  209. if( res_cont_1.cost > res_cont_2.cost || res_cont_1.time > res_cont_2.time) {
  210. return false;
  211. }
  212. if( !std::includes( res_cont_2.marked.begin(),
  213. res_cont_2.marked.end(),
  214. res_cont_1.marked.begin(),
  215. res_cont_1.marked.end() ) ) {
  216. return false;
  217. }
  218. if( res_cont_1.cost == res_cont_2.cost ) {
  219. return res_cont_1.time < res_cont_2.time;
  220. }
  221. return true;
  222. }
  223. class ref_spptw_marked {
  224. public:
  225. inline bool operator()(const SPPRC_Example_Graph &g,
  226. spp_spptw_marked_res_cont &new_cont,
  227. const spp_spptw_marked_res_cont &old_cont,
  228. graph_traits
  229. <SPPRC_Example_Graph>::edge_descriptor ed) const {
  230. const graph_traits <SPPRC_Example_Graph>::vertex_descriptor dest = target(ed, g);
  231. if(old_cont.marked.find(dest) != old_cont.marked.end()) {
  232. return false;
  233. }
  234. const SPPRC_Example_Graph_Arc_Prop& arc_prop = get( edge_bundle, g )[ed];
  235. const SPPRC_Example_Graph_Vert_Prop& vert_prop = get( vertex_bundle, g )[dest];
  236. new_cont.cost = old_cont.cost + arc_prop.cost;
  237. new_cont.marked = old_cont.marked;
  238. new_cont.marked.insert(dest);
  239. int& i_time = new_cont.time;
  240. i_time = old_cont.time + arc_prop.time;
  241. i_time < vert_prop.eat ? i_time = vert_prop.eat : 0;
  242. return i_time <= vert_prop.lat;
  243. }
  244. };
  245. class dominance_spptw_marked {
  246. public:
  247. inline bool operator()( const spp_spptw_marked_res_cont& res_cont_1,
  248. const spp_spptw_marked_res_cont& res_cont_2 ) const {
  249. return res_cont_1.time <= res_cont_2.time
  250. && res_cont_1.cost <= res_cont_2.cost
  251. && std::includes( res_cont_1.marked.begin(),
  252. res_cont_1.marked.end(),
  253. res_cont_2.marked.begin(),
  254. res_cont_2.marked.end() );
  255. }
  256. };
  257. int test_main(int, char*[])
  258. {
  259. SPPRC_Example_Graph g;
  260. add_vertex( SPPRC_Example_Graph_Vert_Prop( 0, 0, 1000000000 ), g );
  261. add_vertex( SPPRC_Example_Graph_Vert_Prop( 1, 56, 142 ), g );
  262. add_vertex( SPPRC_Example_Graph_Vert_Prop( 2, 0, 1000000000 ), g );
  263. add_vertex( SPPRC_Example_Graph_Vert_Prop( 3, 89, 178 ), g );
  264. add_vertex( SPPRC_Example_Graph_Vert_Prop( 4, 0, 1000000000 ), g );
  265. add_vertex( SPPRC_Example_Graph_Vert_Prop( 5, 49, 76 ), g );
  266. add_vertex( SPPRC_Example_Graph_Vert_Prop( 6, 0, 1000000000 ), g );
  267. add_vertex( SPPRC_Example_Graph_Vert_Prop( 7, 98, 160 ), g );
  268. add_vertex( SPPRC_Example_Graph_Vert_Prop( 8, 0, 1000000000 ), g );
  269. add_vertex( SPPRC_Example_Graph_Vert_Prop( 9, 90, 158 ), g );
  270. add_edge( 0, 7, SPPRC_Example_Graph_Arc_Prop( 6, 33, 2 ), g );
  271. add_edge( 0, 6, SPPRC_Example_Graph_Arc_Prop( 5, 31, 6 ), g );
  272. add_edge( 0, 4, SPPRC_Example_Graph_Arc_Prop( 3, 14, 4 ), g );
  273. add_edge( 0, 1, SPPRC_Example_Graph_Arc_Prop( 0, 43, 8 ), g );
  274. add_edge( 0, 4, SPPRC_Example_Graph_Arc_Prop( 4, 28, 10 ), g );
  275. add_edge( 0, 3, SPPRC_Example_Graph_Arc_Prop( 1, 31, 10 ), g );
  276. add_edge( 0, 3, SPPRC_Example_Graph_Arc_Prop( 2, 1, 7 ), g );
  277. add_edge( 0, 9, SPPRC_Example_Graph_Arc_Prop( 7, 25, 9 ), g );
  278. add_edge( 1, 0, SPPRC_Example_Graph_Arc_Prop( 8, 37, 4 ), g );
  279. add_edge( 1, 6, SPPRC_Example_Graph_Arc_Prop( 9, 7, 3 ), g );
  280. add_edge( 2, 6, SPPRC_Example_Graph_Arc_Prop( 12, 6, 7 ), g );
  281. add_edge( 2, 3, SPPRC_Example_Graph_Arc_Prop( 10, 13, 7 ), g );
  282. add_edge( 2, 3, SPPRC_Example_Graph_Arc_Prop( 11, 49, 9 ), g );
  283. add_edge( 2, 8, SPPRC_Example_Graph_Arc_Prop( 13, 47, 5 ), g );
  284. add_edge( 3, 4, SPPRC_Example_Graph_Arc_Prop( 17, 5, 10 ), g );
  285. add_edge( 3, 1, SPPRC_Example_Graph_Arc_Prop( 15, 47, 1 ), g );
  286. add_edge( 3, 2, SPPRC_Example_Graph_Arc_Prop( 16, 26, 9 ), g );
  287. add_edge( 3, 9, SPPRC_Example_Graph_Arc_Prop( 21, 24, 10 ), g );
  288. add_edge( 3, 7, SPPRC_Example_Graph_Arc_Prop( 20, 50, 10 ), g );
  289. add_edge( 3, 0, SPPRC_Example_Graph_Arc_Prop( 14, 41, 4 ), g );
  290. add_edge( 3, 6, SPPRC_Example_Graph_Arc_Prop( 19, 6, 1 ), g );
  291. add_edge( 3, 4, SPPRC_Example_Graph_Arc_Prop( 18, 8, 1 ), g );
  292. add_edge( 4, 5, SPPRC_Example_Graph_Arc_Prop( 26, 38, 4 ), g );
  293. add_edge( 4, 9, SPPRC_Example_Graph_Arc_Prop( 27, 32, 10 ), g );
  294. add_edge( 4, 3, SPPRC_Example_Graph_Arc_Prop( 24, 40, 3 ), g );
  295. add_edge( 4, 0, SPPRC_Example_Graph_Arc_Prop( 22, 7, 3 ), g );
  296. add_edge( 4, 3, SPPRC_Example_Graph_Arc_Prop( 25, 28, 9 ), g );
  297. add_edge( 4, 2, SPPRC_Example_Graph_Arc_Prop( 23, 39, 6 ), g );
  298. add_edge( 5, 8, SPPRC_Example_Graph_Arc_Prop( 32, 6, 2 ), g );
  299. add_edge( 5, 2, SPPRC_Example_Graph_Arc_Prop( 30, 26, 10 ), g );
  300. add_edge( 5, 0, SPPRC_Example_Graph_Arc_Prop( 28, 38, 9 ), g );
  301. add_edge( 5, 2, SPPRC_Example_Graph_Arc_Prop( 31, 48, 10 ), g );
  302. add_edge( 5, 9, SPPRC_Example_Graph_Arc_Prop( 33, 49, 2 ), g );
  303. add_edge( 5, 1, SPPRC_Example_Graph_Arc_Prop( 29, 22, 7 ), g );
  304. add_edge( 6, 1, SPPRC_Example_Graph_Arc_Prop( 34, 15, 7 ), g );
  305. add_edge( 6, 7, SPPRC_Example_Graph_Arc_Prop( 35, 20, 3 ), g );
  306. add_edge( 7, 9, SPPRC_Example_Graph_Arc_Prop( 40, 1, 3 ), g );
  307. add_edge( 7, 0, SPPRC_Example_Graph_Arc_Prop( 36, 23, 5 ), g );
  308. add_edge( 7, 6, SPPRC_Example_Graph_Arc_Prop( 38, 36, 2 ), g );
  309. add_edge( 7, 6, SPPRC_Example_Graph_Arc_Prop( 39, 18, 10 ), g );
  310. add_edge( 7, 2, SPPRC_Example_Graph_Arc_Prop( 37, 2, 1 ), g );
  311. add_edge( 8, 5, SPPRC_Example_Graph_Arc_Prop( 46, 36, 5 ), g );
  312. add_edge( 8, 1, SPPRC_Example_Graph_Arc_Prop( 42, 13, 10 ), g );
  313. add_edge( 8, 0, SPPRC_Example_Graph_Arc_Prop( 41, 40, 5 ), g );
  314. add_edge( 8, 1, SPPRC_Example_Graph_Arc_Prop( 43, 32, 8 ), g );
  315. add_edge( 8, 6, SPPRC_Example_Graph_Arc_Prop( 47, 25, 1 ), g );
  316. add_edge( 8, 2, SPPRC_Example_Graph_Arc_Prop( 44, 44, 3 ), g );
  317. add_edge( 8, 3, SPPRC_Example_Graph_Arc_Prop( 45, 11, 9 ), g );
  318. add_edge( 9, 0, SPPRC_Example_Graph_Arc_Prop( 48, 41, 5 ), g );
  319. add_edge( 9, 1, SPPRC_Example_Graph_Arc_Prop( 49, 44, 7 ), g );
  320. // spp without resource constraints
  321. std::vector
  322. <std::vector
  323. <graph_traits<SPPRC_Example_Graph>::edge_descriptor> >
  324. opt_solutions;
  325. std::vector<spp_no_rc_res_cont> pareto_opt_rcs_no_rc;
  326. std::vector<int> i_vec_opt_solutions_spp_no_rc;
  327. //std::cout << "r_c_shortest_paths:" << std::endl;
  328. for( int s = 0; s < 10; ++s )
  329. {
  330. for( int t = 0; t < 10; ++t )
  331. {
  332. r_c_shortest_paths
  333. ( g,
  334. get( &SPPRC_Example_Graph_Vert_Prop::num, g ),
  335. get( &SPPRC_Example_Graph_Arc_Prop::num, g ),
  336. s,
  337. t,
  338. opt_solutions,
  339. pareto_opt_rcs_no_rc,
  340. spp_no_rc_res_cont( 0 ),
  341. ref_no_res_cont(),
  342. dominance_no_res_cont(),
  343. std::allocator
  344. <r_c_shortest_paths_label
  345. <SPPRC_Example_Graph, spp_no_rc_res_cont> >(),
  346. default_r_c_shortest_paths_visitor() );
  347. i_vec_opt_solutions_spp_no_rc.push_back( pareto_opt_rcs_no_rc[0].cost );
  348. //std::cout << "From " << s << " to " << t << ": ";
  349. //std::cout << pareto_opt_rcs_no_rc[0].cost << std::endl;
  350. }
  351. }
  352. //std::vector<graph_traits<SPPRC_Example_Graph>::vertex_descriptor>
  353. // p( num_vertices( g ) );
  354. //std::vector<int> d( num_vertices( g ) );
  355. //std::vector<int> i_vec_dijkstra_distances;
  356. //std::cout << "Dijkstra:" << std::endl;
  357. //for( int s = 0; s < 10; ++s )
  358. //{
  359. // dijkstra_shortest_paths( g,
  360. // s,
  361. // &p[0],
  362. // &d[0],
  363. // get( &SPPRC_Example_Graph_Arc_Prop::cost, g ),
  364. // get( &SPPRC_Example_Graph_Vert_Prop::num, g ),
  365. // std::less<int>(),
  366. // closed_plus<int>(),
  367. // (std::numeric_limits<int>::max)(),
  368. // 0,
  369. // default_dijkstra_visitor() );
  370. // for( int t = 0; t < 10; ++t )
  371. // {
  372. // i_vec_dijkstra_distances.push_back( d[t] );
  373. // std::cout << "From " << s << " to " << t << ": " << d[t] << std::endl;
  374. // }
  375. //}
  376. std::vector<int> i_vec_correct_solutions;
  377. i_vec_correct_solutions.push_back( 0 );
  378. i_vec_correct_solutions.push_back( 22 );
  379. i_vec_correct_solutions.push_back( 27 );
  380. i_vec_correct_solutions.push_back( 1 );
  381. i_vec_correct_solutions.push_back( 6 );
  382. i_vec_correct_solutions.push_back( 44 );
  383. i_vec_correct_solutions.push_back( 7 );
  384. i_vec_correct_solutions.push_back( 27 );
  385. i_vec_correct_solutions.push_back( 50 );
  386. i_vec_correct_solutions.push_back( 25 );
  387. i_vec_correct_solutions.push_back( 37 );
  388. i_vec_correct_solutions.push_back( 0 );
  389. i_vec_correct_solutions.push_back( 29 );
  390. i_vec_correct_solutions.push_back( 38 );
  391. i_vec_correct_solutions.push_back( 43 );
  392. i_vec_correct_solutions.push_back( 81 );
  393. i_vec_correct_solutions.push_back( 7 );
  394. i_vec_correct_solutions.push_back( 27 );
  395. i_vec_correct_solutions.push_back( 76 );
  396. i_vec_correct_solutions.push_back( 28 );
  397. i_vec_correct_solutions.push_back( 25 );
  398. i_vec_correct_solutions.push_back( 21 );
  399. i_vec_correct_solutions.push_back( 0 );
  400. i_vec_correct_solutions.push_back( 13 );
  401. i_vec_correct_solutions.push_back( 18 );
  402. i_vec_correct_solutions.push_back( 56 );
  403. i_vec_correct_solutions.push_back( 6 );
  404. i_vec_correct_solutions.push_back( 26 );
  405. i_vec_correct_solutions.push_back( 47 );
  406. i_vec_correct_solutions.push_back( 27 );
  407. i_vec_correct_solutions.push_back( 12 );
  408. i_vec_correct_solutions.push_back( 21 );
  409. i_vec_correct_solutions.push_back( 26 );
  410. i_vec_correct_solutions.push_back( 0 );
  411. i_vec_correct_solutions.push_back( 5 );
  412. i_vec_correct_solutions.push_back( 43 );
  413. i_vec_correct_solutions.push_back( 6 );
  414. i_vec_correct_solutions.push_back( 26 );
  415. i_vec_correct_solutions.push_back( 49 );
  416. i_vec_correct_solutions.push_back( 24 );
  417. i_vec_correct_solutions.push_back( 7 );
  418. i_vec_correct_solutions.push_back( 29 );
  419. i_vec_correct_solutions.push_back( 34 );
  420. i_vec_correct_solutions.push_back( 8 );
  421. i_vec_correct_solutions.push_back( 0 );
  422. i_vec_correct_solutions.push_back( 38 );
  423. i_vec_correct_solutions.push_back( 14 );
  424. i_vec_correct_solutions.push_back( 34 );
  425. i_vec_correct_solutions.push_back( 44 );
  426. i_vec_correct_solutions.push_back( 32 );
  427. i_vec_correct_solutions.push_back( 29 );
  428. i_vec_correct_solutions.push_back( 19 );
  429. i_vec_correct_solutions.push_back( 26 );
  430. i_vec_correct_solutions.push_back( 17 );
  431. i_vec_correct_solutions.push_back( 22 );
  432. i_vec_correct_solutions.push_back( 0 );
  433. i_vec_correct_solutions.push_back( 23 );
  434. i_vec_correct_solutions.push_back( 43 );
  435. i_vec_correct_solutions.push_back( 6 );
  436. i_vec_correct_solutions.push_back( 41 );
  437. i_vec_correct_solutions.push_back( 43 );
  438. i_vec_correct_solutions.push_back( 15 );
  439. i_vec_correct_solutions.push_back( 22 );
  440. i_vec_correct_solutions.push_back( 35 );
  441. i_vec_correct_solutions.push_back( 40 );
  442. i_vec_correct_solutions.push_back( 78 );
  443. i_vec_correct_solutions.push_back( 0 );
  444. i_vec_correct_solutions.push_back( 20 );
  445. i_vec_correct_solutions.push_back( 69 );
  446. i_vec_correct_solutions.push_back( 21 );
  447. i_vec_correct_solutions.push_back( 23 );
  448. i_vec_correct_solutions.push_back( 23 );
  449. i_vec_correct_solutions.push_back( 2 );
  450. i_vec_correct_solutions.push_back( 15 );
  451. i_vec_correct_solutions.push_back( 20 );
  452. i_vec_correct_solutions.push_back( 58 );
  453. i_vec_correct_solutions.push_back( 8 );
  454. i_vec_correct_solutions.push_back( 0 );
  455. i_vec_correct_solutions.push_back( 49 );
  456. i_vec_correct_solutions.push_back( 1 );
  457. i_vec_correct_solutions.push_back( 23 );
  458. i_vec_correct_solutions.push_back( 13 );
  459. i_vec_correct_solutions.push_back( 37 );
  460. i_vec_correct_solutions.push_back( 11 );
  461. i_vec_correct_solutions.push_back( 16 );
  462. i_vec_correct_solutions.push_back( 36 );
  463. i_vec_correct_solutions.push_back( 17 );
  464. i_vec_correct_solutions.push_back( 37 );
  465. i_vec_correct_solutions.push_back( 0 );
  466. i_vec_correct_solutions.push_back( 35 );
  467. i_vec_correct_solutions.push_back( 41 );
  468. i_vec_correct_solutions.push_back( 44 );
  469. i_vec_correct_solutions.push_back( 68 );
  470. i_vec_correct_solutions.push_back( 42 );
  471. i_vec_correct_solutions.push_back( 47 );
  472. i_vec_correct_solutions.push_back( 85 );
  473. i_vec_correct_solutions.push_back( 48 );
  474. i_vec_correct_solutions.push_back( 68 );
  475. i_vec_correct_solutions.push_back( 91 );
  476. i_vec_correct_solutions.push_back( 0 );
  477. BOOST_CHECK(i_vec_opt_solutions_spp_no_rc.size() == i_vec_correct_solutions.size() );
  478. for( int i = 0; i < static_cast<int>( i_vec_correct_solutions.size() ); ++i )
  479. BOOST_CHECK( i_vec_opt_solutions_spp_no_rc[i] == i_vec_correct_solutions[i] );
  480. // spptw
  481. std::vector
  482. <std::vector
  483. <graph_traits<SPPRC_Example_Graph>::edge_descriptor> >
  484. opt_solutions_spptw;
  485. std::vector<spp_spptw_res_cont> pareto_opt_rcs_spptw;
  486. std::vector
  487. <std::vector
  488. <std::vector
  489. <std::vector
  490. <graph_traits<SPPRC_Example_Graph>::edge_descriptor> > > >
  491. vec_vec_vec_vec_opt_solutions_spptw( 10 );
  492. for( int s = 0; s < 10; ++s )
  493. {
  494. for( int t = 0; t < 10; ++t )
  495. {
  496. r_c_shortest_paths
  497. ( g,
  498. get( &SPPRC_Example_Graph_Vert_Prop::num, g ),
  499. get( &SPPRC_Example_Graph_Arc_Prop::num, g ),
  500. s,
  501. t,
  502. opt_solutions_spptw,
  503. pareto_opt_rcs_spptw,
  504. // be careful, do not simply take 0 as initial value for time
  505. spp_spptw_res_cont( 0, g[s].eat ),
  506. ref_spptw(),
  507. dominance_spptw(),
  508. std::allocator
  509. <r_c_shortest_paths_label
  510. <SPPRC_Example_Graph, spp_spptw_res_cont> >(),
  511. default_r_c_shortest_paths_visitor() );
  512. vec_vec_vec_vec_opt_solutions_spptw[s].push_back( opt_solutions_spptw );
  513. if( opt_solutions_spptw.size() )
  514. {
  515. bool b_is_a_path_at_all = false;
  516. bool b_feasible = false;
  517. bool b_correctly_extended = false;
  518. spp_spptw_res_cont actual_final_resource_levels( 0, 0 );
  519. graph_traits<SPPRC_Example_Graph>::edge_descriptor ed_last_extended_arc;
  520. check_r_c_path( g,
  521. opt_solutions_spptw[0],
  522. spp_spptw_res_cont( 0, g[s].eat ),
  523. true,
  524. pareto_opt_rcs_spptw[0],
  525. actual_final_resource_levels,
  526. ref_spptw(),
  527. b_is_a_path_at_all,
  528. b_feasible,
  529. b_correctly_extended,
  530. ed_last_extended_arc );
  531. BOOST_CHECK(b_is_a_path_at_all && b_feasible && b_correctly_extended);
  532. b_is_a_path_at_all = false;
  533. b_feasible = false;
  534. b_correctly_extended = false;
  535. spp_spptw_res_cont actual_final_resource_levels2( 0, 0 );
  536. graph_traits<SPPRC_Example_Graph>::edge_descriptor ed_last_extended_arc2;
  537. check_r_c_path( g,
  538. opt_solutions_spptw[0],
  539. spp_spptw_res_cont( 0, g[s].eat ),
  540. false,
  541. pareto_opt_rcs_spptw[0],
  542. actual_final_resource_levels2,
  543. ref_spptw(),
  544. b_is_a_path_at_all,
  545. b_feasible,
  546. b_correctly_extended,
  547. ed_last_extended_arc2 );
  548. BOOST_CHECK(b_is_a_path_at_all && b_feasible && b_correctly_extended);
  549. }
  550. }
  551. }
  552. std::vector<int> i_vec_correct_num_solutions_spptw;
  553. i_vec_correct_num_solutions_spptw.push_back( 1 );
  554. i_vec_correct_num_solutions_spptw.push_back( 2 );
  555. i_vec_correct_num_solutions_spptw.push_back( 3 );
  556. i_vec_correct_num_solutions_spptw.push_back( 1 );
  557. i_vec_correct_num_solutions_spptw.push_back( 3 );
  558. i_vec_correct_num_solutions_spptw.push_back( 1 );
  559. i_vec_correct_num_solutions_spptw.push_back( 2 );
  560. i_vec_correct_num_solutions_spptw.push_back( 1 );
  561. i_vec_correct_num_solutions_spptw.push_back( 2 );
  562. i_vec_correct_num_solutions_spptw.push_back( 1 );
  563. i_vec_correct_num_solutions_spptw.push_back( 1 );
  564. i_vec_correct_num_solutions_spptw.push_back( 1 );
  565. i_vec_correct_num_solutions_spptw.push_back( 4 );
  566. i_vec_correct_num_solutions_spptw.push_back( 1 );
  567. i_vec_correct_num_solutions_spptw.push_back( 3 );
  568. i_vec_correct_num_solutions_spptw.push_back( 1 );
  569. i_vec_correct_num_solutions_spptw.push_back( 1 );
  570. i_vec_correct_num_solutions_spptw.push_back( 1 );
  571. i_vec_correct_num_solutions_spptw.push_back( 2 );
  572. i_vec_correct_num_solutions_spptw.push_back( 2 );
  573. i_vec_correct_num_solutions_spptw.push_back( 4 );
  574. i_vec_correct_num_solutions_spptw.push_back( 1 );
  575. i_vec_correct_num_solutions_spptw.push_back( 1 );
  576. i_vec_correct_num_solutions_spptw.push_back( 1 );
  577. i_vec_correct_num_solutions_spptw.push_back( 4 );
  578. i_vec_correct_num_solutions_spptw.push_back( 1 );
  579. i_vec_correct_num_solutions_spptw.push_back( 2 );
  580. i_vec_correct_num_solutions_spptw.push_back( 1 );
  581. i_vec_correct_num_solutions_spptw.push_back( 1 );
  582. i_vec_correct_num_solutions_spptw.push_back( 3 );
  583. i_vec_correct_num_solutions_spptw.push_back( 2 );
  584. i_vec_correct_num_solutions_spptw.push_back( 2 );
  585. i_vec_correct_num_solutions_spptw.push_back( 2 );
  586. i_vec_correct_num_solutions_spptw.push_back( 1 );
  587. i_vec_correct_num_solutions_spptw.push_back( 2 );
  588. i_vec_correct_num_solutions_spptw.push_back( 0 );
  589. i_vec_correct_num_solutions_spptw.push_back( 1 );
  590. i_vec_correct_num_solutions_spptw.push_back( 1 );
  591. i_vec_correct_num_solutions_spptw.push_back( 2 );
  592. i_vec_correct_num_solutions_spptw.push_back( 1 );
  593. i_vec_correct_num_solutions_spptw.push_back( 1 );
  594. i_vec_correct_num_solutions_spptw.push_back( 2 );
  595. i_vec_correct_num_solutions_spptw.push_back( 2 );
  596. i_vec_correct_num_solutions_spptw.push_back( 1 );
  597. i_vec_correct_num_solutions_spptw.push_back( 1 );
  598. i_vec_correct_num_solutions_spptw.push_back( 1 );
  599. i_vec_correct_num_solutions_spptw.push_back( 2 );
  600. i_vec_correct_num_solutions_spptw.push_back( 1 );
  601. i_vec_correct_num_solutions_spptw.push_back( 2 );
  602. i_vec_correct_num_solutions_spptw.push_back( 1 );
  603. i_vec_correct_num_solutions_spptw.push_back( 4 );
  604. i_vec_correct_num_solutions_spptw.push_back( 2 );
  605. i_vec_correct_num_solutions_spptw.push_back( 2 );
  606. i_vec_correct_num_solutions_spptw.push_back( 1 );
  607. i_vec_correct_num_solutions_spptw.push_back( 4 );
  608. i_vec_correct_num_solutions_spptw.push_back( 1 );
  609. i_vec_correct_num_solutions_spptw.push_back( 4 );
  610. i_vec_correct_num_solutions_spptw.push_back( 1 );
  611. i_vec_correct_num_solutions_spptw.push_back( 1 );
  612. i_vec_correct_num_solutions_spptw.push_back( 2 );
  613. i_vec_correct_num_solutions_spptw.push_back( 2 );
  614. i_vec_correct_num_solutions_spptw.push_back( 1 );
  615. i_vec_correct_num_solutions_spptw.push_back( 4 );
  616. i_vec_correct_num_solutions_spptw.push_back( 2 );
  617. i_vec_correct_num_solutions_spptw.push_back( 5 );
  618. i_vec_correct_num_solutions_spptw.push_back( 1 );
  619. i_vec_correct_num_solutions_spptw.push_back( 1 );
  620. i_vec_correct_num_solutions_spptw.push_back( 1 );
  621. i_vec_correct_num_solutions_spptw.push_back( 2 );
  622. i_vec_correct_num_solutions_spptw.push_back( 2 );
  623. i_vec_correct_num_solutions_spptw.push_back( 1 );
  624. i_vec_correct_num_solutions_spptw.push_back( 3 );
  625. i_vec_correct_num_solutions_spptw.push_back( 1 );
  626. i_vec_correct_num_solutions_spptw.push_back( 1 );
  627. i_vec_correct_num_solutions_spptw.push_back( 2 );
  628. i_vec_correct_num_solutions_spptw.push_back( 0 );
  629. i_vec_correct_num_solutions_spptw.push_back( 2 );
  630. i_vec_correct_num_solutions_spptw.push_back( 1 );
  631. i_vec_correct_num_solutions_spptw.push_back( 1 );
  632. i_vec_correct_num_solutions_spptw.push_back( 1 );
  633. i_vec_correct_num_solutions_spptw.push_back( 3 );
  634. i_vec_correct_num_solutions_spptw.push_back( 1 );
  635. i_vec_correct_num_solutions_spptw.push_back( 2 );
  636. i_vec_correct_num_solutions_spptw.push_back( 1 );
  637. i_vec_correct_num_solutions_spptw.push_back( 3 );
  638. i_vec_correct_num_solutions_spptw.push_back( 1 );
  639. i_vec_correct_num_solutions_spptw.push_back( 3 );
  640. i_vec_correct_num_solutions_spptw.push_back( 1 );
  641. i_vec_correct_num_solutions_spptw.push_back( 1 );
  642. i_vec_correct_num_solutions_spptw.push_back( 2 );
  643. i_vec_correct_num_solutions_spptw.push_back( 1 );
  644. i_vec_correct_num_solutions_spptw.push_back( 1 );
  645. i_vec_correct_num_solutions_spptw.push_back( 4 );
  646. i_vec_correct_num_solutions_spptw.push_back( 1 );
  647. i_vec_correct_num_solutions_spptw.push_back( 3 );
  648. i_vec_correct_num_solutions_spptw.push_back( 0 );
  649. i_vec_correct_num_solutions_spptw.push_back( 2 );
  650. i_vec_correct_num_solutions_spptw.push_back( 3 );
  651. i_vec_correct_num_solutions_spptw.push_back( 4 );
  652. i_vec_correct_num_solutions_spptw.push_back( 1 );
  653. for( int s = 0; s < 10; ++s )
  654. for( int t = 0; t < 10; ++t )
  655. BOOST_CHECK( static_cast<int>
  656. ( vec_vec_vec_vec_opt_solutions_spptw[s][t].size() ) ==
  657. i_vec_correct_num_solutions_spptw[10 * s + t] );
  658. // one pareto-optimal solution
  659. SPPRC_Example_Graph g2;
  660. add_vertex( SPPRC_Example_Graph_Vert_Prop( 0, 0, 1000000000 ), g2 );
  661. add_vertex( SPPRC_Example_Graph_Vert_Prop( 1, 0, 1000000000 ), g2 );
  662. add_vertex( SPPRC_Example_Graph_Vert_Prop( 2, 0, 1000000000 ), g2 );
  663. add_vertex( SPPRC_Example_Graph_Vert_Prop( 3, 0, 1000000000 ), g2 );
  664. add_edge( 0, 1, SPPRC_Example_Graph_Arc_Prop( 0, 1, 1 ), g2 );
  665. add_edge( 0, 2, SPPRC_Example_Graph_Arc_Prop( 1, 2, 1 ), g2 );
  666. add_edge( 1, 3, SPPRC_Example_Graph_Arc_Prop( 2, 3, 1 ), g2 );
  667. add_edge( 2, 3, SPPRC_Example_Graph_Arc_Prop( 3, 1, 1 ), g2 );
  668. std::vector<graph_traits<SPPRC_Example_Graph>::edge_descriptor> opt_solution;
  669. spp_spptw_res_cont pareto_opt_rc;
  670. r_c_shortest_paths( g2,
  671. get( &SPPRC_Example_Graph_Vert_Prop::num, g2 ),
  672. get( &SPPRC_Example_Graph_Arc_Prop::num, g2 ),
  673. 0,
  674. 3,
  675. opt_solution,
  676. pareto_opt_rc,
  677. spp_spptw_res_cont( 0, 0 ),
  678. ref_spptw(),
  679. dominance_spptw(),
  680. std::allocator
  681. <r_c_shortest_paths_label
  682. <SPPRC_Example_Graph, spp_spptw_res_cont> >(),
  683. default_r_c_shortest_paths_visitor() );
  684. BOOST_CHECK(pareto_opt_rc.cost == 3);
  685. SPPRC_Example_Graph g3;
  686. add_vertex( SPPRC_Example_Graph_Vert_Prop( 0, 0, 1000 ), g3 );
  687. add_vertex( SPPRC_Example_Graph_Vert_Prop( 1, 0, 1000 ), g3 );
  688. add_vertex( SPPRC_Example_Graph_Vert_Prop( 2, 0, 974 ), g3 );
  689. add_vertex( SPPRC_Example_Graph_Vert_Prop( 3, 0, 972 ), g3 );
  690. add_vertex( SPPRC_Example_Graph_Vert_Prop( 4, 0, 967 ), g3 );
  691. add_vertex( SPPRC_Example_Graph_Vert_Prop( 5, 678, 801 ), g3 );
  692. add_edge( 0, 2, SPPRC_Example_Graph_Arc_Prop( 0, 0, 16 ), g3 );
  693. add_edge( 0, 3, SPPRC_Example_Graph_Arc_Prop( 1, 0, 18 ), g3 );
  694. add_edge( 0, 4, SPPRC_Example_Graph_Arc_Prop( 2, 0, 23 ), g3 );
  695. add_edge( 0, 5, SPPRC_Example_Graph_Arc_Prop( 3, 0, 25 ), g3 );
  696. add_edge( 2, 3, SPPRC_Example_Graph_Arc_Prop( 4, 0, 33 ), g3 );
  697. add_edge( 2, 4, SPPRC_Example_Graph_Arc_Prop( 5, 0, 15 ), g3 );
  698. add_edge( 2, 5, SPPRC_Example_Graph_Arc_Prop( 6, 0, 33 ), g3 );
  699. add_edge( 2, 1, SPPRC_Example_Graph_Arc_Prop( 7, 0, 16 ), g3 );
  700. add_edge( 3, 2, SPPRC_Example_Graph_Arc_Prop( 8, 0, 33 ), g3 );
  701. add_edge( 3, 4, SPPRC_Example_Graph_Arc_Prop( 9, 0, 35 ), g3 );
  702. add_edge( 3, 5, SPPRC_Example_Graph_Arc_Prop( 10, 0, 21 ), g3 );
  703. add_edge( 3, 1, SPPRC_Example_Graph_Arc_Prop( 11, 0, 18 ), g3 );
  704. add_edge( 4, 2, SPPRC_Example_Graph_Arc_Prop( 12, 0, 15 ), g3 );
  705. add_edge( 4, 3, SPPRC_Example_Graph_Arc_Prop( 13, 0, 35 ), g3 );
  706. add_edge( 4, 5, SPPRC_Example_Graph_Arc_Prop( 14, 0, 25 ), g3 );
  707. add_edge( 4, 1, SPPRC_Example_Graph_Arc_Prop( 15, 0, 23 ), g3 );
  708. add_edge( 5, 2, SPPRC_Example_Graph_Arc_Prop( 16, 0, 33 ), g3 );
  709. add_edge( 5, 3, SPPRC_Example_Graph_Arc_Prop( 17, 0, 21 ), g3 );
  710. add_edge( 5, 4, SPPRC_Example_Graph_Arc_Prop( 18, 0, 25 ), g3 );
  711. add_edge( 5, 1, SPPRC_Example_Graph_Arc_Prop( 19, 0, 25 ), g3 );
  712. std::vector<std::vector<graph_traits<SPPRC_Example_Graph>::edge_descriptor> >
  713. pareto_opt_marked_solutions;
  714. std::vector<spp_spptw_marked_res_cont> pareto_opt_marked_resource_containers;
  715. graph_traits<SPPRC_Example_Graph>::vertex_descriptor g3_source = 0, g3_target = 1;
  716. r_c_shortest_paths( g3,
  717. get( &SPPRC_Example_Graph_Vert_Prop::num, g3 ),
  718. get( &SPPRC_Example_Graph_Arc_Prop::num, g3 ),
  719. g3_source,
  720. g3_target,
  721. pareto_opt_marked_solutions,
  722. pareto_opt_marked_resource_containers,
  723. spp_spptw_marked_res_cont( 0, 0, 0 ),
  724. ref_spptw_marked(),
  725. dominance_spptw_marked(),
  726. std::allocator
  727. <r_c_shortest_paths_label
  728. <SPPRC_Example_Graph, spp_spptw_marked_res_cont> >(),
  729. default_r_c_shortest_paths_visitor() );
  730. BOOST_CHECK(!pareto_opt_marked_solutions.empty());
  731. std::vector<std::vector<graph_traits<SPPRC_Example_Graph>::edge_descriptor> >::const_iterator path_it, path_end_it;
  732. for (path_it = pareto_opt_marked_solutions.begin(), path_end_it = pareto_opt_marked_solutions.end(); path_it != path_end_it; ++path_it) {
  733. const std::vector<graph_traits<SPPRC_Example_Graph>::edge_descriptor> &path = *path_it;
  734. BOOST_CHECK(!path.empty());
  735. const graph_traits<SPPRC_Example_Graph>::edge_descriptor front = path.front();
  736. BOOST_CHECK(boost::target(front, g3) == g3_target);
  737. std::vector<graph_traits<SPPRC_Example_Graph>::edge_descriptor>::const_iterator edge_it, edge_it_end;
  738. graph_traits<SPPRC_Example_Graph>::edge_descriptor prev_edge = front;
  739. for(edge_it = path.begin() + 1, edge_it_end = path.end(); edge_it != edge_it_end; ++edge_it) {
  740. graph_traits<SPPRC_Example_Graph>::edge_descriptor edge = *edge_it;
  741. graph_traits<SPPRC_Example_Graph>::vertex_descriptor prev_end, current_end;
  742. prev_end = boost::source(prev_edge, g3);
  743. current_end = boost::target(edge, g3);
  744. BOOST_CHECK(prev_end == current_end);
  745. prev_edge = edge;
  746. }
  747. const graph_traits<SPPRC_Example_Graph>::edge_descriptor back = path.back();
  748. BOOST_CHECK(boost::source(back, g3) == g3_source);
  749. }
  750. return 0;
  751. }