99#pragma warning(disable : 4267)
1010#endif
1111
12+ #include < map>
1213#include < boost/graph/adjacency_list.hpp>
1314
1415#include < boost/graph/r_c_shortest_paths.hpp>
@@ -48,7 +49,7 @@ struct edge_t
4849typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, vertex_t , edge_t > graph_t ;
4950typedef boost::graph_traits<graph_t >::vertex_descriptor vertex_desc;
5051typedef boost::graph_traits<graph_t >::edge_descriptor edge_desc;
51- typedef std::unordered_map <size_t , std::unordered_map <size_t , vertex_desc> > vertex_map_t ;
52+ typedef std::map <size_t , std::map <size_t , vertex_desc> > vertex_map_t ;
5253
5354// /
5455// / @brief Function creating the vertices.
@@ -112,7 +113,8 @@ void create_edges(const vertex_map_t &vertex_map, graph_t &g)
112113 cur_edge.id = index_l++;
113114 vertex_desc v1 = map_get (j-1 ,map_get (i, vertex_map));
114115 vertex_desc v2 = map_get (j,map_get (i, vertex_map));
115- cur_edge.extremities = {g[v1], g[v2]};
116+ cur_edge.extremities .push_back (g[v1]);
117+ cur_edge.extremities .push_back (g[v2]);
116118 add_edge (v1, v2, cur_edge, g);
117119 }
118120 // If not on first column we link every vertex
@@ -123,7 +125,8 @@ void create_edges(const vertex_map_t &vertex_map, graph_t &g)
123125 cur_edge.id = index_l++;
124126 vertex_desc v1 = map_get (j,map_get (i-1 , vertex_map));
125127 vertex_desc v2 = map_get (j,map_get (i, vertex_map));
126- cur_edge.extremities = {g[v1], g[v2]};
128+ cur_edge.extremities .push_back (g[v1]);
129+ cur_edge.extremities .push_back (g[v2]);
127130 add_edge (v1, v2, cur_edge, g);
128131 }
129132 }
@@ -134,12 +137,12 @@ void create_edges(const vertex_map_t &vertex_map, graph_t &g)
134137// / @brief A simple label wtih movement required and exposition (plus the current vertex)
135138// /
136139struct Label {
137- Label () {}
140+ Label () : v(), id( 0 ), movedReq( 0 ), expo( 0 .) {}
138141
139142 vertex_t v;
140143 size_t id;
141- size_t movedReq = 0 ;
142- double expo = 0 . ;
144+ size_t movedReq;
145+ double expo;
143146
144147 // Required for r_c_shortest_paths
145148 bool operator <(Label const & other_p ) const
@@ -224,7 +227,7 @@ std::ostream &operator<<(std::ostream &os_p, Path const &path_p)
224227 os_p << " Path[target = " <<path_p.label .v .name <<" , path={" ;
225228 std::string lastId_l = path_p.label .v .name ;
226229 os_p << " \" " <<lastId_l<< " \" " ;
227- for (edge_t const &e_l : path_p.edges )
230+ BOOST_FOREACH (edge_t const &e_l, path_p.edges )
228231 {
229232 os_p<<" , " ;
230233 // If extremities[0] is last vertex walked on then use extremities[1]
@@ -277,10 +280,10 @@ std::vector<Path> getAllPathsToN(std::vector<std::vector<size_t> > const &map_p,
277280 for (size_t i = 0 ; i < shortestPaths_l.size () ; ++ i)
278281 {
279282 Path newPath_l;
280- auto path_l = shortestPaths_l[i];
281- auto label_l = bestLabels_l[i];
283+ std::vector< edge_desc > const & path_l = shortestPaths_l[i];
284+ Label const & label_l = bestLabels_l[i];
282285 newPath_l.label = label_l;
283- for ( auto edge_desc_l : path_l)
286+ BOOST_FOREACH (edge_desc const & edge_desc_l, path_l)
284287 {
285288 newPath_l.edges .push_back (g[edge_desc_l]);
286289 }
@@ -293,29 +296,26 @@ std::vector<Path> getAllPathsToN(std::vector<std::vector<size_t> > const &map_p,
293296// / @brief construct the string representation of a handmade path
294297// / based on the operator<< of Path
295298// / used to compare handmade path with real Path
296- std::string buildString (std::vector<std::string> const &path_p, size_t moveReq_p, double expo_p, bool reverse_p )
299+ std::string buildString (std::vector<std::string> const &path_p, size_t moveReq_p, double expo_p)
297300{
298301 if (path_p.empty ())
299302 {
300303 return std::string ();
301304 }
302305 std::stringstream ss_l;
303306 // Get correct iterator based on reverse
304- std::string firstId_l = reverse_p ? *path_p. rbegin () : * path_p.begin ();
307+ std::string firstId_l = * path_p.begin ();
305308 ss_l << " Path[target = " <<firstId_l<<" , path={" ;
306309 ss_l << " \" " << firstId_l<<" \" " ;
307- if (reverse_p)
310+ bool first_l = true ;
311+ BOOST_FOREACH (std::string const &str_l, path_p)
308312 {
309- std::for_each (++path_p. rbegin (), path_p. rend (), [&](std::string const str_p )
313+ if (first_l )
310314 {
311- ss_l<<" , \" " <<str_p<<" \" " ;
312- });
313- } else
314- {
315- std::for_each (++path_p.begin (), path_p.end (), [&](std::string const str_p)
316- {
317- ss_l<<" , \" " <<str_p<<" \" " ;
318- });
315+ first_l = false ;
316+ continue ;
317+ }
318+ ss_l<<" , \" " <<str_l<<" \" " ;
319319 }
320320 ss_l<<" }" ;
321321 ss_l<<" , movedReq = " <<moveReq_p;
@@ -337,8 +337,8 @@ struct manual_path
337337// / @brief test that the given path exists in the solution
338338bool testPathExistence (std::vector<Path> const &paths_p, manual_path const &manual_path_p, size_t moveReq_p, double expo_p)
339339{
340- std::string refStringOneWay_l = buildString (manual_path_p.internal_path , moveReq_p, expo_p, false );
341- for (Path const &path_l : paths_p)
340+ std::string refStringOneWay_l = buildString (manual_path_p.internal_path , moveReq_p, expo_p);
341+ BOOST_FOREACH (Path const &path_l, paths_p)
342342 {
343343 if (boost::lexical_cast<std::string, Path>(path_l) == refStringOneWay_l)
344344 {
@@ -400,7 +400,7 @@ void test_shortest_paths_to_all_no_move_allowed()
400400 map_l % (manual_row () % 1 % 0 % 1 % 0 % 1 );
401401 map_l % (manual_row () % 1 % 1 % 1 % 0 % 1 );
402402
403- std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , { 2 ,0 } , 0 );
403+ std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , std::make_pair< size_t , size_t >( 2 ,0 ) , 0 );
404404
405405 // Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
406406 BOOST_TEST (testPathExistence (vectPath_l, manual_path () % " 1,1" % " 2,1" % " 2,0" , 0 , 2 ));
@@ -432,7 +432,7 @@ void test_shortest_paths_to_all_one_move_allowed()
432432 map_l % (manual_row () % 1 % 1 % 1 % 0 % 1 );
433433 map_l % (manual_row () % 0 % 0 % 1 % 0 % 1 );
434434
435- std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , { 2 ,0 } , 1 );
435+ std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , std::make_pair< size_t , size_t >( 2 ,0 ) , 1 );
436436
437437 // Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
438438 BOOST_TEST (testPathExistence (vectPath_l, manual_path () % " 1,0" % " 2,0" , 1 , 1 ));
@@ -460,7 +460,7 @@ void test_shortest_paths_to_all_multiple_paths()
460460 map_l % (manual_row () % 0 % 0 % 1 % 0 % 1 );
461461 map_l % (manual_row () % 0 % 0 % 1 % 0 % 0 );
462462
463- std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , { 2 ,0 } , 0 );
463+ std::vector<Path> vectPath_l = getAllPathsToN (map_l.map , std::make_pair< size_t , size_t >( 2 ,0 ) , 0 );
464464
465465 // Check all paths to all accessible tiles (no move are allowed meaning that all tile with 1 value are forbidden)
466466 BOOST_TEST (testPathExistence (vectPath_l, manual_path () % " 1,0" % " 2,0" , 0 , 1 ));
0 commit comments