Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgSearchControl.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file SgSearchControl.h
00003     Search control for searchengine.
00004 
00005     Provides base class SgSearchControl and several 
00006     basic serch control strategies.
00007     An SgSearchControl object is installed into SgSearch or derived engine. */
00008 //----------------------------------------------------------------------------
00009 
00010 #ifndef SG_SEARCHCONTROL_H
00011 #define SG_SEARCHCONTROL_H
00012 
00013 //----------------------------------------------------------------------------
00014 
00015 /** Resource control used in class SgSearch. */
00016 class SgSearchControl
00017 {
00018 public:
00019     SgSearchControl();
00020 
00021     virtual ~SgSearchControl();
00022 
00023     /** Check if search should be aborted.
00024         Called at each node. */
00025     virtual bool Abort(double elapsedTime, int numNodes) = 0;
00026 
00027     /** Check if next iteration should be started.
00028         Called before each iteration.
00029         The default implementation always returns true.
00030         @param depth The depth of the next iteration.
00031         @param elapsedTime The elapsed time in seconds.
00032         @param numNodes The number of nodes visited. */
00033     virtual bool StartNextIteration(int depth, double elapsedTime,
00034                                     int numNodes);
00035 
00036 private:
00037     /** Not implemented */
00038     SgSearchControl(const SgSearchControl&);
00039 
00040     /** Not implemented */
00041     SgSearchControl& operator=(const SgSearchControl&);
00042 };
00043 
00044 inline SgSearchControl::SgSearchControl()
00045 {
00046 }
00047 
00048 //----------------------------------------------------------------------------
00049 
00050 /** Example of a simple search abort class: abort when time has expired. */
00051 class SgTimeSearchControl
00052     : public SgSearchControl
00053 {
00054 public:
00055     SgTimeSearchControl(double maxTime);
00056 
00057     virtual ~SgTimeSearchControl();
00058 
00059     virtual bool Abort(double elapsedTime, int ignoreNumNodes);
00060 
00061     double GetMaxTime() const;
00062 
00063     void SetMaxTime(double maxTime);
00064 
00065 private:
00066     double m_maxTime;
00067 
00068     /** Not implemented */
00069     SgTimeSearchControl(const SgTimeSearchControl&);
00070 
00071     /** Not implemented */
00072     SgTimeSearchControl& operator=(const SgTimeSearchControl&);
00073 };
00074 
00075 inline double SgTimeSearchControl::GetMaxTime() const
00076 {
00077     return m_maxTime;
00078 }
00079 
00080 inline void SgTimeSearchControl::SetMaxTime(double maxTime)
00081 {
00082     m_maxTime = maxTime;
00083 }
00084 
00085 //----------------------------------------------------------------------------
00086 
00087 /** Example of a simple search abort class: abort when node limit
00088     is reached. */
00089 class SgNodeSearchControl
00090     : public SgSearchControl
00091 {
00092 public:
00093     SgNodeSearchControl(int maxNumNodes);
00094 
00095     virtual ~SgNodeSearchControl();
00096 
00097     virtual bool Abort(double ignoreElapsedTime, int numNodes);
00098 
00099     void SetMaxNumNodes(int maxNumNodes);
00100 
00101 private:
00102     int m_maxNumNodes;
00103 
00104     /** Not implemented */
00105     SgNodeSearchControl(const SgNodeSearchControl&);
00106 
00107     /** Not implemented */
00108     SgNodeSearchControl& operator=(const SgNodeSearchControl&);
00109 };
00110 
00111 inline void SgNodeSearchControl::SetMaxNumNodes(int maxNumNodes)
00112 {
00113     m_maxNumNodes = maxNumNodes;
00114 }
00115 
00116 //----------------------------------------------------------------------------
00117 
00118 /** Abort when either time or node limit is reached. */
00119 class SgCombinedSearchControl
00120     : public SgSearchControl
00121 {
00122 public:
00123     SgCombinedSearchControl(double maxTime, int maxNumNodes);
00124 
00125     virtual ~SgCombinedSearchControl();
00126 
00127     virtual bool Abort(double elapsedTime, int numNodes);
00128 
00129 private:
00130     double m_maxTime;
00131 
00132     int m_maxNumNodes;
00133 
00134     /** Not implemented */
00135     SgCombinedSearchControl(const SgCombinedSearchControl&);
00136 
00137     /** Not implemented */
00138     SgCombinedSearchControl& operator=(const SgCombinedSearchControl&);
00139 };
00140 
00141 inline SgCombinedSearchControl::SgCombinedSearchControl(double maxTime,
00142                                                         int maxNumNodes)
00143     : m_maxTime(maxTime),
00144       m_maxNumNodes(maxNumNodes)
00145 {
00146 }
00147 
00148 //----------------------------------------------------------------------------
00149 
00150 /** Abort when time limit is reached AND a number of nodes were searched. */
00151 class SgRelaxedSearchControl
00152     : public SgSearchControl
00153 {
00154 public:
00155     static const int MIN_NODES_PER_SECOND = 1000;
00156 
00157     SgRelaxedSearchControl(double maxTime);
00158 
00159     virtual ~SgRelaxedSearchControl();
00160 
00161     virtual bool Abort(double elapsedTime, int numNodes);
00162 
00163 private:
00164     double m_maxTime;
00165 
00166     /** Not implemented */
00167     SgRelaxedSearchControl(const SgRelaxedSearchControl&);
00168 
00169     /** Not implemented */
00170     SgRelaxedSearchControl& operator=(const SgRelaxedSearchControl&);
00171 };
00172 
00173 inline SgRelaxedSearchControl::SgRelaxedSearchControl(double maxTime)
00174     : m_maxTime(maxTime)
00175 {
00176 }
00177 
00178 //----------------------------------------------------------------------------
00179 
00180 #endif // SG_SEARCHCONTROL_H


Sun Mar 13 2011 Doxygen 1.7.1