LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
partition_simple.h
Go to the documentation of this file.
1 
12 namespace pr_bgl
13 {
14 
15 template <class Graph>
17 {
18  typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
19  typedef typename boost::graph_traits<Graph>::out_edge_iterator EdgeOutIter;
20  Vertex v; // source vertex
21  double len; // total len from start
22  std::pair<EdgeOutIter,EdgeOutIter> es;
23  double score; // total score through this vertex
24  partition_simple_el(Vertex v, double len, std::pair<EdgeOutIter,EdgeOutIter> es):
25  v(v), len(len), es(es), score(0) {}
26 };
27 
40 template <class Graph, class WeightMap, class DistanceMap, class ScoreMap, class IsUsedMap>
41 double partition_simple(
42  const Graph & g,
43  typename boost::graph_traits<Graph>::vertex_descriptor v_start,
44  typename boost::graph_traits<Graph>::vertex_descriptor v_goal,
45  double beta,
46  double len_max,
47  WeightMap weight_map,
48  DistanceMap goal_distance_map,
49  ScoreMap score_map,
50  IsUsedMap is_used_map)
51 {
52  typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
53  typedef typename boost::graph_traits<Graph>::vertex_iterator VertexIter;
54  typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
55  typedef typename boost::graph_traits<Graph>::edge_iterator EdgeIter;
56 
57  // clear edge scores
58  for (std::pair<EdgeIter,EdgeIter> ep=edges(g); ep.first!=ep.second; ep.first++)
59  put(score_map, *ep.first, 0.0);
60 
61  // track total score
62  double score_total = 0.0;
63 
64  // if true, the vertex is used already (the source of an edge in the stack)
65  for (std::pair<VertexIter,VertexIter> vp=vertices(g); vp.first!=vp.second; vp.first++)
66  put(is_used_map, *vp.first, false);
67 
68  put(is_used_map, v_start, true);
69  std::vector< partition_simple_el<Graph> > stack;
70  stack.push_back(partition_simple_el<Graph>(v_start, 0.0, out_edges(v_start, g)));
71 
72  while (stack.size())
73  {
74  // are we done?
75  if (stack.back().es.first == stack.back().es.second)
76  {
77  put(is_used_map, stack.back().v, false);
78  // back-copy score
79  double score_popped = stack.back().score;
80  stack.pop_back();
81  if (stack.size())
82  {
83  put(score_map, *stack.back().es.first,
84  get(score_map, *stack.back().es.first) + score_popped);
85 
86  stack.back().es.first++;
87  stack.back().score += score_popped;
88  }
89  else
90  {
91  score_total = score_popped;
92  }
93  continue;
94  }
95 
96  // ok, the last edge iterator points to a new edge;
97  // look at the vertex at the end
98  Vertex v_next = target(*stack.back().es.first, g);
99 
100  // is this vertex already visited?
101  if (get(is_used_map, v_next))
102  {
103  stack.back().es.first++;
104  continue;
105  }
106  double len = stack.back().len + get(weight_map, *stack.back().es.first);
107 
108  // is the path so far to this target next vertex too long?
109  if (len_max < len + get(goal_distance_map, v_next) )
110  {
111  stack.back().es.first++;
112  continue;
113  }
114 
115  // is this the goal vertex?
116  if (v_next == v_goal)
117  {
118  // compute score for this path
119  double score = exp(-beta*len);
120 
121  stack.back().score += score;
122 
123  // add to last edge
124  put(score_map, *stack.back().es.first,
125  get(score_map, *stack.back().es.first) + score);
126 
127  stack.back().es.first++;
128  continue;
129  }
130 
131  // ok, we reached a new vertex!
132  put(is_used_map, v_next, true);
133  stack.push_back(partition_simple_el<Graph>(v_next, len, out_edges(v_next, g)));
134  }
135 
136  return score_total;
137 }
138 
139 } // namespace pr_bgl
Definition: partition_simple.h:16