Main   Class Hierarchy   Classes   Compound List   Files   Compound Members   File Members   Pages  

idastar.h

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 /** @file idastar.h
00003     IDA* search.
00004 
00005     $Id: idastar_8h-source.html,v 1.1.1.1 2003/08/07 19:41:39 emarkus Exp $
00006     $Source: /usr/cvsroot/www_pathfind/libpathfind/0.1.0/doc/idastar_8h-source.html,v $
00007 */
00008 //-----------------------------------------------------------------------------
00009 
00010 #ifndef PATHFIND_IDASTAR_H
00011 #define PATHFIND_IDASTAR_H
00012 
00013 #include "search.h"
00014 
00015 //-----------------------------------------------------------------------------
00016 
00017 namespace PathFind
00018 {
00019     using namespace std;
00020 
00021     /** IDA* search algorithm.        
00022         Short desciption of IDA*:
00023         
00024         Each iteration is a depth-first search that keeps track of the cost
00025         f = g + h of each node generated. If a node is generated whose cost
00026         exceeds the threshold for that iteration, its path is cut off and
00027         the search backtracks. The cost threshold is initialized to the
00028         heuristic of the initial state and is increased in each iteration
00029         to the total cost of the lowest-cost node that was pruned during the
00030         previous iteration. The algorithm terminates when a goal state is
00031         reached whose total cost does not exceed the current threshold.
00032 
00033         %Statistics (see Search::createStatistics and Search::getStatistics):
00034         - "aborted"
00035         - "cpu_time"
00036         - "path_cost"
00037         - "path_length"
00038         - "branching_factor"
00039         - "nodes_expanded"
00040         - "nodes_visited"
00041         - "iterations"
00042     */
00043     class IDAStar
00044         : public Search
00045     {
00046     public:
00047         /** Caching strategy for f-values. */
00048         typedef enum { 
00049             /** No caching. */
00050             NO_CACHING, 
00051 
00052             /** Local caching (f-caching) */
00053             f_CACHING, 
00054 
00055             /** Caching of backed up f-values (F-caching) */
00056             F_CACHING 
00057         } Caching;
00058 
00059         IDAStar(Caching caching = NO_CACHING);
00060 
00061         StatisticsCollection createStatistics();
00062 
00063         bool findPath(const Environment& env, int start, int target);
00064 
00065         const vector<int>& getPath() const
00066         {
00067             return m_path;
00068         }
00069 
00070         const StatisticsCollection& getStatistics() const;
00071 
00072         const vector<char>& getVisitedNodes() const
00073         {
00074             return m_visitedNodes;
00075         }
00076 
00077     private:   
00078         /** Information for caching f-values. */
00079         class CacheNode 
00080         {
00081         public:
00082             int m_iter;
00083 
00084             int m_f;
00085 
00086             int m_g;
00087         };
00088 
00089 
00090         bool m_abortSearch;
00091 
00092         int m_target;
00093 
00094         int m_fLimit;
00095 
00096         Caching  m_caching;
00097 
00098         const Environment* m_env;
00099 
00100         long long int m_nodesExpanded;
00101 
00102         long long int m_nodesVisited;
00103 
00104         vector<char> m_visitedNodes;
00105 
00106         vector<CacheNode> m_cache;
00107 
00108         vector<int> m_path;
00109 
00110         vector<vector<Environment::Successor> > m_successorStack;
00111 
00112         StatisticsCollection m_statistics;
00113 
00114         Statistics& m_branchingFactor;
00115 
00116         void addCache(int nodeId, int f, int g, int iteration)
00117         {
00118             m_cache[nodeId].m_iter = iteration;
00119             m_cache[nodeId].m_f    = f;
00120             m_cache[nodeId].m_g    = g;
00121         }
00122 
00123         /** Check in cache.
00124             Check in cache if node has be visited before via a shorter path.
00125         */
00126         bool checkCache(int nodeId, int f, int g, int iteration, int& f_min);
00127 
00128         void findPathIdaStar(int start);
00129 
00130         void markVisitedNode(int nodeId, int iteration);
00131 
00132         bool searchPathIdaStar(int iteration, int node, int lastNode,
00133                                int depth, int g, int& f_min);
00134     };
00135 }
00136 
00137 //-----------------------------------------------------------------------------
00138 
00139 #endif


Generated on Thu Aug 7 13:04:49 2003 by Doxygen1.3.1