libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
dijkstra.hpp
1 /*
2  * dijkstra.hpp
3  *
4  * Created on: Oct 5, 2009
5  * Author: jmainpri
6  */
7 
8 #ifndef DIJKSTRA_HPP_
9 #define DIJKSTRA_HPP_
10 
11 #include "API/Trajectory/trajectory.hpp"
12 #include "API/ConfigSpace/configuration.hpp"
13 #include "API/Roadmap/graph.hpp"
14 #include "../../Grids/ThreeDGrid.hpp"
15 
16 #include <list>
17 #include <map>
18 
19 typedef int vertex_t;
20 typedef double weight_t;
21 
25 struct edge_dijkstra {
26  vertex_t target;
27  weight_t weight;
28  edge_dijkstra(vertex_t arg_target, weight_t arg_weight)
29  : target(arg_target), weight(arg_weight) { }
30 };
31 
32 typedef std::map<vertex_t, std::list<edge_dijkstra> > adjacency_map_t;
33 typedef std::map<int,Node*> node_map_t;
34 
38 template <typename T1, typename T2>
40 {
41  bool operator()(std::pair<T1,T2> p1, std::pair<T1,T2> p2) const
42  {
43  if(p1.first == p2.first) {
44  //Otherwise the initial vertex_queue will have the size 2 { 0,source ; inf;n }
45  return p1.second < p2.second;
46  }
47  return p1.first < p2.first;
48  }
49 };
50 
55 class Dijkstra {
56 
57 public :
58  Dijkstra();
59  Dijkstra(Graph* ptrG);
60  ~Dijkstra();
61 
65  void creatStructures();
66 
67  void creatStructuresFromGrid(API::ThreeDGrid* grid);
68 
69  void computePaths(vertex_t source,
70  adjacency_map_t& adjacency_map,
71  std::map<vertex_t, weight_t>& min_distance,
72  std::map<vertex_t, vertex_t>& previous);
73 
74  std::list<vertex_t> getShortestPathTo(
75  vertex_t target, std::map<vertex_t, vertex_t>& previous);
76 
80  int example();
81 
85  API::Trajectory* extractTrajectory(std::tr1::shared_ptr<Configuration> init, std::tr1::shared_ptr<Configuration> goal);
86 
90  API::Trajectory* extractTrajectory(vertex_t source,vertex_t target);
91 
92 
93 private :
94  Graph* m_graph;
95  adjacency_map_t m_graph_adjacency_map;
96  node_map_t m_graph_node_map;
97 };
98 
99 #endif /* DIJKSTRA_HPP_ */
Definition: dijkstra.hpp:25
Implement Dijkstra graph search algorithm.
Definition: dijkstra.hpp:55
Definition: graph.hpp:28
Definition: ThreeDGrid.hpp:24
int example()
Example using the maps.
Definition: dijkstra.cpp:191
API::Trajectory * extractTrajectory(std::tr1::shared_ptr< Configuration > init, std::tr1::shared_ptr< Configuration > goal)
Extract Trajectory beetween two Configurations.
Definition: trajectory.hpp:40
void creatStructures()
Creates the Maps out of the p3d Graph struct.
Definition: dijkstra.cpp:25
Definition: dijkstra.hpp:39