25 template <
class Graph,
class WeightMap>
29 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
30 typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
31 typedef typename boost::graph_traits<Graph>::out_edge_iterator EdgeOutIter;
32 typedef std::pair<double, double> Key;
34 typedef std::pair<double, std::vector<Vertex> > Path;
41 const WeightMap weight_map;
44 std::map<Vertex,double> goaldist;
46 std::vector< Path > paths;
51 Path next_path_buffer;
54 path_generator(
const Graph & g, Vertex v_start, Vertex v_goal, WeightMap weight_map):
55 g(g), v_start(v_start), v_goal(v_goal), weight_map(weight_map)
59 printf(
"running w_est reverse dijstra's ...\n");
60 std::map<Vertex,Vertex> preds;
61 boost::reverse_graph<Graph> rg(g);
62 boost::dijkstra_shortest_paths(
65 boost::make_assoc_property_map(preds),
66 boost::make_assoc_property_map(goaldist),
67 pr_bgl::make_compose_property_map(
70 boost::get(boost::vertex_index, g),
72 boost::closed_plus<double>(std::numeric_limits<double>::max()),
73 std::numeric_limits<double>::max(),
75 boost::make_dijkstra_visitor(boost::null_visitor())
78 paths.push_back(Path(0.0, std::vector<Vertex>(1,v_start)));
79 queue.insert(0, Key(goaldist[v_start],goaldist[v_start]));
81 next_path_buffer = generate_path();
84 bool peek_next_exists()
86 return (0 < next_path_buffer.second.size());
91 return next_path_buffer.first;
96 Path ret = next_path_buffer;
97 next_path_buffer = generate_path();
109 size_t top_idx = queue.top_idx();
111 Path path = paths[top_idx];
113 if (path.second.back() == v_goal)
116 std::pair<EdgeOutIter, EdgeOutIter> out_edges
117 = boost::out_edges(path.second.back(), g);
118 for (; out_edges.first!=out_edges.second; out_edges.first++)
120 Vertex v_successor = boost::target(*out_edges.first, g);
122 for (ui=0; ui<path.second.size(); ui++)
123 if (path.second[ui] == v_successor)
125 if (ui<path.second.size())
128 Path path_new = path;
129 Edge e = *out_edges.first;
130 path_new.first += boost::get(weight_map, e);
131 path_new.second.push_back(v_successor);
132 paths.push_back(path_new);
133 queue.insert(paths.size()-1,
134 Key(path_new.first+goaldist[v_successor],goaldist[v_successor]));
138 return Path(std::numeric_limits<double>::max(), std::vector<Vertex>());
Readable boost property map which maps from reversed edges to original edges.
Definition: rev_edge_map.h:20
Generates all simple paths in non-decreasing order of length.
Definition: path_generator.h:26