Changeset 72
- Timestamp:
- 12/10/07 14:11:15 (1 year ago)
- Files:
-
- trunk/core/src/shooting_star_boost_wrapper.cpp (modified) (23 diffs)
- trunk/core/src/shooting_star.h (modified) (1 diff)
- trunk/core/src/shooting_star_relax.hpp (modified) (6 diffs)
- trunk/core/src/shooting_star_search.hpp (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/core/src/shooting_star_boost_wrapper.cpp
r43 r72 21 21 22 22 #include <boost/config.hpp> 23 #include <iostream>24 #include <fstream>25 23 26 24 #include <boost/graph/graph_traits.hpp> … … 36 34 using namespace boost; 37 35 38 // Maximal number of nodes in the path (to avoid infinite loops)39 #define MAX_NODES 100000040 41 36 struct Edge 42 37 { … … 45 40 int target; 46 41 float8 cost; 47 float8 distance; 48 float8 rank; 49 std::map< int, std::pair<float8, std::vector<int> >, std::less<int> > adjacent_edges; 50 51 std::vector< int > history; 52 42 float distance; 43 float rank; 44 std::map< int, vector< std::pair<float, std::vector<int> > >, std::less<int> > adjacent_edges; 53 45 default_color_type color; 54 55 std::size_t index;56 57 adjacency_list_traits<vecS, vecS, directedS>::edge_descriptor predecessor;58 46 }; 59 47 … … 63 51 float8 x; 64 52 float8 y; 65 66 default_color_type color;67 68 float8 cost;69 70 53 }; 71 54 72 73 struct found_goal {}; // exception for termination 55 // exception for termination 56 struct found_goal 57 { 58 public: 59 found_goal() {} 60 found_goal(const found_goal &fg) {} 61 ~found_goal() {} 62 }; 74 63 75 64 // visitor that terminates when we find the goal … … 78 67 { 79 68 public: 80 shooting_star_goal_visitor(Edge goal) : m_goal(goal) {} 69 shooting_star_goal_visitor(Edge goal, int max_id) : m_goal(goal){} 70 shooting_star_goal_visitor(const shooting_star_goal_visitor &gv) : m_goal(gv.m_goal){} 71 ~shooting_star_goal_visitor(){} 81 72 82 73 template <class Graph> 83 void examine_edge(Edge e, Graph& g) { 84 if(g[e].id == g[m_goal].id) 74 void examine_edge(Edge e, Graph& g) 75 { 76 if( g[e].id == g[m_goal].id) 77 { 85 78 throw found_goal(); 79 } 86 80 } 87 81 template <class Graph> … … 89 83 private: 90 84 Edge m_goal; 85 int e_max_id; 91 86 }; 92 87 93 88 94 89 template <class Graph, class CostType> 95 class distance_heuristic : public astar_heuristic<Graph, CostType>90 class distance_heuristic 96 91 { 97 92 public: … … 100 95 CostType operator()(Edge e) 101 96 { 102 CostType dx = m_g[target(m_goal, m_g)].x - m_g[target(e, m_g)].x; 103 CostType dy = m_g[target(m_goal, m_g)].y - m_g[target(e, m_g)].y; 97 CostType dx = m_g[source(m_goal, m_g)].x - m_g[source(e, m_g)].x; 98 CostType dxt = m_g[target(m_goal, m_g)].x - m_g[target(e, m_g)].x; 99 CostType dy = m_g[source(m_goal, m_g)].y - m_g[source(e, m_g)].y; 100 CostType dyt = m_g[target(m_goal, m_g)].y - m_g[target(e, m_g)].y; 104 101 //You can choose any heuristical function from below 105 102 //return ::max(dx, dy); 106 103 //return ::sqrt(dx * dx + dy * dy)/2; 107 104 //return 0; 108 return ( ::fabs(dx)+::fabs(dy))/2;105 return (min(::fabs(dx),::fabs(dxt))+min(::fabs(dy),::fabs(dyt)))/2; 109 106 } 110 107 private: … … 118 115 graph_add_edge(G &graph, int id, int source, int target, 119 116 float8 cost, float8 s_x, float8 s_y, float8 t_x, float8 t_y, 120 std::map< int, std::pair<float8, vector<int> >, std::less<int> > adjacent_edges)117 std::map< int, vector< std::pair<float, vector<int> > >, std::less<int> > adjacent_edges) 121 118 { 122 119 … … 124 121 bool inserted; 125 122 126 if (cost < 0) // edges are not inserted in the graphif cost is negative127 return;123 if (cost < 0) // edges are inserted as unpassable if cost is negative 124 cost = MAX_COST; 128 125 129 126 tie(e, inserted) = add_edge(source, target, graph); … … 131 128 graph[e].cost = cost; 132 129 graph[e].id = id; 133 134 // put(edge_index, graph, graph[e], id);135 130 136 131 graph[e].source = source; … … 138 133 139 134 graph[e].adjacent_edges = adjacent_edges; 135 136 graph[e].rank = 0; 137 graph[e].distance = 0; 138 140 139 141 140 typedef typename graph_traits<G>::vertex_descriptor Vertex; … … 161 160 162 161 typedef adjacency_list<vecS, vecS, directedS, Vertex, Edge> graph_t; 163 162 164 163 typedef graph_traits < graph_t >::vertex_descriptor vertex_descriptor; 165 164 typedef graph_traits < graph_t >::edge_descriptor edge_descriptor; 166 165 167 const unsigned int num_nodes = /*1*/count*2;166 const unsigned int num_nodes = count*2; 168 167 169 168 int z; 170 int src, trg, offset ;169 int src, trg, offset, rule_num; 171 170 172 171 graph_t graph(num_nodes); 173 172 174 std::map< int, std::pair<float8, vector<int> >, std::less<int> > adjacent_edges;173 std::map< int, vector< std::pair<float, vector<int> > >, std::less<int> > adjacent_edges; 175 174 176 175 std::map< int, int, std::less<int> > vertices; 177 178 offset = 0; 179 176 177 vector<int> rule; 178 179 offset = 1; 180 rule_num = 0; 181 180 182 for (std::size_t j = 0; j < count; ++j) 181 183 { 182 184 //Vertex ids renumbering moved here 183 184 185 src = edges_array[j].source; 185 186 trg = edges_array[j].target; 186 187 if(vertices[src]==NULL) 188 //if (vertices.find(edges_array[j].source) == vertices.end()) 187 188 if(vertices[src]==0) 189 189 { 190 190 vertices[src]=j+offset; 191 edges_array[j].source=j+offset; 192 193 } 194 else 195 { 196 edges_array[j].source=vertices[src]; 197 } 198 199 if(vertices[trg]==NULL) 200 //if (vertices.find(edges_array[j].target) == vertices.end()) 201 { 202 offset++; 203 191 } 192 edges_array[j].source=vertices[src]; 193 194 if(vertices[trg]==0) 195 { 196 offset++; 204 197 vertices[trg]=j+offset; 205 edges_array[j].target=j+offset; 206 } 207 else 208 { 209 edges_array[j].target=vertices[trg]; 210 } 211 212 adjacent_edges[edges_array[j].id].first = edges_array[j].to_cost; 213 198 } 199 edges_array[j].target=vertices[trg]; 200 214 201 for(z=0; z<MAX_RULE_LENGTH;++z) 215 202 { 216 203 if(edges_array[j].rule[z] > 0) 217 204 { 218 adjacent_edges[edges_array[j].id].second.push_back(edges_array[j].rule[z]);205 rule.push_back(edges_array[j].rule[z]); 219 206 } 207 } 208 209 if(edges_array[j].to_cost > 0) 210 { 211 adjacent_edges[edges_array[j].id].push_back(std::pair<float8, vector<int> > (edges_array[j].to_cost, rule) ); 212 rule.clear(); 220 213 } 221 214 … … 227 220 edges_array[j].s_x, edges_array[j].s_y, 228 221 edges_array[j].t_x, edges_array[j].t_y, adjacent_edges); 229 222 230 223 if (!directed || (directed && has_reverse_cost)) 231 224 { … … 241 234 } 242 235 236 237 if(adjacent_edges[edges_array[j].id].size() > 0) 238 { 239 adjacent_edges[edges_array[j].id+e_max_id].assign( adjacent_edges[edges_array[j].id].begin(), adjacent_edges[edges_array[j].id].end() ); 240 adjacent_edges.erase(edges_array[j].id); 241 } 242 243 243 244 graph_add_edge<graph_t, edge_descriptor>(graph, 244 245 edges_array[j].id+e_max_id, edges_array[j].target, … … 249 250 250 251 adjacent_edges.clear(); 251 252 } 253 } 254 255 std::map< int, edge_descriptor, std::less<int> > predecessors; 252 rule_num = 0; 253 } 254 else 255 { 256 rule_num++; 257 } 258 } 259 256 260 257 261 edge_descriptor source_edge; … … 261 265 262 266 graph_traits<graph_t>::edge_iterator ei, ei_end; 263 int index; 264 265 index = 1; 266 267 for(tie(ei, ei_end) = edges(graph); ei != ei_end; ++ei, ++index) 268 graph[*ei].index = index; 269 267 270 268 for(tie(ei, ei_end) = edges(graph); ei != ei_end; ++ei) 271 269 { … … 276 274 break; 277 275 } 276 278 277 } 279 278 … … 283 282 return -1; 284 283 } 284 285 285 286 286 for(tie(ei, ei_end) = edges(graph); ei != ei_end; ++ei) … … 294 294 } 295 295 296 296 297 if (!target_found) 297 298 { … … 300 301 } 301 302 302 std::vector<float8> distances(num_edges(graph)); 303 304 std::vector<default_color_type> edge_colors(num_edges(graph), color_traits<default_color_type>::white()); 305 306 property_map<graph_t, std::vector< int > Edge::*>::type history = get(&Edge::history, graph); 307 308 property_map<graph_t, std::size_t Edge::*>::type edge_index = get(&Edge::index, graph); 309 310 property_map<graph_t, float8 Edge::*>::type rank = get(&Edge::rank, graph); 311 property_map<graph_t, float8 Edge::*>::type distance = get(&Edge::distance, graph); 303 property_map<graph_t, int Edge::*>::type edge_index = get(&Edge::id, graph); 304 305 std::map< int, edge_descriptor, std::less<int> > predecessors; 306 307 property_map<graph_t, float Edge::*>::type rank = get(&Edge::rank, graph); 308 property_map<graph_t, float Edge::*>::type distance = get(&Edge::distance, graph); 312 309 313 310 try … … 318 315 weight_map(get(&Edge::cost, graph)). 319 316 weight_map2(get(&Edge::adjacent_edges, graph)). 320 vertex_color_map(get(&Vertex::color, graph)).321 317 edge_color_map(get(&Edge::color, graph)). 322 visitor(shooting_star_goal_visitor<edge_descriptor>(target_edge )),318 visitor(shooting_star_goal_visitor<edge_descriptor>(target_edge, e_max_id)), 323 319 edge_index, 324 320 distance, rank, 325 history,326 321 predecessors, e_max_id 327 322 ); 328 323 329 324 } 330 catch(found_goal fg) { 325 catch(found_goal &fg) 326 { 331 327 332 328 vector<edge_descriptor> path_vect; … … 337 333 while (target_edge != source_edge) 338 334 { 335 339 336 if ((target_edge == predecessors[graph[target_edge].id]) && (predecessors[graph[target_edge].id] != source_edge)) 340 337 { … … 346 343 target_edge = predecessors[graph[target_edge].id]; 347 344 348 if(target_edge == predecessors[graph[target_edge].id] )349 continue;350 351 345 path_vect.push_back(target_edge); 352 346 trunk/core/src/shooting_star.h
r43 r72 22 22 #define _SHOOTING_STAR_H 23 23 #define MAX_RULE_LENGTH 5 24 25 #define MAX_NODES 1000000 26 #define MAX_COST 100000 24 27 25 28 #include "postgres.h" trunk/core/src/shooting_star_relax.hpp
r43 r72 18 18 #include <boost/property_map.hpp> 19 19 20 #include <iostream>21 #include <fstream>22 20 #include <postgres.h> 21 22 #define U_TURN_COST 100000 23 23 24 24 bool is_equal ( int a[], int b[], int size ) … … 56 56 template <class Edge, class Graph, class WeightMap, class EdgeMap, 57 57 class PredecessorMap, class DistanceMap, class CostMap, 58 class HistoryMap, classBinaryFunction, class BinaryPredicate>58 class BinaryFunction, class BinaryPredicate> 59 59 bool relax(Edge e, 60 60 Edge pe, 61 61 const Graph& g, const WeightMap& w, const EdgeMap& em, 62 62 PredecessorMap& p, DistanceMap& d, CostMap& c, 63 HistoryMap& his,64 63 const BinaryFunction& combine, const BinaryPredicate& compare, 65 64 int e_max_id) … … 81 80 82 81 W w_e = get(w, e); 83 84 //myfile<<"w(e) = "<<w_e<<"\n"<<std::flush;85 86 //myfile<<"cost("<<g[e].id<<") = "<<get(c, e)<<"\n"<<std::flush;87 88 //myfile<<"d("<<g[e].id<<") = "<<get(d, e)<<"\n"<<std::flush;89 90 //myfile<<g[u].id<<" - "<<g[v].id<<" : d_e="<<d_e<<"\n"<<std::flush;91 92 82 93 83 //edge where we came from 94 84 bool edge_exists; 95 //Edge pe;96 97 //pe = get(p, g[e].id);98 85 99 86 W w_pe_e; 100 87 101 //E w_pe = get(em, pe);102 88 E w_pe = get(em, e); 103 89 104 bool contains = false;90 int contains = -1; 105 91 106 107 //myfile<<"w(pe, e) = "<<w_pe_e<<"\n"<<std::flush;108 109 //myfile<<"id = "<<g[e].id<<", size = "<<w_pe[g[e].id].second.size()<<"\n"<<std::flush;110 111 92 Edge ce = pe; 112 93 int e_id; … … 115 96 typedef typename std::vector<Edge>::iterator It; 116 97 117 //for(int i=w_pe[g[e].id].second.size()-1; i>=0; --i)98 for(int i=0; i< w_pe[g[e].id].size(); ++i) 118 99 119 if(w_pe[g[e].id].second.size() < 1 || w_pe[g[e].id].second.back() > 0) 120 for(int i=0; i<w_pe[g[e].id].second.size(); ++i) 100 if(w_pe[g[e].id].at(i).second.size() < 1 || w_pe[g[e].id].at(i).second.back() > 0) 101 { 102 103 for(int j=0; j<w_pe[g[e].id].at(i).second.size(); ++j) 121 104 { 122 105 e_id = g[ce].id; 123 //myfile<<"e_id="<<e_id<<", second["<<g[e].id<<"]="<<w_pe[g[e].id].second.at(i)<<"\n"<<std::flush;124 106 125 if(w_pe[g[e].id]. second.at(i) == -1)107 if(w_pe[g[e].id].at(i).second.at(j) == -1) 126 108 continue; 127 128 if(w_pe[g[e].id].second.at(i) == e_id || w_pe[g[e].id].second.at(i)+e_max_id == e_id) 109 110 if(w_pe[g[e].id].at(i).second.at(j) == e_id || w_pe[g[e].id].at(i).second.at(j)+e_max_id == e_id|| 111 w_pe[g[e].id].at(i).second.at(j) == e_id+e_max_id || w_pe[g[e].id].at(i).second.at(j)+e_max_id == e_id+e_max_id) 129 112 { 130 contains = true;113 contains = i; 131 114 edge_h.push_back(ce); 132 115 } 133 else 116 else if(i == contains) 134 117 { 135 contains = false;118 contains = -1; 136 119 } 137 120 … … 139 122 } 140 123 124 } 125 141 126 //calculate w_pe_e 142 if(contains )127 if(contains >= 0) 143 128 { 144 145 w_pe_e = w_pe[g[e].id].first; 146 147 129 w_pe_e = w_pe[g[e].id].at(contains).first; 130 } 131 else if(abs(g[e].id-g[pe].id) == e_max_id) 132 { 133 w_pe_e = U_TURN_COST; 148 134 } 149 135 else … … 151 137 w_pe_e = 0; 152 138 } 153 139 154 140 //Ugly combination with w_e_pe. 155 141 trunk/core/src/shooting_star_search.hpp
r43 r72 28 28 #include "edge_visitors.hpp" 29 29 30 #include <iostream> 31 #include <fstream> 32 33 template <class Edge> 34 struct EdgeRankCompare { 35 bool operator()(const Edge& LHS, const Edge& RHS) { 36 return (LHS.rank < RHS.rank); 37 } 30 template <class Edge> 31 struct EdgeRankCompare 32 { 33 bool operator()(const Edge& LHS, const Edge& RHS) 34 { 35 return (LHS.rank < RHS.rank); 36 } 38 37 39 };40 41 template <class Edge, class Container, class Cmp>42 class edge_queue : public std::priority_queue<Edge, Container, Cmp>43 {44 protected:45 using std::priority_queue< Edge, Container, Cmp >::c;46 using std::priority_queue< Edge, Container, Cmp >::comp;47 48 public:49 void sort()50 {51 sort_heap(c.begin(), c.end(), comp);52 }53 };54 55 namespace boost {56 38 }; 39 40 template <class Edge, class Container, class Cmp> 41 class edge_queue : public std::priority_queue<Edge, Container, Cmp> 42 { 43 protected: 44 using std::priority_queue< Edge, Container, Cmp >::c; 45 using std::priority_queue< Edge, Container, Cmp >::comp; 46 47 public: 48 void sort() 49 { 50 sort_heap(c.begin(), c.end(), comp); 51 } 52 }; 53 54 namespace boost 55 { 57 56 58 57 template <class Heuristic, class Graph> 59 struct AStarHeuristicConcept { 58 struct AStarHeuristicConcept 59 { 60 60 void constraints() 61 61 { … … 70 70 71 71 template <class Graph, class CostType> 72 class astar_heuristic : public std::unary_function<72 class astar_heuristic : public std::unary_function< 73 73 typename graph_traits<Graph>::vertex_descriptor, CostType> 74 74 { … … 110 110 111 111 template <class IncidenceGraph, class Buffer, class BFSVisitor, 112 class ColorMap, class EdgeColorMap , class HistoryMap>112 class ColorMap, class EdgeColorMap/*, class HistoryMap*/> 113 113 void shooting_star_edges_visit (const IncidenceGraph& g, 114 114 typename graph_traits<IncidenceGraph>::edge_descriptor s, 115 115 Buffer& Q, BFSVisitor vis, ColorMap color, EdgeColorMap edge_color, 116 HistoryMap history,int e_max_id)116 int e_max_id) 117 117 { 118 118 function_requires< IncidenceGraphConcept<IncidenceGraph> >(); … … 121 121 typedef typename GTraits::edge_descriptor Edge; 122 122 function_requires< ShootingStarVisitorConcept<BFSVisitor, IncidenceGraph> >(); 123 function_requires< ReadWritePropertyMapConcept<ColorMap, Vertex> >();124 123 function_requires< ReadWritePropertyMapConcept<EdgeColorMap, Edge> >(); 125 124 … … 131 130 132 131 typename GTraits::out_edge_iterator ei, ei_end; 133 134 put(edge_color, s, EdgeColor::gray()); vis.discover_edge(s, g); 132 133 put(edge_color, s, EdgeColor::gray()); 134 vis.discover_edge(s, g); 135 135 136 Q.push(s); 136 137 137 while (! Q.empty()) { 138 Edge e = Q.top(); Q.pop(); vis.examine_edge(e, g); 139 140 for (tie(ei, ei_end) = out_edges(target(e, g), g); ei != ei_end; ++ei) { 141 142 EdgeColorValue e_color = get(edge_color, *ei); 143 144 if (e_color == EdgeColor::white()) { vis.tree_edge(*ei, e, g, e_max_id); 145 put(edge_color, *ei, EdgeColor::gray()); vis.discover_edge(*ei, g); 138 while (! Q.empty()) 139 { 140 Edge e = Q.top(); Q.pop(); 141 142 vis.examine_edge(e, g); 143 144 for (tie(ei, ei_end) = out_edges(target(e, g), g); ei != ei_end; ++ei) 145 { 146 EdgeColorValue e_color = get(edge_color, *ei); 147 148 if (e_color == EdgeColor::white()) 149 { 150 vis.tree_edge(*ei, e, g, e_max_id); 151 put(edge_color, *ei, EdgeColor::gray()); 152 vis.discover_edge(*ei, g); 146 153 Q.push(*ei); 147 148 } else { vis.non_tree_edge(*ei, g); 149 if (e_color == EdgeColor::gray()){ vis.gray_target(*ei, e, g, e_max_id); 154 } 155 else 156 { 157 vis.non_tree_edge(*ei, g); 158 if (e_color == EdgeColor::gray()) 159 { 160 vis.gray_target(*ei, e, g, e_max_id); 150 161 } 151 else{ vis.black_target(*ei, e, g, e_max_id); 162 else 163 { 164 vis.black_target(*ei, e, g, e_max_id); 152 165 } 153 166 } … … 155 168 } // end for 156 169 157 put(edge_color, e, EdgeColor::black()); vis.finish_edge(e, g); 170 put(edge_color, e, EdgeColor::black()); 171 vis.finish_edge(e, g); 158 172 159 173 } // end while 160 161 174 } 162 175 163 176 164 177 template <class Visitors = null_visitor> 165 class shooting_star_visitor : public bfs_visitor<Visitors> { 166 public: 167 shooting_star_visitor() {} 168 shooting_star_visitor(Visitors vis) 169 : bfs_visitor<Visitors>(vis) {} 170 171 template <class Edge, class Graph> 172 void edge_relaxed(Edge e, Graph& g) { 173 invoke_visitors(this->m_vis, e, g, on_edge_relaxed()); 174 } 175 template <class Edge, class Graph> 176 void edge_not_relaxed(Edge e, Graph& g) { 177 invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed()); 178 } 179 template <class Edge, class Graph> 180 void initialize_edge(Edge e, Graph& g) { 181 invoke_visitors(this->m_vis, e, g, on_initialize_edge()); 182 } 183 184 private: 185 template <class Edge, class Graph> 186 void tree_edge(Edge e, Edge pe, Graph& g) {} 187 template <class Edge, class Graph> 188 void non_tree_edge(Edge e, Graph& g) {} 178 class shooting_star_visitor : public bfs_visitor<Visitors> 179 { 180 public: 181 shooting_star_visitor() {} 182 shooting_star_visitor(Visitors vis) 183 : bfs_visitor<Visitors>(vis) {} 184 185 template <class Edge, class Graph> 186 void edge_relaxed(Edge e, Graph& g) 187 { 188 invoke_visitors(this->m_vis, e, g, on_edge_relaxed()); 189 } 190 template <class Edge, class Graph> 191 void edge_not_relaxed(Edge e, Graph& g) 192 { 193 invoke_visitors(this->m_vis, e, g, on_edge_not_relaxed()); 194 } 195 template <class Edge, class Graph> 196 void initialize_edge(Edge e, Graph& g) 197 { 198 invoke_visitors(this->m_vis, e, g, on_initialize_edge()); 199 } 200 201 private: 202 template <class Edge, class Graph> 203 void tree_edge(Edge e, Edge pe, Graph& g) {} 204 template <class Edge, class Graph> 205 void non_tree_edge(Edge e, Graph& g) {} 189 206 }; 207 190 208 template <class Visitors> 191 209 shooting_star_visitor<Visitors> 192 make_shooting_star_visitor(Visitors vis) { 210 make_shooting_star_visitor(Visitors vis) 211 { 193 212 return shooting_star_visitor<Visitors>(vis); 194 213 } 214 195 215 typedef shooting_star_visitor<> default_shooting_star_visitor; 196 216 … … 200 220 template <class AStarHeuristic, class UniformCostVisitor, 201 221 class UpdatableQueue, class PredecessorMap, 202 class CostMap, class DistanceMap, class WeightMap, 222 class CostMap, 223 class DistanceMap, class WeightMap, 203 224 class EdgeMap, 204 class ColorMap, class EdgeColorMap, class HistoryMap,225 class ColorMap, class EdgeColorMap, 205 226 class BinaryFunction, 206 227 class BinaryPredicate> … … 220 241 UpdatableQueue& Q, PredecessorMap& p, 221 242 CostMap c, DistanceMap d, WeightMap w, EdgeMap em, 222 ColorMap col, EdgeColorMap ecol, HistoryMap his,243 ColorMap col, EdgeColorMap ecol, //HistoryMap his, 223 244 BinaryFunction combine, 224 245 BinaryPredicate compare, C zero) 225 246 : m_h(h), m_vis(vis), m_Q(Q), m_predecessor(p), m_cost(c), 226 247 m_distance(d), m_weight(w), m_edge(em), m_color(col), 227 m_ecolor(ecol), m_history(his),248 m_ecolor(ecol), //m_history(his), 228 249 m_combine(combine), m_compare(compare), m_zero(zero) {} 229 250 251 shooting_star_bfs_visitor(const shooting_star_bfs_visitor &v) 252 : m_h(v.m_h), m_vis(v.m_vis), m_Q(v.m_Q), m_predecessor(v.m_predecessor), m_cost(v.m_cost), 253 m_distance(v.m_distance), m_weight(v.m_weight), m_edge(v.m_edge), m_color(v.m_color), 254 m_ecolor(v.m_ecolor), //m_history(his), 255 m_combine(v.m_combine), m_compare(v.m_compare), m_zero(v.m_zero) {} 256 257 ~shooting_star_bfs_visitor() {} 230 258 231 259 template <class Vertex, class Graph> 232 void initialize_vertex(Vertex u, Graph& g) { 260 void initialize_vertex(Vertex u, Graph& g) 261 { 233 262 m_vis.initialize_vertex(u, g); 234 263 } 235 264 template <class Edge, class Graph> 236 void initialize_edge(Edge e, Graph& g) { 265 void initialize_edge(Edge e, Graph& g) 266 { 237 267 m_vis.initialize_edge(e, g); 238 268 } 239 269 template <class Vertex, class Graph> 240 void discover_vertex(Vertex u, Graph& g) { 270 void discover_vertex(Vertex u, Graph& g) 271 { 241 272 m_vis.discover_vertex(u, g); 242 273 } 243 274 template <class Edge, class Graph> 244 void discover_edge(Edge e, Graph& g) { 275 void discover_edge(Edge e, Graph& g) 276 { 245 277 m_vis.discover_vertex(e, g); 246 278 } 247 279 template <class Vertex, class Graph> 248 void examine_vertex(Vertex u, Graph& g) { 280 void examine_vertex(Vertex u, Graph& g) 281 { 249 282 m_vis.examine_vertex(u, g); 250 283 } 251 284 template <class Vertex, class Graph> 252 void finish_vertex(Vertex u, Graph& g) { 285 void finish_vertex(Vertex u, Graph& g) 286 { 253 287 m_vis.finish_vertex(u, g); 254 288 } 255 289 template <class Edge, class Graph> 256 void examine_edge(Edge e, Graph& g) { 290 void examine_edge(Edge e, Graph& g) 291 { 257 292 if (m_compare(get(m_weight, e), m_zero)) 258 293 throw negative_edge(); … … 263 298 264 299 template <class Edge, class Graph> 265 void finish_edge(Edge e, Graph& g) { 300 void finish_edge(Edge e, Graph& g) 301 { 266 302 m_vis.finish_edge(e, g); 267 303 } … … 269 305 270 306 template <class Edge, class Graph> 271 void tree_edge(Edge e, Edge pe, Graph& g, int e_max_id) {272 307 void tree_edge(Edge e, Edge pe, Graph& g, int e_max_id) 308 { 273 309 m_decreased = relax(e, pe, g, m_weight, m_edge, m_predecessor, m_distance, 274 m_cost, m_history, m_combine, m_compare, e_max_id); 275 276 if(m_decreased) { 310 m_cost, m_combine, m_compare, e_max_id); 311 312 if(m_decreased) 313 { 277 314 m_vis.edge_relaxed(e, g); 278 315 … … 281 318 m_h(e))); 282 319 283 } else 320 } 321 else 284 322 m_vis.edge_not_relaxed(e, g); 285 323 } … … 287 325 288 326 template <class Edge, class Graph> 289 void gray_target(Edge e, Edge pe, Graph& g, int e_max_id) {290 327 void gray_target(Edge e, Edge pe, Graph& g, int e_max_id) 328 { 291 329 m_decreased = relax(e, pe, g, m_weight, m_edge, m_predecessor, m_distance, 292 m_cost, m_history, m_combine, m_compare, e_max_id); 293 294 if(m_decreased) { 330 m_cost, m_combine, m_compare, e_max_id); 331 332 if(m_decreased) 333 { 295 334 put(m_cost, e, 296 335 m_combine(get(m_distance, e), … … 300 339 301 340 m_vis.edge_relaxed(e, g); 302 } else 341 } 342 else 303 343 m_vis.edge_not_relaxed(e, g); 304 344 } … … 306 346 307 347 template <class Edge, class Graph> 308 void black_target(Edge e, Edge pe, Graph& g, int e_max_id) { 348 void black_target(Edge e, Edge pe, Graph& g, int e_max_id) 349 { 309 350 310 351 m_decreased = relax(e, pe, g, m_weight, m_edge, m_predecessor, m_distance, 311 m_cost, m_history, m_combine, m_compare, e_max_id); 312 313 if(m_decreased) { 352 m_cost, m_combine, m_compare, e_max_id); 353 354 if(m_decreased) 355 { 314 356 m_vis.edge_relaxed(e, g); 315 put(m_cost, e, 316 m_combine(get(m_distance, e), 317 m_h(e))); 357 put(m_cost, e, m_combine(get(m_distance, e), m_h(e))); 318 358 319 359 m_Q.push(e); 320 360 put(m_ecolor, e, EdgeColor::gray()); 321 361 m_vis.black_target(e, g); 322 } else 362 } 363 else 323 364 m_vis.edge_not_relaxed(e, g); 324 365 } … … 334 375 ColorMap m_color; 335 376 EdgeColorMap m_ecolor; 336 HistoryMap m_history;337 377 BinaryFunction m_combine; 338 378 BinaryPredicate m_compare; 339 379 bool m_decreased; 340 C m_zero; 341 380 C m_zero; 342 381 }; 343 382 … … 346 385 template <typename VertexAndEdgeListGraph, typename AStarHeuristic, 347 386 typename ShootingStarVisitor, typename PredecessorMap, 348 typename CostMap, typename DistanceMap, 387 typename CostMap, 388 typename DistanceMap, 349 389 typename WeightMap, 350 390 typename EdgeMap, 351 391 typename ColorMap, typename EdgeColorMap, 352 typename HistoryMap,353 392 typename IndexMap, 354 393 typename CompareFunction, typename CombineFunction, … … 361 400 PredecessorMap &predecessor, CostMap cost, 362 401 DistanceMap distance, WeightMap weight, EdgeMap edge_map, 363 ColorMap color, EdgeColorMap edge_color, HistoryMap history,402 ColorMap color, EdgeColorMap edge_color, 364 403 IndexMap index_map, CompareFunction compare, CombineFunction combine, 365 404 CostInf inf, CostZero zero, int e_max_id) … … 377 416 detail::shooting_star_bfs_visitor<AStarHeuristic, ShootingStarVisitor, 378 417 MutableQueue, PredecessorMap, CostMap, DistanceMap, 379 WeightMap, EdgeMap, ColorMap, EdgeColorMap, HistoryMap,CombineFunction, CompareFunction>418 WeightMap, EdgeMap, ColorMap, EdgeColorMap, /*HistoryMap,*/ CombineFunction, CompareFunction> 380 419 bfs_vis(h, vis, Q, predecessor, cost, distance, weight, 381 edge_map, color, edge_color, history,combine, compare, zero);382 383 shooting_star_edges_visit(g, s, Q, bfs_vis, color, edge_color, history,e_max_id);420 edge_map, color, edge_color, combine, compare, zero); 421 422 shooting_star_edges_visit(g, s, Q, bfs_vis, color, edge_color, e_max_id); 384 423 } 385 424 … … 391 430 typename IndexMap, 392 431 typename ColorMap, typename EdgeColorMap, 393 typename HistoryMap,432 //typename HistoryMap, 394 433 typename CompareFunction, typename CombineFunction, 395 434 typename CostInf, typename CostZero> … … 402 441 DistanceMap distance, WeightMap weight, 403 442 EdgeMap edge_map, IndexMap index_map, ColorMap color, EdgeColorMap edge_color, 404 HistoryMap history,CompareFunction compare, CombineFunction combine,443 CompareFunction compare, CombineFunction combine, 405 444 CostInf inf, CostZero zero, int e_max_id) 406 445 { … … 415 454 typename graph_traits<VertexAndEdgeListGraph>::edge_iterator ei, ei_end; 416 455 417 for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { 456 for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) 457 { 418 458 vis.initialize_vertex(*ui, g); 419 459 } 420 460 421 for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) { 461 for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei) 462 { 422 463 put(distance, *ei, inf); 423 464 put(edge_color, *ei, EdgeColor::white()); … … 432 473 shooting_star_search_no_init 433 474 (g, s, h, vis, predecessor, cost, distance, weight, edge_map, 434 color, edge_color, history,index_map, compare, combine, inf, zero, e_max_id);475 color, edge_color, index_map, compare, combine, inf, zero, e_max_id); 435 476 436 477 } 437 478 438 namespace detail { 479 namespace detail 480 { 439 481 template <class VertexAndEdgeListGraph, class AStarHeuristic, 440 482 class CostMap, class DistanceMap, class WeightMap, class EdgeMap, … … 442 484 class PredecessorMap, 443 485 class ColorMap, class EdgeColorMap, 444 class HistoryMap, classParams>486 class Params> 445 487 inline void 446 488 shooting_star_dispatch2 … … 450 492 WeightMap weight, EdgeMap edge_map, IndexMap index_map, 451 493 PredecessorMap& predecessor, ColorMap color, 452 EdgeColorMap edge_color, HistoryMap history,const Params& params,494 EdgeColorMap edge_color, const Params& params, 453 495 int e_max_id) 454 496 { … … 460 502 make_shooting_star_visitor(null_visitor())), 461 503 predecessor, 462 cost, distance, weight, edge_map, index_map, color, edge_color, history,504 cost, distance, weight, edge_map, index_map, color, edge_color, //history, 463 505 choose_param(get_param(params, distance_compare_t()), 464 506 std::less<C>()), … … 478 520 class PredecessorMap, 479 521 class ColorMap, class EdgeColorMap, 480 class HistoryMap, classParams>522 class Params> 481 523 inline void 482 524 shooting_star_dispatch1 … … 485 527 AStarHeuristic h, CostMap cost, DistanceMap distance, 486 528 WeightMap weight, EdgeMap edge_map, IndexMap index_map, PredecessorMap& predecessor, 487 ColorMap color, EdgeColorMap edge_color, HistoryMap history,const Params& params,529 ColorMap color, EdgeColorMap edge_color, const Params& params, 488 530 int e_max_id) 489 531 { … … 496 538 497 539 std::vector<default_color_type> color_map(num_vertices(g)); 498 std::vector<default_color_type> edge_color_map(num_edges(g));499 540 default_color_type c = white_color; 500 541 … … 512 553 (color_map.begin(), index_map, c)), 513 554 edge_color, 514 history,515 555 params, 516 556 e_max_id); … … 525 565 typename DistanceMap, 526 566 typename CostMap, 527 typename
