Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
NavHeuristics.hpp
Go to the documentation of this file.
00001 
00012 #ifndef LGL_NAVIGATION_HEURISTICS_HPP
00013 #define LGL_NAVIGATION_HEURISTICS_HPP
00014 
00015 #include <math.h>
00016 
00017 #include <lgl/Location.hpp>
00018 #include <lgl/NavHeuDistances.hpp>
00019 
00020 namespace jafar { 
00021   namespace lgl { 
00022 
00027     // HEURISTIC 1 : Euclidean Distance
00028     template <
00029       class Graph,    // the graph in question 
00030       class CostType, // the CostType (int, double or any other class)
00031       typename Vertex    //the vertex template
00032       >
00033     class nav_heuristic : public boost::astar_heuristic<Graph, CostType>
00034     {
00035       public:
00036     
00037         // constructor of the heuristic : take the goal
00038         nav_heuristic(const Graph& _g, const Vertex& _goal)
00039           : g(_g), goal(_goal) {}
00040         
00041         CostType operator()(const Vertex& u)
00042         {
00043           return Euclidean2DDist<NavLocation,CostType>(g[u].pos, g[goal].pos);      
00044         }
00045     
00046       private:
00047         Graph g;
00048         Vertex goal;
00049     };
00050 
00051     // HEURISTIC 2 : Euclidean Distance + Path Length
00052     template <
00053       class Graph,    // the graph in question 
00054       class CostType, // the CostType (int, double or any other class)
00055       typename Vertex    //the vertex template
00056       >
00057     class nav_heuristic_rdv: public boost::astar_heuristic<Graph, CostType>
00058     {
00059       public:
00062         nav_heuristic_rdv(const Graph& g_, const Vertex& goal_, CostType authDist_, std::vector<Vertex> &predMap_)
00063           : g(g_), goal(goal_), authDist(authDist_), predMap(predMap_) {}
00064         
00065         CostType operator()(const Vertex& u)
00066         {
00067           CostType eucDist = Euclidean2DDist<NavLocation,CostType>(g[u].pos, g[goal].pos);      
00068           // Calculating path length at this vertex greedily.
00069           // Could be optimized.
00070           CostType pathLength = 0.0;
00071           for(Vertex ui = u;; ui = predMap[ui]) {
00072             if(predMap[ui] == ui)
00073             {
00074               break;
00075             }
00076             pathLength += Euclidean2DDist<NavLocation,CostType>(
00077               g[predMap[ui]].pos,
00078               g[ui].pos);
00079           }
00080 
00081           // Adapting pathLength for cost: using squared differences
00082           // Cost grows fast when pathLength is not close to authDist.
00083           pathLength = fabs(authDist - pathLength);
00084           //pathLength = pathLength * pathLength;
00085 
00086           return (eucDist + pathLength);
00087 
00088         }
00089     
00090       private:
00091         Graph g;
00092         Vertex goal;
00093         Vertex start;
00094         CostType authDist;
00095         std::vector<Vertex> predMap;
00096     };
00097   }
00098 }
00099 #endif /* LGL_NAVIGATION_HEURISTICS_HPP */
00100 
00101 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:24 for Jafar by doxygen 1.7.6.1
LAAS-CNRS