27 template <
class Graph,
class WLazyMap>
31 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
32 typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
33 typedef typename boost::graph_traits<Graph>::edge_iterator EdgeIter;
35 typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VerIndexMap;
37 typedef boost::vector_property_map<double,VerIndexMap> VerVector;
38 typedef boost::vector_property_map<double,VerPairIndexMap> VerPairVector;
45 const bool do_fake_roots;
50 VerPairVector coupling_map;
54 WLazyMap w_lazy_map,
double len_ref,
55 Vertex v_start, Vertex v_goal,
57 g(g), w_lazy_map(w_lazy_map), len_ref(len_ref),
58 v_start(v_start), v_goal(v_goal),
59 do_fake_roots(do_fake_roots),
60 temp1(num_vertices(g),
get(boost::vertex_index,g)),
61 temp2(num_vertices(g),
get(boost::vertex_index,g)),
63 num_vertices(g)*num_vertices(g),
66 printf(
"computing partition_all from scratch ...\n");
69 pr_bgl::partition_all_init(g, coupling_map);
71 std::pair<EdgeIter,EdgeIter> ep=edges(g);
72 for (EdgeIter ei=ep.first; ei!=ep.second; ei++)
74 Vertex v_s = source(*ei, g);
75 Vertex v_t = target(*ei, g);
76 double weight_frac =
get(w_lazy_map,*ei) / len_ref;
78 if (!do_fake_roots || (v_t != v_start && v_s != v_goal))
81 partition_all_update_directed_edge(g,
86 coupling_map, temp1, temp2);
89 if (!do_fake_roots || (v_s != v_start && v_t != v_goal))
92 partition_all_update_directed_edge(g,
97 coupling_map, temp1, temp2);
102 void get_to_evaluate(
104 const std::vector< std::pair<Edge,bool> > & path,
105 std::vector<Edge> & to_evaluate)
107 double coupling_withall = coupling_map[std::make_pair(v_start,v_goal)];
110 double score_best = 0.0;
112 bool found_best =
false;
113 for (
unsigned int ui=0; ui<path.size(); ui++)
115 Edge e = path[ui].first;
120 if (do_fake_roots && (ui==0 || ui==path.size()-1))
125 double coupling_without = pr_bgl::partition_all_without_edge(g, v_start, v_goal,
126 e,
get(w_lazy_map,e)/len_ref, coupling_map);
128 score = 1.0 - coupling_without/coupling_withall;
132 if (score_best <= score)
140 throw std::runtime_error(
"no best edge found!");
141 to_evaluate.push_back(e_best);
144 template <
class Edge,
class WeightType>
145 void update_notify(Edge e, WeightType e_weight_old)
148 double e_weight_new =
get(w_lazy_map, e);
149 if (e_weight_new == e_weight_old)
153 Vertex v_s = source(e, g);
154 Vertex v_t = target(e, g);
156 double weight_frac_old = e_weight_old / len_ref;
157 if (!do_fake_roots || (v_t != v_start && v_s != v_goal))
158 partition_all_update_directed_edge(g, v_s, v_t, weight_frac_old,
false, coupling_map, temp1, temp2);
159 if (!do_fake_roots || (v_s != v_start && v_t != v_goal))
160 partition_all_update_directed_edge(g, v_t, v_s, weight_frac_old,
false, coupling_map, temp1, temp2);
162 double weight_frac =
get(w_lazy_map, e) / len_ref;
163 if (!do_fake_roots || (v_t != v_start && v_s != v_goal))
164 partition_all_update_directed_edge(g, v_s, v_t, weight_frac,
true, coupling_map, temp1, temp2);
165 if (!do_fake_roots || (v_s != v_start && v_t != v_goal))
166 partition_all_update_directed_edge(g, v_t, v_s, weight_frac,
true, coupling_map, temp1, temp2);
173 template <
class Graph,
class WLazyMap>
177 typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
178 typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
183 const double len_ref;
184 const Vertex v_start;
186 const bool do_fake_roots;
192 WLazyMap w_lazy_map,
double len_ref,
193 Vertex v_start, Vertex v_goal,
196 g(g), w_lazy_map(w_lazy_map), len_ref(len_ref),
197 v_start(v_start), v_goal(v_goal),
198 do_fake_roots(do_fake_roots),
203 void get_to_evaluate(
205 const std::vector< std::pair<Edge,bool> > & path,
206 std::vector<Edge> & to_evaluate)
208 double coupling_withall = solver.Z(v_start, v_goal);
211 double score_best = 0.0;
213 bool found_best =
false;
214 for (
unsigned int ui=0; ui<path.size(); ui++)
216 Edge e = path[ui].first;
221 if (do_fake_roots && (ui==0 || ui==path.size()-1))
225 double weight_frac =
get(w_lazy_map,e)/len_ref;
226 double coupling_without = solver.without_undirected(
227 v_start, v_goal, source(e,g), target(e,g), weight_frac);
230 score = 1.0 - coupling_without/coupling_withall;
234 if (score_best <= score)
242 throw std::runtime_error(
"no best edge found!");
243 to_evaluate.push_back(e_best);
246 template <
class Edge,
class WeightType>
247 void update_notify(Edge e, WeightType e_weight_old)
250 double e_weight_new =
get(w_lazy_map, e);
251 if (e_weight_new == e_weight_old)
255 Vertex va = source(e, g);
256 Vertex vb = target(e, g);
259 double weight_frac_old = e_weight_old / len_ref;
260 if (!do_fake_roots || (vb != v_start && va != v_goal))
261 solver.remove_edge(va, vb, weight_frac_old);
262 if (!do_fake_roots || (va != v_start && vb != v_goal))
263 solver.remove_edge(vb, va, weight_frac_old);
266 double weight_frac =
get(w_lazy_map, e) / len_ref;
267 if (!do_fake_roots || (vb != v_start && va != v_goal))
268 solver.add_edge(va, vb, weight_frac);
269 if (!do_fake_roots || (va != v_start && vb != v_goal))
270 solver.add_edge(vb, va, weight_frac);
Adaptor to use matrix partition_all functions as a LazySP selector.
Definition: lazysp_selector_partition_all.h:174
Adaptor to use non-matrix partition_all functions as a selector for pr_bgl::lazysp.
Definition: lazysp_selector_partition_all.h:28
Convert a master index to a row-major-order matrix index pair.
Definition: pair_index_map.h:20
Definition: partition_all.h:225