LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
lazysp_incsp_incbi.h
Go to the documentation of this file.
1 
10 namespace pr_bgl
11 {
12 
13 template<class Graph, class EdgeIndexMap>
15 {
16 public:
17  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
18  typedef boost::readable_property_map_tag category;
19  typedef Edge key_type;
20  typedef size_t value_type;
21  typedef size_t reference;
22  Graph & g;
23  EdgeIndexMap edge_index_map;
24  lazysp_incsp_incbi_edge_index_adaptor(Graph & g, EdgeIndexMap edge_index_map):
25  g(g), edge_index_map(edge_index_map)
26  {
27  }
28 };
29 
30 template<class Graph, class EdgeIndexMap>
31 inline const size_t get(
33  const typename boost::graph_traits<Graph>::edge_descriptor & e)
34 {
35  return (get(map.edge_index_map,e) << 1)
36  + ((source(e,map.g)<target(e,map.g)) ? 0 : 1);
37 }
38 
39 
57 template <class Graph, class ActualWMap,
58  class StartPredecessorMap, class StartDistanceMap, class StartDistanceLookaheadMap,
59  class GoalPredecessorMap, class GoalDistanceMap, class GoalDistanceLookaheadMap,
60  class EdgeIndexMap, class EdgeVectorMap,
61  typename CompareFunction, typename CombineFunction,
62  class IncBiVisitor, class IncBiBalancer>
64 {
65 public:
66  typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
67  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
68  typedef typename boost::property_traits<ActualWMap>::value_type weight_type;
69  typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VIndexMap;
70 
71  Graph & g;
72  Vertex v_start;
73  Vertex v_goal;
74  ActualWMap w_map;
75  StartPredecessorMap start_predecessor;
76  StartDistanceMap start_distance;
77  GoalPredecessorMap goal_predecessor;
78  GoalDistanceMap goal_distance;
79  EdgeVectorMap edge_vector_map;
80  weight_type inf;
81 
82  // incbi instance
83  pr_bgl::incbi<Graph,
84  StartPredecessorMap,StartDistanceMap,StartDistanceLookaheadMap,
85  GoalPredecessorMap,GoalDistanceMap,GoalDistanceLookaheadMap,
86  ActualWMap,
87  VIndexMap,
89  //std::less<weight_type>, boost::closed_plus<weight_type>,
90  CompareFunction, CombineFunction,
91  weight_type, weight_type,
92  IncBiVisitor, IncBiBalancer
93  > incbi;
94 
96  Graph & g, Vertex v_start, Vertex v_goal, ActualWMap w_map,
97  StartPredecessorMap start_predecessor,
98  StartDistanceMap start_distance, StartDistanceLookaheadMap start_distance_lookahead,
99  GoalPredecessorMap goal_predecessor,
100  GoalDistanceMap goal_distance, GoalDistanceLookaheadMap goal_distance_lookahead,
101  EdgeIndexMap edge_index_map,
102  EdgeVectorMap edge_vector_map,
103  weight_type goal_margin,
104  CompareFunction compare, CombineFunction combine,
105  weight_type inf, weight_type zero,
106  IncBiVisitor vis, IncBiBalancer balancer):
107  g(g), v_start(v_start), v_goal(v_goal),
108  w_map(w_map),
109  start_predecessor(start_predecessor),
110  start_distance(start_distance),
111  goal_predecessor(goal_predecessor),
112  goal_distance(goal_distance),
113  edge_vector_map(edge_vector_map),
114  inf(inf),
115  incbi(g, v_start, v_goal,
116  start_predecessor, start_distance, start_distance_lookahead,
117  goal_predecessor, goal_distance, goal_distance_lookahead,
118  w_map,
119  get(boost::vertex_index, g), // vertex_index_map
121  //std::less<weight_type>(), // compare
122  //boost::closed_plus<weight_type>(std::numeric_limits<weight_type>::max()), // combine
123  //std::numeric_limits<weight_type>::max(),
124  //weight_type(),
125  compare, combine, inf, zero,
126  goal_margin,
127  vis, balancer)
128  {
129  }
130 
131  template <typename LazySPWMap>
132  weight_type solve(const Graph & g, Vertex v_start, Vertex v_goal,
133  LazySPWMap wmap, std::vector<Edge> & path)
134  {
135  std::pair<size_t,bool> spresult = incbi.compute_shortest_path();
136 
137  // no solution?
138  if (!spresult.second)
139  return inf;
140 
141  // which way does the edge go?
142  size_t eidx_actual = spresult.first >> 1;
143  Edge e = get(edge_vector_map, eidx_actual);
144 
145  Vertex v_startside = source(e, g);
146  Vertex v_goalside = target(e, g);
147  unsigned char goalside_is_lower = (v_goalside < v_startside) ? 1 : 0;
148  unsigned char goalside_shouldbe_lower = spresult.first & 1; // 0 or 1
149 
150  if (goalside_is_lower ^ goalside_shouldbe_lower)
151  {
152  Vertex v_temp = v_startside;
153  v_startside = v_goalside;
154  v_goalside = v_temp;
155  e = edge(target(e,g),source(e,g),g).first;
156  }
157 
158  // get path
159  path.clear();
160  // first, walk from the startside vertex to the start
161  for (Vertex v_walk=v_startside; v_walk!=v_start;)
162  {
163  Vertex v_pred = get(start_predecessor,v_walk);
164  std::pair<Edge,bool> ret = edge(v_pred, v_walk, g);
165  BOOST_ASSERT(ret.second);
166  path.push_back(ret.first);
167  v_walk = v_pred;
168  }
169  std::reverse(path.begin(),path.end());
170  // then add middle edge
171  {
172  std::pair<Edge,bool> ret = edge(v_startside, v_goalside, g);
173  BOOST_ASSERT(ret.second);
174  path.push_back(ret.first);
175  }
176  // then, walk from the goalside vertex to the goal
177  for (Vertex v_walk=v_goalside; v_walk!=v_goal;)
178  {
179  Vertex v_succ = get(goal_predecessor,v_walk);
180  std::pair<Edge,bool> ret = edge(v_walk, v_succ, g);
181  BOOST_ASSERT(ret.second);
182  path.push_back(ret.first);
183  v_walk = v_succ;
184  }
185 
186  return get(start_distance,v_startside) + get(w_map,e) + get(goal_distance,v_goalside);
187  }
188 
189  void update_notify(Edge euv)
190  {
191  Vertex u = source(euv,g);
192  Vertex v = target(euv,g);
193  // update forward edge
194  weight_type wuv = get(w_map,euv);
195  incbi.start_update_predecessor(u, v, wuv);
196  incbi.start_update_vertex(v);
197  incbi.goal_update_successor(u, v, wuv);
198  incbi.goal_update_vertex(u);
199  incbi.update_edge(euv);
200  // update reverse edge
201  Edge evu = edge(v,u,g).first;
202  weight_type wvu = get(w_map,evu);
203  incbi.start_update_predecessor(v, u, wvu);
204  incbi.start_update_vertex(u);
205  incbi.goal_update_successor(v, u, wvu);
206  incbi.goal_update_vertex(v);
207  incbi.update_edge(evu);
208  }
209 };
210 
211 template <class Graph, class ActualWMap,
212  class StartPredecessorMap, class StartDistanceMap, class StartDistanceLookaheadMap,
213  class GoalPredecessorMap, class GoalDistanceMap, class GoalDistanceLookaheadMap,
214  class EdgeIndexMap, class EdgeVectorMap,
215  typename CompareFunction, typename CombineFunction,
216  class IncBiVisitor, class IncBiBalancer>
218 make_lazysp_incsp_incbi(
219  Graph & g,
220  typename boost::graph_traits<Graph>::vertex_descriptor v_start,
221  typename boost::graph_traits<Graph>::vertex_descriptor v_goal,
222  ActualWMap w_map,
223  StartPredecessorMap start_predecessor,
224  StartDistanceMap start_distance, StartDistanceLookaheadMap start_distance_lookahead,
225  GoalPredecessorMap goal_predecessor,
226  GoalDistanceMap goal_distance, GoalDistanceLookaheadMap goal_distance_lookahead,
227  EdgeIndexMap edge_index_map, EdgeVectorMap edge_vector_map,
228  typename boost::property_traits<ActualWMap>::value_type goal_margin,
229  CompareFunction compare, CombineFunction combine,
230  typename boost::property_traits<ActualWMap>::value_type inf,
231  typename boost::property_traits<ActualWMap>::value_type zero,
232  IncBiVisitor vis, IncBiBalancer balancer)
233 {
235  g, v_start, v_goal, w_map, start_predecessor, start_distance, start_distance_lookahead, goal_predecessor, goal_distance, goal_distance_lookahead, edge_index_map, edge_vector_map, goal_margin, compare, combine, inf, zero, vis, balancer);
236 }
237 
238 } // namespace pr_bgl
Definition: lazysp_incsp_incbi.h:14
Adaptor to use pr_bgl::incbi as the inner sp algorithm for pr_bgl::lazysp.
Definition: lazysp_incsp_incbi.h:63
This class implements incremental bidirectional Dijkstra's search for the single-pair shortest path p...
Definition: incbi.h:50