LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
lazysp_selector_sp_indicator_probability.h
Go to the documentation of this file.
1 
10 namespace pr_bgl
11 {
12 
21 template <class Graph, class WLazyMap, class IsEvaledMap>
23 {
24 public:
25  typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
26  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
27  typedef typename boost::graph_traits<Graph>::edge_iterator EdgeIter;
28  WLazyMap w_lazy_map;
29  IsEvaledMap is_evaled_map;
30  const int nsamps;
31  const Vertex v_start;
32  const Vertex v_goal;
33  boost::mt19937 rand_gen;
34  boost::uniform_01<> rand_dist;
35  boost::variate_generator<boost::mt19937&, boost::uniform_01<> > rand_var;
36 
37  lazysp_selector_sp_indicator_probability(WLazyMap w_lazy_map, IsEvaledMap is_evaled_map,
38  int nsamps, Vertex v_start, Vertex v_goal, unsigned int seed):
39  w_lazy_map(w_lazy_map), is_evaled_map(is_evaled_map),
40  nsamps(nsamps), v_start(v_start), v_goal(v_goal),
41  rand_gen(seed), rand_var(rand_gen, rand_dist)
42  {
43  }
44 
45  void get_to_evaluate(
46  const Graph & g,
47  const std::vector< std::pair<Edge,bool> > & path,
48  std::vector<Edge> & to_evaluate)
49  {
50  std::map<Edge, int> edge_counts;
51  for (std::pair<EdgeIter,EdgeIter> ep=edges(g); ep.first!=ep.second; ep.first++)
52  edge_counts[*ep.first] = 0;
53 
54  //printf("sampling ...\n");
55  for (int i=0; i<nsamps; i++)
56  {
57  // compute sampled edge weights
58  std::map<Edge, double> w_sampled;
59  for (std::pair<EdgeIter,EdgeIter> ep=edges(g); ep.first!=ep.second; ep.first++)
60  {
61  Edge e = *ep.first;
62  if (get(is_evaled_map,e))
63  w_sampled[e] = get(w_lazy_map,e);
64  else
65  {
66  double randvalue = rand_var();
67  if (0.5 < randvalue) // collides?
68  w_sampled[e] = std::numeric_limits<double>::max();
69  else
70  //w_sampled[e] = get(w_lazy_map,e);
71  w_sampled[e] = 1.0 + randvalue / 0.5;
72  }
73  }
74 
75  // compute shortest path
76  std::map<Vertex,double> wsampled_startdist;
77  std::map<Vertex,Vertex> wsampled_preds;
78  boost::dijkstra_shortest_paths(
79  g,
80  v_start, // source
81  boost::make_assoc_property_map(wsampled_preds),
82  boost::make_assoc_property_map(wsampled_startdist),
83  boost::make_assoc_property_map(w_sampled),
84  boost::get(boost::vertex_index, g),
85  std::less<double>(), // compare
86  boost::closed_plus<double>(std::numeric_limits<double>::max()), // combine
87  std::numeric_limits<double>::max(),
88  double(),
89  boost::make_dijkstra_visitor(boost::null_visitor())
90  );
91 
92  if (wsampled_startdist[v_goal] == std::numeric_limits<double>::max())
93  continue;
94 
95  // add into edge_counts along shortest path
96  Vertex v_cur = v_goal;
97  while (v_cur != v_start)
98  {
99  Vertex v_prev = wsampled_preds[v_cur];
100  Edge e = boost::edge(v_prev, v_cur, g).first;
101  edge_counts[e]++;
102  v_cur = v_prev;
103  }
104  }
105 
106  int count_best = 0;
107  Edge e_best;
108  for (unsigned int ui=0; ui<path.size(); ui++)
109  {
110  Edge e = path[ui].first;
111  if (path[ui].second)
112  continue;
113  if (count_best <= edge_counts[e])
114  {
115  e_best = e;
116  count_best = edge_counts[e];
117  }
118  }
119  to_evaluate.push_back(e_best);
120  }
121 
122  template <class Edge, class WeightType>
123  void update_notify(Edge e, WeightType e_weight_old) {}
124 };
125 
126 } // namespace pr_bgl
Shortest-path indicator probability selector for pr_bgl::lazysp.
Definition: lazysp_selector_sp_indicator_probability.h:22